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
0. Let's take a look at the following illustration:
252
+
0. Let's take a look at the following illustration:
253
253
The blue box is the `View` (think UI).
254
254
The `Presenter` or `ViewModel` has not been drawn for the sake of readability but you can think of having such additional layers between View and Redux State Machine.
255
255
The yellow box represents a `Store`.
@@ -258,19 +258,19 @@ The pink box is a `SideEffect`
258
258
Additionally, a green circle represents `State` and a red circle represents an `Action` (see next step).
259
259
On the right you see a UI mock of a mobile app to illustrate UI changes.
260
260
261
-
1. `NextPageAction` gets triggered from the UI (by scrolling at the end of the list). Every `Action` goes through the `reducer` and all `SideEffects` registered for this type of Action.
261
+
1. `NextPageAction` gets triggered from the UI (by scrolling at the end of the list). Every `Action` goes through the `reducer` and all `SideEffects` registered for this type of Action.
262
262
263
-
2. `Reducer` is not interested in `NextPageAction`. So while `NextPageAction` goes through the reducer, it doesn't change the state.
263
+
2. `Reducer` is not interested in `NextPageAction`. So while `NextPageAction` goes through the reducer, it doesn't change the state.
264
264
265
-
3. `loadNextPageSideEffect` (pink box), however, cares about `NextPageAction`. This is the trigger to run the side-effect.
265
+
3. `loadNextPageSideEffect` (pink box), however, cares about `NextPageAction`. This is the trigger to run the side-effect.
266
266
267
-
4. So `loadNextPageSideEffect` takes `NextPageAction` and starts doing the job and makes the http request to load the next page from backend. Before doing that, this side effect starts with emitting `LoadPageAction`.
267
+
4. So `loadNextPageSideEffect` takes `NextPageAction` and starts doing the job and makes the http request to load the next page from backend. Before doing that, this side effect starts with emitting `LoadPageAction`.
268
268
269
-
5. `Reducer` takes `LoadPageAction` emitted from the side effect and reacts on it by "reducing the state".
269
+
5. `Reducer` takes `LoadPageAction` emitted from the side effect and reacts on it by "reducing the state".
270
270
This means `Reducer` knows how to react on `LoadPageAction` to compute the new state (showing progress indicator at the bottom of the list).
271
271
Please note that the state has changed (highlighted in green) which also results in changing the UI (progress indicator at the end of the list).
272
272
273
-
6. Once `loadNextPageSideEffect` gets the result back from backend, the side effect emits a new `PageLoadedAction`.
273
+
6. Once `loadNextPageSideEffect` gets the result back from backend, the side effect emits a new `PageLoadedAction`.
274
274
This Action contains a "payload" - the loaded data.
275
275
276
276
```dart
@@ -280,7 +280,7 @@ class PageLoadedAction implements Action {
280
280
}
281
281
```
282
282
283
-
7. As any other Action `PageLoadedAction` goes through the `Reducer`. The Reducer processes this Action and computes a new state out of it by appending the loaded data to the already existing data (progress bar also is hidden).
283
+
7. As any other Action `PageLoadedAction` goes through the `Reducer`. The Reducer processes this Action and computes a new state out of it by appending the loaded data to the already existing data (progress bar also is hidden).
284
284
285
285
Final remark:
286
286
This system allows you to create a plugin in system of `SideEffects` that are highly reusable and specific to do a single use case.
0 commit comments