-
Notifications
You must be signed in to change notification settings - Fork 56
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge remote-tracking branch 'origin/main' into 2023-11-01-merge-main…
…-into-v2 Other than fixing merge conflicts, the notable changes which bring the recently-added stuff in `main` in line with the changes from v2 are: - Removing mentions of the `ably/promises` and `Realtime.Promise` API from the React hooks code and documentation - Updating presence message extras test to use the promise-based API - Fixing a newly-introduced compilation error calling `wsConnection.send` in WebSocketTransport (not sure exactly why, but I’m guessing something to do with the upgrade to the `ws` library in `main` and perhaps some changes to TypeScript version in v2) — the fix, which uses a type assertion to always pretend we’re always in the Node case, is a bit dodgy but that’s because the signature of `ProtocolMessage.serialize` is also a bit dodgy (it refers to Buffer even though the code that uses it is also called on web). The package-lock.json merge conflicts were handled by fixing the package.json merge conflicts then running `npm install --lockfile-version 2` using Node 16.20.0. Using Node 18.18.2 seemed to lead to a lockfile that caused an error "@esbuild/android-arm not accessible from esbuild" when running `npm ci` in the Node 12 and 14 CI jobs.
- Loading branch information
Showing
64 changed files
with
12,413 additions
and
4,872 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -56,6 +56,7 @@ module.exports = { | |
"tools", | ||
"scripts", | ||
"docs", | ||
"react", | ||
"Gruntfile.js", | ||
], | ||
settings: { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
name: Test (react hooks) | ||
|
||
on: | ||
workflow_dispatch: | ||
pull_request: | ||
push: | ||
branches: | ||
- main | ||
|
||
jobs: | ||
build: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v2 | ||
- uses: actions/setup-node@v1 | ||
with: | ||
node-version: 16 | ||
- run: npm ci | ||
- run: npm run format:check | ||
- run: npm run test:react |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,4 +5,5 @@ node_modules | |
npm-debug.log | ||
.tool-versions | ||
build/ | ||
react/ | ||
docs/generated/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
# React hooks upgrade / migration guide | ||
|
||
## Version 2.x to 3.x | ||
|
||
### Hooks now return object | ||
|
||
In previous versions of our react hooks, the `useChannel` and `usePresence` hooks returned arrays. | ||
Since these hooks now return more values we've opted to change them to return objects. | ||
You can still access the return values using simple destructuring syntax like in the below example: | ||
|
||
```jsx | ||
const { channel, ably } = useChannel("your-channel-name", (message) => { /* ... */ }); | ||
|
||
const { presenceData, updateStatus } = usePresence("your-channel-name"); | ||
``` | ||
|
||
### Replacing `configureAbly` with `AblyProvider` | ||
|
||
In versions 1 and 2 of our react-hooks, we exported a function called `configureAbly` which was used to register an Ably client instance to global state. | ||
This caused a few issues (most notably it made the hooks difficult to use with hot module reloading), so we have replaced the global configuration function with a context provider (`AblyProvider`) | ||
The simplest way to use the context provider is to create your own ably-js client outside and then pass it as a prop to the `AblyProvider`. | ||
All child components of the `AblyProvider` will then be able to use the hooks, making use of the provided Ably client instance. For this reason, we recommend putting the `AblyProvider` high up in your component tree, surrounding all components which may need to use Ably hooks. | ||
|
||
For example, replace this: | ||
```jsx | ||
configureAbly(options); | ||
``` | ||
|
||
With this: | ||
```jsx | ||
const client = new Ably.Realtime(options); | ||
|
||
return <AblyProvider client={ably}> | ||
{children} | ||
</AblyProvider> | ||
``` | ||
|
||
If you were already using multiple Ably clients in the same react application, you may pass in an optional `id` prop to the provider, which you can then pass to the hooks to specify which Ably client instance the hook should use: | ||
```jsx | ||
const client = new Ably.Realtime(options); | ||
|
||
return <AblyProvider client={ably} id="foo"> | ||
{children} | ||
</AblyProvider> | ||
|
||
// in a child component: | ||
useChannel({channelName: 'my_channel', id: 'foo'}, (msg) => { | ||
console.log(msg); | ||
}); | ||
``` |
Oops, something went wrong.