backbone.fwd icon indicating copy to clipboard operation
backbone.fwd copied to clipboard

Add event filtering

Open jamesplease opened this issue 11 years ago • 0 comments

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, ...);

jamesplease avatar May 17 '14 21:05 jamesplease