I'm just starting to get into Entwine, and I'm loving so far how much more organized my code is. One thing I find myself wanting to do a lot is define everything related to a given component under one entwine definition. As an example, I'll illustrate building an accordion component the standard way:
$('div.accordion').entwine({
onmatch: function() {this.find('.panel').close();}
// etc..
});
$('div.accordion .panel').entwine({
close: function() {....}
// etc
});
$('div.accordion h3 a').entwine({
onclick: function() {.....}
// etc
});
I tend to think of the div "accordion" as a class with its own methods and properties, e.g. $('div.accordion').closeAll(), but having to write separate entwine() definitions for every DOM element related to the accordion feels like a shortcoming. I'm wondering something like the following would be acceptable. (I'm guessing it's an abomination of the onmatch constructor).
$('div.accordion').entwine({
Panels: null,
Buttons: null
onmatch: function() {
this.setPanels(this.find('.panel'));
this.setButtons(this.find('h3 a'));
this.Panels.entwine({
close: function() {....},
open: function() {....}
});
this.Buttons.entwine({
onclick: function() {....}
});
this.Panels.close();
}
});
I'm not even sure if that code works. It's just a rough idea of what I want. Doesn't it just feel better to have everything under one roof, so to speak?