Plugin API
API
Plugins can be a callable "thing" or an object with a public callable setup
method which will be called by the library upon intialisation. The init method will get a reference to the library and can subscribe to events via the on
method like so:
const plugin = (optInOut) => {
optInOut.on('optIn', eventCallback);
optInOut.on('optOut', eventCallback);
};
const pluginObject = {
setup: function(lib) {
lib.on('optIn', eventCallback);
lib.on('optOut', eventCallback);
}
}
Event callbacks get passed two arguments:
data
: an object with all the data passed from the triggering methodevent
: the name of the event
Events
The following events are triggered & published by the library:
init
: called after everything has been initialized- Arguments:
- lib: OptInOut-object
- Arguments:
optIn
:- Arguments:
- service: the service key
- storage: the storage key
- date: the date set
- Arguments:
optOut
:- Arguments:
- service: the service key
- storage: the storage key
- date: the date set
- Arguments: