You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
There is a new pattern that is being used across different projects now, and we realised that it could be made simpler.
It's a form of sticky events, but not really. An example:
// this will send a new listener for "status-changed" event the current statusthis.on(emitr.meta.AddListenerEvent,function(addEvent){if(addEvent.event==='status-changed'){addEvent.listener.call(addEvent.context,this._status);}}.bind(this));
So after discussing with @dchambers and @bit-shifter we decided to add a new method to emitr: .onMetaEvent(metaEvent, eventName, callback, ctx). And deprecate the current .on(metaEvent, ... (which will internally invoke the new method for backwards compatibility).
If eventName is null emitr instance will be told of every new listener, otherwise it will only be told of the event it is interested in.
callback will have the following signature: callback(eventName, sendToListenerFunc).
sendToListenerFunc will be a function that will take care of invoking the listener with the correct context and so on.
this seems like a specific instance of a more general concept - filtering event listeners based on some of their parameters. This functionality would be useful in normal events too, not just metaevents.
There is a new pattern that is being used across different projects now, and we realised that it could be made simpler.
It's a form of sticky events, but not really. An example:
So after discussing with @dchambers and @bit-shifter we decided to add a new method to emitr:
.onMetaEvent(metaEvent, eventName, callback, ctx)
. And deprecate the current.on(metaEvent, ...
(which will internally invoke the new method for backwards compatibility).If
eventName
isnull
emitr instance will be told of every new listener, otherwise it will only be told of the event it is interested in.callback
will have the following signature:callback(eventName, sendToListenerFunc)
.sendToListenerFunc
will be a function that will take care of invoking the listener with the correct context and so on.From a user's perspective it will look like this:
I'm just capturing what we discussed here, I'll make a PR as soon as I have some time :)
The text was updated successfully, but these errors were encountered: