Hi Tom,
I've been thinking about something like that for a while. Since
Entwine decides what a particular key/value pair does (adds entwined
method, property, event handler, etc.) based on what's in the key, the
trick is to find a key format that isn't going to clash with anything.
I quite like using '&' - did you take that from sass? Do you think
that just at the beginning would be enough, or anywhere in the
selector, i.e.
$('div.movie').entwine({
'body.foo &': {
}
});
Obviously the second could be abused to produce totally unreadable
code, but it could still be useful in some situations.
Another reason I like using '&' is that we can use the same syntax for
delegated events. Currently there's a pattern I use a lot for getting
events from non-children elements that looks like
$('foo').entwine({
onmatch: function(){
var self = this;
this.parent('bar').bind('change', function()
{ self.onchangefromparent(); });
}
...
});
Which I don't like - every onmatch adds a performance penalty, and
binding like that causes a reference to be created, so elements don't
get garbage collected like they should unless you carefully unbind.
We could use the same syntax to do
$('foo').entwine({
'onchange from bar:has(&)': function(){
...
}
});
Hamish Friedlander