api.events

Registering and triggering events

events.removeAllEventListeners()

Remove all registered events

events.on(name, eventType, func)

Register event listener for a specific plugin

Param Type Description
name string The plugin which listens for the event.
eventType string The event to listen for.
func function Function to call when event is triggered.

Example

import {api, event} from 'writer'
api.events.on('myplugin', Event.DOCUMENT_CHANGED, (event) => {
   // React on event
})

events.off(name, eventType)

Unregister event listener for a specific plugin.

Param Type Description
name string The plugin which listens for the event.
eventType string The event to stop listening for.

Example

import {api, event} from 'writer'
api.events.off('myplugin', Event.DOCUMENT_CHANGED)

events.trigger(name, eventType, [data])

Trigger an event of specified type with optional specified data

Param Type Default Description
name string Plugin name or originator of event
eventType string Event type to trigger (mandatory)
[data] object Optional data structure to send with event

Example

import {api, event} from 'writer'
api.events.trigger(
   'myplugin',
   Event.DOCUMENT_CHANGED,
   {
      type: 'edit',
      action: 'edit',
      data: {
         key: 'strange things'
      }
   }
)

events.triggerEvent()

Deprecated

Use api.events.trigger() instead, deprecated. Deprecated since 2018-11-20.

events.documentChanged()

Deprecated

Use api.events.trigger() with Event.DOCUMENT_CHANGED instead. Deprecated since 2018-11-20.

events.externalUpdate()

Deprecated

Use api.events.trigger() with Event.DOCUMENT_CHANGED_EXTERNAL instead. Deprecated since 2018-11-20.

events.documentReplaced()

Deprecated

Use api.events.trigger() with Event.DOCUMENT_REPLACED instead. Deprecated since 2018-11-20.

events.documentSaved()

Deprecated

Use api.events.trigger() with Event.DOCUMENT_SAVED instead. Deprecated since 2018-11-20.

events.documentSaveFailed()

Deprecated

Use api.events.trigger() with Event.DOCUMENT_SAVE_FAILED instead. Deprecated since 2018-11-20.

events.userActionSave()

Deprecated

Use api.events.trigger() with Event.USERACTION_SAVE instead. Deprecated since 2018-11-20.

events.userActionCancelSave()

Deprecated

Use api.events.trigger() with Event.USERACTION_CANCEL_SAVE instead. Deprecated since 2018-11-20.

events.userActionLock()

Deprecated

Use api.events.trigger() with Event.USERACTION_LOCK instead. Deprecated since 2018-11-20.

events.userActionUnlock()

Deprecated

Use api.events.trigger() with Event.USERACTION_UNLOCK instead. Deprecated since 2018-11-20.

events.languageChanged()

Deprecated

Use api.events.trigger() with Event.ARTICLELANGUAGE_CHANGED instead. Deprecated since 2018-11-20.

events.onDocumentStartSaving()

Deprecated

Use api.events.trigger() with "document:startsaving" instead. Deprecated since 2018-11-20.

results matching ""

    No results matching ""