3.3.1 • Published 1 year ago
@nextcloud/event-bus v3.3.1
@nextcloud/event-bus
A simple event bus to communicate between Nextcloud components.
Installation
npm install @nextcloud/event-bus --saveyarn add @nextcloud/event-busUsage
import { emit, subscribe, unsubscribe } from '@nextcloud/event-bus'
const h = (e) => console.info(e)
subscribe('a', h)
subscribe('b', h)
emit('a', {
data: 123,
})
unsubscribe('a', h)
unsubscribe('b', h)Typed events
It is also possible to type events, which allows type infering on the event-bus methods like emit, subscribe and unsubscribe.
To register new events, simply extend the NextcloudEvents interface:
- Create a file like
event-bus.d.ts:
declare module '@nextcloud/event-bus' {
interface NextcloudEvents {
'example-app:awesomeness:increased': { level: number }
}
}
export {}- Now if you use any of the event bus functions, the parameters will automatically be typed correctly:
import { subscribe } from '@nextcloud/event-bus'
subscribe('example-app:awesomeness:increased', (event) => {
// "event" automatically infers type { level: number}
console.log(event.level)
})Naming convention
To stay consistent, we encourage you to use the following syntax when declaring events
app-id:object:verb
Examples:
nextcloud:unified-search:closedfiles:node:uploadingfiles:node:uploadedfiles:node:deletedcontacts:contact:deletedcalendar:event:createdforms:answer:updated
Development
npm install
npm run build
npm run testRequirements
3.3.1
1 year ago
3.3.0
1 year ago
3.2.0
2 years ago
3.1.0
2 years ago
3.0.2
3 years ago
3.0.1
3 years ago
3.0.0
3 years ago
2.1.1
4 years ago
2.1.0
4 years ago
1.3.0
4 years ago
2.0.0
4 years ago
1.2.0
5 years ago
1.1.4
6 years ago
1.1.3
6 years ago
1.1.2
6 years ago
1.1.1
6 years ago
1.1.0
6 years ago
1.0.1
6 years ago
1.0.0
6 years ago
0.2.1
6 years ago
0.2.0
6 years ago
0.1.0
6 years ago