-
Notifications
You must be signed in to change notification settings - Fork 39
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Shorthands for subview declaration #43
Comments
So you're thinking about something that would automatically parse the subviews attribute and call registerSubview for everything there? When would that get called? |
Yep. Just adding more attributes to the prepareView function that is created in _parseSubview and the model or collection to waitfor. It would be called on subviewParent.on('change'). Just like it is now. Something like this. (a very crude solution) // ## _parseSubview
// helper for parsing out the subview declaration and registering
// the `waitFor` if need be.
_parseSubview: function (subview, name) {
var self = this;
var opts = {
selector: subview.container || '[role=' + subview.role + ']',
waitFor: subview.waitFor || subview.model || subview.collection || '',
prepareView: subview.prepareView || function (el) {
return new subview.constructor({
el: el,
parent: self,
model: subview.model ? getPath(self, subview.model) : self.model,
collection: subview.collection ? getPath(self, subview.collection) : null
});
}
};
function action() {
var el, subview;
// if not rendered or we can't find our element, stop here.
if (!this.el || !(el = this.get(opts.selector))) return;
if (!opts.waitFor || getPath(this, opts.waitFor)) {
subview = this[name] = opts.prepareView.call(this, el);
subview.render();
this.registerSubview(subview);
this.off('change', action);
}
}
// we listen for main `change` items
this.on('change', action, this);
} |
I'd love to see that added. What's status here? |
The default return new subview.constructor({
el: el,
parent: self
}); So the subview will have a reference to its parent so you within the subview you could reference it by doing I like where you're going with this. I'll play around with an implementation. |
I'm currently using this fork where shorthands are implemented and waitFor takes multiple dependencies. |
closing per commit |
That's not in master yet |
Seems this isn't in master yet - please merge! 👍 |
That commit is from this branch afaik #64 Which has merge conflicts still. @HenrikJoreteg what are the odds we could take another look at that PR this week? |
@wraithgar I'm a +1 on simplifying things here, but there's certainly some variance in opinions on how to actually do it, I think that's why things stalled. Philip raised some valid concerns as feedback to my original PR. |
Henrik made some progress on this, but it wasn't quite all there yet. if someone wants to pick it up and run with it, feel free. however, given that it's not high priority, I am closing out until someone takes the reigns. |
Wouldn't it be great if you could do like this when you declared subviews?
Right now it looks like this in my code.
I can implement it, but first I would like to know if I missing something and if it is a good idea. What are the downsides to auto assigning parent model as model? What are the downsides to the two new shorthands?
The text was updated successfully, but these errors were encountered: