views without templates

51 views
Skip to first unread message

Matt Jackson

unread,
Jul 11, 2012, 10:39:29 AM7/11/12
to mari...@googlegroups.com
Hi Peter. Really enjoying the framework so far, just found one problem.

I'm retro-fitting maria into some existing pages, and I don't need any HTML generation (I'm just using it for seperation of concerns between DOM and model) so my getTemplate() is not being set. However, I'm seeing an error when constructing my ElementView via the build() method

Cannot call method 'replace' of undefined 

So getTemplate() is undefined, which is expected I suppose, however the parseHTML is blowing when doing the string trim. I'm working around currently it by calling 

new ..ElementView(model, controller).buildUIActions();

Do you accept pull requests? Or should I leave it with you?

Peter Michaux

unread,
Jul 11, 2012, 1:01:08 PM7/11/12
to mari...@googlegroups.com
Hi Matt,

On Wed, Jul 11, 2012 at 7:39 AM, Matt Jackson <em...@mwjackson.net> wrote:

> I'm retro-fitting maria into some existing pages, and I don't need any HTML
> generation (I'm just using it for seperation of concerns between DOM and
> model)

Is this a progressive enhancements situation?

> so my getTemplate() is not being set.

When using maria.ElementView.subclass, the getTemplate method is
actually being auto-generated for you to look for the template by
naming convention.

> However, I'm seeing an error
> when constructing my ElementView via the build() method
>
> Cannot call method 'replace' of undefined
>
> So getTemplate() is undefined,

Yes the results of calling getTemplate would be undefined if the
template does not exist according to the naming convention or
according to the configuration you supply to override the convention.

> which is expected I suppose, however the
> parseHTML is blowing when doing the string trim. I'm working around
> currently it by calling
>
> new ..ElementView(model, controller).buildUIActions();
>
> Do you accept pull requests? Or should I leave it with you?

Does your ElementView have a root DOM node already in the page? Does
the view update parts of that DOM node along the life of the page? How
do you extract data for the model layer out of the page?

I'm thinking you may want to do something like the following when
defining your view to avoid the base buildTemplate method so that
getTemplate won't be called.

maria.ElementView.subclass(app, 'MyView', {
properties: {
setRootEl: function(rootEl) {
this._rootEl = rootEl;
},
buildTemplate: function() {
return this._rootEl;
}
}
});

Then in your bootstrap code

var myView = new app.MyView();
myView.setRootEl = document.getElementById('someElementsId');
myView.build();

I'm not sure how you are planning to extract the model data from the HTML.

If this doesn't seem like a reasonable approach, please share more
code so I can see what is happening in your app.

Peter
Reply all
Reply to author
Forward
0 new messages