JavaScript framework to just sign up and fire custom events?

JavaScript framework makes it easy to listen / subscribe and trigger / fire custom events similar to Backbone.Events?

Just curious if there is any JS mini / micro framework / lib that I am missing ...

Backbone.Events does this, but any small / lib framework that just does this, or makes it simpler / better?

Thanks.

+4
source share
2 answers

I worked with Chaplin , which uses publish / subscribe .
You can search for some "intermediaries" such as Core.js , PubSub or Signal-js .
Links and user reviews in this post .

+3
source

The simplest way - if you use jQuery - use jQuery.trigger (equivalent to publishing) and jQuery.bind (equivalent to subscribing). Also jQuery.unbind (to unsubscribe).

You can use them with DOM events, as well as with custom events.

//Subsribe to my custom Event $(document).bind('MyCustomEvent', function() { alert('Reacting to my custom event ..'); }); // .... somewhere else in the code, publish the event jQuery.event.trigger('MyCustomEvent'); //or $(document).trigger('MyCustomEvent'); 

[Update from jquery documentation]

(Starting with jQuery 1.7, the .on () and .off () methods are preferred for attaching and removing event handlers on elements.)

+6
source

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


All Articles