Closed ghost closed 7 years ago
Happy to consider it, but the issue is that from our experience, it's extremely useful to have a mediator that allows wildcard subscriptions.
That sounds like functionality you can add to the mediator.
var boundEvents = $.data(document, 'events'); $.each(boundEvents, function () { if (this.indexOf("")) // Checks each event name for an asterisk console.log(this);
// alerts the namespace of the first handler bound to this event name
console.log(this[0].namespace);
});
The prospect of removing the dependence on EE2 and doing the extra logic within the Mediator is exciting because it would lead the way to a '.collect()' implementation within the Mediator as well. See #322.
@addyosmani @sbellity
We don't need event emitter at all in the mediator. If you want complete library agnostic I would recommend doing this with the $ factory. there should already be a event library in what ever lib you are using and all of them or most of them support custom events even jquery.
The minnowjs script I am going to be putting in this week uses beanjs.
I would do custom events like
$(window).on("CUSTOM_EVENT_NAME", function(data){ console.log(data); });
then the usage is like $(window).trigger("CUSTOM_EVENT_NAME"); or $(window).trigger("CUSTOM_EVENT_NAME", {"someObj": ["one", "two"]});
Jquery is similar but I believe it doesn't work off of window but document should work.
http://www.sitepoint.com/jquery-custom-events/