Skip to content

Commit

Permalink
Unsubscribing docs
Browse files Browse the repository at this point in the history
  • Loading branch information
cesarParra committed Oct 31, 2024
1 parent 352c818 commit 27ec701
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -796,6 +796,26 @@ The following storage helpers are available by default:
- `onError` A callback function called when an error response is received from the server for
handshake, connect, subscribe, and unsubscribe meta channels.

**Unsubscribing from the event bus**

When using the `useEventBus` storage, the signal will hold a special function called `unsubscribe` that you can call
to unsubscribe from the event bus.

```javascript
import { $signal, useEventBus } from "c/signals";

const receivedEvent = $signal(undefined, {
storage: useEventBus("/event/PlatEvent__e", ({ data }) => ({
message: data.payload.Message__c,
sender: data.payload.Sender__c,
time: data.payload.Time__c
}))
});

// Unsubscribe from the event bus
receivedEvent.unsubscribe();
```

### Creating a custom storage

The `storage` option receives a function that defines the behavior for where the data should be stored.
Expand Down

0 comments on commit 27ec701

Please sign in to comment.