Skip to content

Commit

Permalink
docs(readme): add clear method documentation
Browse files Browse the repository at this point in the history
Add documention to the new clear method. Update previous docs.
  • Loading branch information
bencelaszlo committed Oct 2, 2024
1 parent 261c3fd commit 5ebb3bc
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ npm install chiisai-event-emitter

### Subscribe to an Event

Use `EventEmitter.subscribe(eventName, callback)` to subscribe to an event.

```ts
import { EventEmitter } from 'chiisai-event-emitter';

Expand All @@ -37,6 +39,8 @@ eventEmitter.emit('event')

### Unsubscibe

`EventEmitter.subscribe(eventName, callback)` method returns a function which can be called to unsubscribe the callback from the event.

```ts
const unsubscibe = eventEmitter.subscribe('event', () => console.log('event-handler called!'));
unsubscribe();
Expand All @@ -45,6 +49,20 @@ eventEmitter.emit('event')
// (nothing happened)
```

### Delete an Event

`EventEmitter.clear(eventName)` method removes an event and all callbacks subscibed to this event.

```ts
eventEmitter.subscribe('event', () => console.log('event-handler called!'));
eventEmitter.subscribe('event', () => console.log('another event-handler called!'));
eventEmitter.clear('event')

eventEmitter.emit('event')
// (nothing happened)

```

[build-img]:https://github.com/bencelaszlo/chiisai-event-emitter/actions/workflows/release.yml/badge.svg
[build-url]:https://github.com/bencelaszlo/chiisai-event-emitter/actions/workflows/release.yml
[downloads-img]:https://img.shields.io/npm/dt/chiisai-event-emitter
Expand Down

0 comments on commit 5ebb3bc

Please sign in to comment.