gsimpleevents
v1.0.0
Published
Provide simple class to manage custom events.
Downloads
24
Readme
#GSimpleEvents This provides a utility class called Events.
Would be nice if sometimes you could add custom events to an object in your code. This class provides that basic functionality.
#Usage
To use this, create a new events object, passing in an array of named events
let events = new Events(['onFileUpload', 'onUserIdle']);
or, if you're in a class:
this.events = new Events(['onClosed', 'onMinimized', 'onResized']);
after it's constructed, listeners can be added:
let id = someObject.events.onClosed.addListener((optionalParameters) => { // do a thing })
This will return an ID number which you can use to remove the listener later, or just pass the function in if it's not anonymous.
someObject.events.onClosed.removeListener(id)
.
The even can be fired like so:
events.onClosed.fire([optional, parameters, array])
The parameters passed into fire will be applied to the callback, as input parameters (not as an array)
#Author: Greg Miller, gmiller.net