Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/main' into 2023-12-11-merge-main…
Browse files Browse the repository at this point in the history
…-into-v2
  • Loading branch information
lawrence-forooghian committed Dec 11, 2023
2 parents 717733d + fdd5a56 commit 694babc
Show file tree
Hide file tree
Showing 21 changed files with 2,276 additions and 4,650 deletions.
3 changes: 3 additions & 0 deletions .github/workflows/check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,7 @@ jobs:
- run: npm run lint
- run: npm run format:check
- run: npx tsc --noEmit ably.d.ts modules.d.ts build/ably-webworker.min.d.ts
# for some reason, this doesn't work in CI using `npx attw --pack .`
- run: npm pack
- run: npx attw ably-$(npm show ably version).tgz --summary
- run: npm audit --production
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@

This contains only the most important and/or user-facing changes; for a full changelog, see the commit history.

## [1.2.48](https://github.com/ably/ably-js/tree/1.2.48) (2023-11-20)

- Enable 'derived' options in 'useChannel' hook (by @rustworthy) [\#1501](https://github.com/ably/ably-js/pull/1501)
- fix: use 'ably' as import path from react-hooks [\#1509](https://github.com/ably/ably-js/pull/1509)

## [1.2.47](https://github.com/ably/ably-js/tree/1.2.47) (2023-11-02)

- fix(react): fix issue where useChannel would error upon router navigation or hmr [\#1478](https://github.com/ably/ably-js/pull/1478)
Expand Down
2 changes: 1 addition & 1 deletion ably.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2620,7 +2620,7 @@ declare namespace Types {
*
* @returns A promise which, upon success, will be fulfilled with a page of results for message and presence history, stats, and REST presence requests. Upon failure, the promise will be rejected with an {@link ErrorInfo} object which explains the error.
*/
next(): Promise<PaginatedResult<T>>;
next(): Promise<PaginatedResult<T> | null>;
/**
* Returns the `PaginatedResult` for the current page of results.
*/
Expand Down
23 changes: 23 additions & 0 deletions docs/react.md
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,29 @@ const { channel } = useChannel({ channelName: "your-channel-name", options: { ..
});
```

[Subscription filters](https://ably.com/docs/channels#filter-subscribe) are also supported:

```javascript
const deriveOptions = { filter: 'headers.email == `"[email protected]"` || headers.company == `"domain"`' }
const { channel } = useChannel({ channelName: "your-derived-channel-name", options: { ... }, deriveOptions }, (message) => {
...
});
```

Please note that attempts to publish to a derived channel (the one created or retrieved with a filter expression) will fail. In order to send messages to the channel called _"your-derived-channel-name"_ from the example above, you will need to create another channel instance without a filter expression.

```javascript
const channelName = "your-derived-channel-name";
const options = { ... };
const deriveOptions = { filter: 'headers.email == `"[email protected]"` || headers.company == `"domain"`' }
const callback = (message) => { ... };

const { channel: readOnlyChannelInstance } = useChannel({ channelName, options, deriveOptions }, callback);
const { channel: readWriteChannelInstance } = useChannel({ channelName, options }, callback); // NB! No 'deriveOptions' passed here

readWriteChannelInstance.publish("test-message", { text: "message text" });
```

---

### usePresence
Expand Down
Loading

0 comments on commit 694babc

Please sign in to comment.