Simple events management for all object/HTML elements
Events exposes static methods
import Events from '@openmind/om-events';
Attach events to target
object
Events.on( target, 'eventname', function callback() {});
Events.one( target, 'eventname', function callback() {});
You can also use attach more than one event per time. You can use namespaces, too
Events.on( target, 'eventname.namespace', function callback() {});
Events.on( target, 'eventname.namespace.subspace', function callback() {});
Events.on( target, 'eventname.namespace otherevent.namespace', function callback() {});
Detach event from target
object
Events.off( target, 'eventname'); // detach all event-callbacks associated to given `eventname`
Events.off( target, 'eventname', callback); // detach given event-callback to given `eventname`
Events.off( target, 'eventname.namespace'); detach all event-callback associated to given `eventname` with given `namespace`
Events.off( target, '.namespace'); detach all events-callbacks with given 'namespace'
Trigger event to target
object
Events.trigger( target, 'eventname'); // detach all event-callbacks associated to given `eventname`
Events.trigger( target, 'eventname', callback); // detach given event-callback to given `eventname`
Events.trigger( target, 'eventname.namespace'); detach all event-callback associated to given `eventname` with given `namespace`
Events.trigger( target, '.namespace'); detach all events-callbacks with given 'namespace'
You can use dynamic methods
const eventObject = new Events(target);
Use all previous methods such as
eventObject.on('eventname', function callback() {});