Backbone.js captures RegEx events?

I looked around but couldn't find anything, is it possible to add an event listener according to the RegEx rule?

i.e:.

EventBus.trigger('catalog:filter'); EventBus.trigger('catalog:removed'); 

And I want to catch them in two different ways: 1) Direct binding to ie event:

 EventBus.on('catalog:filter', callback); 

2) Binding for the RegEx test and capturing all events of this type ie:

 EventBus.on(/catalog/, callback); 

The second is to catch and process the event directory: filter and directory: deleted. This is the same as the โ€œchangeโ€ and โ€œchange: [attribute]โ€ method of event binding. It does not have to be a RegEx object to work.

thanks

+4
source share
1 answer

Both of your problems can be resolved with names containing basic events. I use it in a large project as a broadcast application bus, and it does wonders. Here you can find one of the Backbone.namespaced-events implementations, and here is Dereck Bailey's message on dos / donts agregation events Re -enabling the trunk event aggregator: lessons learned

0
source

Source: https://habr.com/ru/post/1478926/


All Articles