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: README.md
+29-31Lines changed: 29 additions & 31 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -10,20 +10,6 @@ As a consequence, of the fix, the library also introduce an elegant approach in
10
10
A `deferred action` is an `action` that is not immediately dispatched, but rather scheduled to be dispatched later.
11
11
In contrast with `reducers` (that given an action and the state, provides the new state), a `scheduler` is a function that given the current context and a deferred action, can execute (user defined) side effects, and return (or not) a cleanup/cancellation function associated with.
12
12
13
-
## Installation
14
-
15
-
```console
16
-
$ yarn add rescript-react-restate
17
-
```
18
-
19
-
or
20
-
21
-
```console
22
-
$ npm install --save rescript-react-restate
23
-
```
24
-
25
-
Then add `rescript-react-restate` to your `bsconfig.json``bs-dependencies` field.
26
-
27
13
## Handling side effects (Asynchronous actions, logging, etc.)
28
14
29
15
`Restate` powers up reducers by allow them not just update state, but also defer an action to be dispatched later if is desired. This is useful when you want to handle side effects (like logging, network requests, etc.) after the state has been updated.
@@ -44,36 +30,23 @@ type deferredAction =
44
30
| LogIncrement
45
31
| LogDecrement
46
32
47
-
// Because of implementation details related on how we clean up the side effects, we need to provide a way to identify each deferred action. In other words, deferred actions, must have a unique identifier.
48
-
module DeferredAction: Restate.HasDeferredAction with type t = deferredAction = {
49
-
type t = deferredAction
50
-
let variantId = action =>
51
-
switch action {
52
-
| LogIncrement => "LogIncrement"
53
-
| LogDecrement => "LogDecrement"
54
-
}
55
-
}
56
-
57
-
// Instantiate the reducer with your deferred action type
If you'd rather initialize state lazily (if there's some computation you don't want executed at every render for instance), use `useReducerWithMapState` where the first argument is a function taking `unit` and returning the initial state.
103
76
77
+
## Installation
78
+
79
+
```console
80
+
$ yarn add rescript-react-restate
81
+
```
82
+
83
+
or
84
+
85
+
```console
86
+
$ npm install --save rescript-react-restate
87
+
```
88
+
89
+
Then add `rescript-react-restate` to your `bsconfig.json``bs-dependencies` field.
0 commit comments