The Events feature allows decoupled parts of the CMS to:
interface Events {
dispatch(event: Event): void
subscribe(eventType: string, listener: Listener): Unsubscribe
}
interface Event {
type: string
// Any other data may be added to the event.
[key: string]: any
}
type Listener = (event: Event) => void
type Unsubscribe = () => void
cms.events.dispatch({
type: 'something-happened',
})
The cms.events.subscribe
function can be used to start listening for certain events.
cms.events.subscribe(EVENT_NAME, event => {
// ...
})
The EVENT_NAME
is a string that matches a pattern for the event name.
Checkout the tests for specific examples of how the matching happens.
cms.events.subscribe('*', event => {
console.log(event)
})
cms.events.subscribe("plugins:add:form", (event) => {
console.log(`Added a Form called "${event.plugin.name}"`
})
cms.events.subscribe('plugins:*:form', event => {
console.log(`Something happened to the form plugins`)
})
cms.events.subscribe('plugins', event => {
console.log(`Something happened to the plugins`)
})
Note that the string plugins
is equivalent to plugins:*
or plugins:*:*
.
Type | Description |
---|---|
cms:enabled | The CMS has been enabled. |
cms:disabled | The CMS has been disabled |
sidebar:opened | The Sidebar has been opened |
sidebar:closed | The Sidebar has been closed. |
plugin:add:{__type} | A Plugin of a given __type has been added. |
plugin:remove:{__type} | A Plugin of a given __type has been removed. |
Event Name | Decription |
---|---|
github:error | An error has occurred when making requests to the GitHub API. |
github:branch:checkout | The current branch has been switched. |