@xroom.app/events
TypeScript icon, indicating that this package has built-in type declarations

1.0.2 • Public • Published

Wrapper over standard nodejs events

This package is deprecated and will be deleted soon

Use events2 package instead

Installation

Run from command line

npm i @xroom.app/events

Usage example

const { createEvent, createEventSystem } = require('@xroom.app/events')

/**
 * @template T
 *
 * @typedef {import('@xroom.app/events').Event<T>} Event
 */

const events = {
    /** @type {Event<{ roomId: string, options: Record<string, any> }>} */
    roomCreated: createEvent(),
    /** @type {Event<{ roomId: string }>} */
    roomRemoved: createEvent(),
}

const eventSystem = createEventSystem(Object.values(events))

eventSystem.on(events.roomCreated, ({ roomId }) => console.log(`Created a room with id ${roomId}`))
eventSystem.on(events.roomRemoved, ({ roomId }) => console.log(`Removed a room with id ${roomId}`))

eventSystem.emit(events.roomCreated, { roomId: 'foobar', options: {} })
eventSystem.emit(events.roomRemoved, { roomId: 'foobar' })

Package Sidebar

Install

npm i @xroom.app/events

Weekly Downloads

0

Version

1.0.2

License

MIT

Unpacked Size

7.93 kB

Total Files

5

Last publish

Collaborators

  • xroom.app