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/Getting Started Guide.md
+10-3Lines changed: 10 additions & 3 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -201,11 +201,9 @@ Let's take a look at a quick example that shows how ReactiveReSwift supports Red
201
201
The simplest example of a middleware, is one that prints all actions to the console. Here's how you can implement it:
202
202
203
203
```swift
204
-
let loggingMiddleware = Middleware<State> { getState, dispatch, action in
204
+
let loggingMiddleware = Middleware<State>().sideEffect { getState, dispatch, action in
205
205
// perform middleware logic
206
206
print(action)
207
-
// call next middleware
208
-
return action
209
207
}
210
208
```
211
209
You can define which middleware you would like to use when creating your store:
@@ -219,3 +217,12 @@ Store(
219
217
)
220
218
```
221
219
The actions will pass through the middleware in the order in which they are arranged in the `Middleware` initializer, however ideally middleware should not make any assumptions about when exactly it is called.
220
+
221
+
`Middleware` supports multiple different operations.
222
+
223
+
In no particular order, some of the more important operations are:
224
+
225
+
-`sideEffect(_:)` Gives access to the `dispatch(_:)` function. Does not return, to ensure that only side effects reside inside.
226
+
-`filter(_:)` If the predicate function passed to filter passes, keep the action, otherwise discard the action.
227
+
-`map(_:)` Apply a transformative function to the action.
228
+
-`flatMap(_:)` Essentially a `map` that can also filter out the action by returning `nil`
0 commit comments