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
vareventify=require('ngraph.events');varyourObject={};// any javascript objecteventify(yourObject);// now any object can listen to events from your objectyourObject.on('beep',function(name){console.log('Hello '+name);});// and you can fire events from your object:yourObject.fire('beep','World!');// prints 'Hello World!'// stop listen to events:yourObject.off('beep');
More advanced examples:
vareventify=require('ngraph.events');varyourObject=eventify({});// Pass context to event handler as last argument:yourObject.on('beep',function(){console.log(this===yourObject);},yourObject);yourObject.fire('beep');// prints true;// Pass additional arguments to fire:varonBop=function(x,y){console.log(x+y);};yourObject.on('bop',onBop);yourObject.fire('bop',40,2);// prints 42;// Remove given event handler for 'bop' eventyourObject.off('bop',onBop);// Remove all event listeners from your object:yourObject.off();
Why?
I wanted a light-weight eventing library, so I built this.