Skip to main content

SipaEvents

SipaEvents

SipaEvents

Provides adding and triggering customized events.

new SipaEvents(...valid_event_names)

ParamTypeDescription
...valid_event_namesstringdefine the available event names

Example

// To add to a class, the suggested pattern is

events() {
return this._events ??= new SipaEvents(['click','delete','update']);
}

sipaEvents._event_registry : Object.<string, Array.<function()>>

Here we store registered events

sipaEvents.subscribe(event_name, callback)

Kind: instance method of SipaEvents

ParamTypeDescription
event_namestringmust be one of this._valid_event_names
callbackfunction

sipaEvents.unsubscribe(event_name, callback)

Kind: instance method of SipaEvents

ParamType
event_namestring
callbackfunction

sipaEvents.unsubscribeAll(event_name)

Unsubscribe all subscriptions of the given event name.

Usually you should only use the unsubscribe() method to unsubscribe. Use this method with care!

Param
event_name

sipaEvents.trigger(event_name, msg, options)

Calls all registered events of event_name

ParamTypeDefaultDescription
event_nameString
msgArray.<any>params to pass to the created event function
optionsObject
options.validatebooleantruevalidate the given event name to be valid

sipaEvents.reset()

Unsubscribes all subscriptions of any event

sipaEvents.createEvents(...event_names)

Extend valid event names dynamically

ParamType
...event_namesstring

sipaEvents.deleteEvents(...event_names)

Delete valid event names dynamically

ParamType
...event_namesstring