Top
craft-uikit
craft-widget-

NotificationCenter

NotificationCenter

Source:

Global event manager.

Example

// source
// you can use any keyword for your event name, and also can use wild card

Craft.Core.NotificationCenter.notify('Entity/path.to.attribute.updated',message);
Craft.Core.NotificationCenter.notify('Entity/path.to.attribute.deleted',message);
Craft.Core.NotificationCenter.notify('Entity/path.to.*',message);

// listener
// NotificationCenter returns serial id for your listener entry, that can be used to un-listen the event.

const serial = Craft.Core.NotificationCenter.listen('Entity.updated',handler);
Craft.Core.NotificationCenter.notify('Entity.updated',handler);

Craft.Core.NotificationCenter.remove('Entity.updated',serial);

Methods

(static) listen(event, handler)

Source:

Register event listener

Parameters:
Name Type Description
event String

event name

handler function

handler

(static) once(event, handler)

Source:

Register event listener only onece fired

Parameters:
Name Type Description
event String

event name

handler function

handler

(static) notify(event, obj)

Source:

Fire event

Parameters:
Name Type Description
event String

event name

obj Object

argument (optional)

(static) remove(event, serial)

Source:

Remove listener

Parameters:
Name Type Description
event String

event name

serial Number

serial id