backbone.fwd
backbone.fwd copied to clipboard
Add event filtering
I wrote a similar library for your very own Wreqr over here, heh heh.
One feature I added was event filtering. The code there for filtering is bad (really the lot of it is), but if you used the space-separated format to attach multiple listeners it should be pretty simple to do.
Possible API
// Accept an array
parent.fwd(child, {
filter: [ 'event:one', 'event:two' ]
});
// Or a space-separated list
parent.fwd(child, {
filter: 'event:one event:two'
});
Implementation
// before you call this.listenTo
var forwardedEvents = this.filter || 'all';
// if filter is an array
forwardedEvents = this.filter.join(' ');
// once it's space-separated...
this.listenTo('source', forwardedEvents, ...);