Treibstoff contains an event dispatcher to inherit from. It supports subscribing
and unsubscribing handlers to (named) events and implementing default handlers
for events on the class directly.
import{Events}from'events'/** * Custom event dispatcher. */classMyDispatcherextendsEvents{/** * Default event handler if 'on_my_event' gets triggered on an * instance of ``MyDispatcher`` * * @param {Object} options - Options passed to ``tigger``. */on_my_event(options){}}/** * External subscriber function. * * @param {Events} inst - ``Events`` instance the ``trigger`` * function was called on. * @param {Object} options - Options passed to ``tigger``. */letmy_subscriber(inst,options){}// Create dispatcherletdsp=newMyDispatcher();// Bind external subscriber functiondsp.on('on_my_event',my_subscriber);// Trigger eventdsp.trigger('on_my_event',{foo:'bar'});// Unbind external subscriber function.dsp.off('on_my_event',my_subscriber);