|
@@ -60,10 +60,11 @@ composeReducers(
|
|
)
|
|
)
|
|
```
|
|
```
|
|
|
|
|
|
-### `subMiddleware(key, middleware)`
|
|
|
|
|
|
+### `subMiddleware(key | selectorFn, middleware)`
|
|
|
|
|
|
Creates a wrapper middleware
|
|
Creates a wrapper middleware
|
|
on the sub-state specified by `key`
|
|
on the sub-state specified by `key`
|
|
|
|
+or the selector function `selectorFn`
|
|
by decorating `getState` part of the passed arg.
|
|
by decorating `getState` part of the passed arg.
|
|
You may use dot notation.
|
|
You may use dot notation.
|
|
Rest of the passed arg is left untouched.
|
|
Rest of the passed arg is left untouched.
|
|
@@ -74,7 +75,12 @@ const r = subMiddleware("persons", ({getState}) => next => action => {
|
|
return next(action);
|
|
return next(action);
|
|
});
|
|
});
|
|
|
|
|
|
-// use r in creation of store
|
|
|
|
|
|
+const altR = subMiddleware(state => state.persons, ({getState}) => next => action => {
|
|
|
|
+ console.log(JSON.stringify(getState()));
|
|
|
|
+ return next(action);
|
|
|
|
+});
|
|
|
|
+
|
|
|
|
+// use r or altR in creation of store
|
|
|
|
|
|
store.getState();
|
|
store.getState();
|
|
// => {persons: ["John", "Jill"], cars: ["Honda"]}
|
|
// => {persons: ["John", "Jill"], cars: ["Honda"]}
|
|
@@ -91,11 +97,12 @@ one of the properties passed is `getState` function;
|
|
it is not special-case for middleware.
|
|
it is not special-case for middleware.
|
|
For example, it is usable for wrapping `redux-effex` effect function.
|
|
For example, it is usable for wrapping `redux-effex` effect function.
|
|
|
|
|
|
-### `subEffex(key, effects)`
|
|
|
|
|
|
+### `subEffex(key | selectorFn, effects)`
|
|
|
|
|
|
Creates a wrapper around each element
|
|
Creates a wrapper around each element
|
|
of the effects array
|
|
of the effects array
|
|
on the sub-state specified by `key`
|
|
on the sub-state specified by `key`
|
|
|
|
+or by selector function `selectorFn`
|
|
by decorating `effect` function with `subMiddleware`
|
|
by decorating `effect` function with `subMiddleware`
|
|
and returns the array of the wrapped effects.
|
|
and returns the array of the wrapped effects.
|
|
|
|
|
|
@@ -107,7 +114,10 @@ const effects = [{
|
|
}
|
|
}
|
|
}];
|
|
}];
|
|
|
|
|
|
-// use effects in creation of store
|
|
|
|
|
|
+const e = subEffex("persons", effects);
|
|
|
|
+const altE = subEffex(state => state.persons, effects);
|
|
|
|
+
|
|
|
|
+// use e or altE in creation of store
|
|
|
|
|
|
store.getState();
|
|
store.getState();
|
|
// => {persons: ["John", "Jill"], cars: ["Honda"]}
|
|
// => {persons: ["John", "Jill"], cars: ["Honda"]}
|