Skip to content

Commit

Permalink
Document async interop initialization
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexandrHoroshih committed Mar 7, 2024
1 parent d11ec51 commit a3f183e
Showing 1 changed file with 31 additions and 0 deletions.
31 changes: 31 additions & 0 deletions apps/website/docs/redux/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,37 @@ Explicit `setup` event is required to initialize the interoperability. Usually i

You can read more about this practice [in the "Explicit start of the app" article](/magazine/explicit_start).

#### Async initialization

You can also defer interop object initialization and Redux Store creation in time.

The `createReduxIntegration` overload without explicit `reduxStore` allows you to pass the Store via `setup` event later.

```ts
// src/shared/redux-interop
export const startReduxInterop = createEvent<ReduxStore>();
export const reduxInterop = createReduxIntegration({
setup: startReduxInterop,
})

// src/entrypoint.ts
import { startReduxInterop } from 'shared/redux-interop';

const myReduxStore = configureStore({
// ...
});

startReduxInterop(myReduxStore)
// or, if you use the Fork API
allSettled(startReduxInterop, {
scope: clientScope,
params: myReduxStore,
})
```
In that case the type support for `reduxInterop.$state` will be slightly worse and `reduxInterop.dispatch` will be no-op (and will show warnings in console) until interop object is provided with Redux Store.

☝️ This is useful, if your project has cyclic dependencies.

### Interoperability object

Redux Interoperability object provides few useful APIs.
Expand Down

0 comments on commit a3f183e

Please sign in to comment.