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: docs/README.md
+31-8Lines changed: 31 additions & 8 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -25,7 +25,7 @@ const loadState = (key) => ...
25
25
/**
26
26
* You define the structure that you want to save
27
27
* in this object, and then pass it as an argument.
28
-
* Instructions on how to create this object are above.
28
+
* Instructions on how to create this object are bellow.
29
29
*/
30
30
conststructure= {
31
31
orders: {
@@ -68,23 +68,31 @@ persistMiddleware.run(store)
68
68
69
69
For the load and save method, you don't have to write them by yourself, they are [available as separate packages below](#providers).
70
70
71
-
Your reducer data will automatically saved when the values are changed. You can load each reducer using its load action (to see all the load actions generated in your console set the fourth parameter of `createPersistMachine` to `true`).
71
+
Your reducer data will automatically save when the values are changed. You can load each reducer using its load action (to see all the load actions generated in your console set the fourth parameter of `createPersistMachine` to `true`).
72
72
73
73
74
74
### Loading Data
75
75
76
-
You can receive actions in your reducers. The code below will apply the saved state to your current state:
76
+
You can receive actions in your reducers.
77
+
78
+
This allows you to have loading on a per reducer basis separated across the application for stored data instead of having the full application wait for the data to be loaded.
79
+
80
+
The package exports a function that makes it easier for you to set up a case in the reducer, by generating an action name that matches the one that the package uses under the hood.
81
+
82
+
The code below will apply the saved state to your current state:
case getPersistMachineAction("load.subscriptionOrders"): {
88
+
return {
89
+
...state,
82
90
...action.payload,
83
91
}
84
92
}
85
93
```
86
94
87
-
This allows you to have loading on a per reducer basis separated across the application for stored data instead of having the full application wait for the data to be loaded.
95
+
Of course, you can also define your own custom action name. This custom action name has to be passed oon the `action` property of the reducer in the structure object.
88
96
89
97
The middleware runs: `action.payload = { ...storedData, ...action.payload };` to add the saved data to the payload when the `@ReduxPM/LoadActions` is triggered. You can also pass additional data in your payload to add context to your `@ReduxPM/LoadActions` for complex conditional consummation of the loaded data in your reducers.
90
98
@@ -105,14 +113,29 @@ Creates a Redux persist middleware with your store structure.
0 commit comments