You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: recipes/advanced/using-in-redux-application/README.md
+68-1Lines changed: 68 additions & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -6,4 +6,71 @@ If you are new to **simplux** there is [a recipe](../../basics/getting-started#r
6
6
7
7
> You can play with the code for this recipe in this [code sandbox](https://codesandbox.io/s/github/MrWolfZ/simplux/tree/master/recipes/advanced/using-in-redux-application).
8
8
9
-
This recipe is still a work-in-progress.
9
+
Before we start let's install all the packages we need.
10
+
11
+
```sh
12
+
npm i @simplux/core redux -S
13
+
```
14
+
15
+
Now we're ready to go.
16
+
17
+
For this recipe we assume we have a very simple existing application that uses redux to manage a counter. In your application this setup is probably quite a bit more complex with many more reducers, middlewares and such. All of these things do not affect **simplux**, so you can keep them just as they are.
const counterReducer:Reducer<number> = (c=0, { type }) =>
23
+
type==='INC'?c+1:c
24
+
25
+
const rootReducer =combineReducers({
26
+
counter: counterReducer,
27
+
})
28
+
29
+
const store =createStore(rootReducer)
30
+
```
31
+
32
+
**simplux** is built on top of Redux. However, instead of wrapping Redux it is designed to seamlessly compose with it. To achieve this **simplux** exports its root reducer which you can place anywhere in your reducer hierarchy. Therefore, we only need to make a slight adjustment to the store setup above.
33
+
34
+
```ts
35
+
import { getSimpluxReducer } from'@simplux/core'
36
+
37
+
const rootReducer =combineReducers({
38
+
counter: counterReducer,
39
+
40
+
// this key can be anything, but it is recommended to name the
41
+
// slice of state that simplux is responsible for "simplux"
42
+
simplux: getSimpluxReducer(),
43
+
})
44
+
```
45
+
46
+
Now there is only one more step that is required. We need to let **simplux** know about our new store.
0 commit comments