Skip to content

Commit

Permalink
docs(signal): ListenerInterface
Browse files Browse the repository at this point in the history
  • Loading branch information
alimd committed Mar 22, 2022
1 parent 38ef029 commit 44a055b
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 5 deletions.
20 changes: 17 additions & 3 deletions package/signal/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -200,14 +200,28 @@ Example:
const listener = contentChangeSignal.addListener((content) => console.log(content));
```

### `removeListener(listener)`
### Listener API Interface

#### `listener.disabled`

Disable the listener, not called anymore.

Example:

```ts
const listener = contentChangeSignal.addListener((content) => console.log(content));
...
listener.disabled = true;
```

#### `listener.remove()`

Remove listener from specific signal.

Example:

```ts
const listenerId = contentChangeSignal.addListener((content) => console.log(content));
const listener = contentChangeSignal.addListener((content) => console.log(content));
...
contentChangeSignal.removeListener(listenerId);
listener.remove();
```
6 changes: 4 additions & 2 deletions package/signal/src/signal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -249,12 +249,14 @@ export class ListenerInterface<SignalName extends keyof AlwatrSignals> {
}

/**
* Disable signal, all dispatch's ignored (just value updated) and no more listeners will be called.
* Disable the listener, not called anymore.
*
* Example:
*
* ```ts
* contentChangeSignal.disabled = true;
* const listener = contentChangeSignal.addListener((content) => console.log(content));
* ...
* listener.disabled = true;
* ```
*/
get disabled(): boolean {
Expand Down

0 comments on commit 44a055b

Please sign in to comment.