Browse Source

`sub{Reducer,Middleware,Effex}` use `de{get,cow}`.

No code uses `cowValueModel` internally any more.
Herby Vojčík 5 years ago
parent
commit
f740830102
2 changed files with 10 additions and 9 deletions
  1. 2 2
      README.md
  2. 8 7
      src/sac.js

+ 2 - 2
README.md

@@ -6,7 +6,7 @@
 
 Creates a wrapper reducer that calls `reducer`
 on the sub-state specified by `key`.
-Key can go in different formats, see `cowValueModel` below.
+Key can go in different formats, see `deepGetOrNil` below.
 Rest of the state is left untouched.
 
 ```js
@@ -49,7 +49,7 @@ Creates a wrapper middleware
 on the sub-state specified by `key`
 or the selector function `selectorFn`
 by decorating `getState` part of the passed arg.
-The `key` can have different format, see `cowValueModel` below.
+The `key` can have different format, see `deepGetOrNil` below.
 Rest of the passed arg is left untouched.
 
 ```js

+ 8 - 7
src/sac.js

@@ -1,15 +1,16 @@
-import {cowValueModel} from './cow-value-model';
+import {decow, deget} from './cow-value-model';
 
 export const subReducer = (key, reducer, ...otherKeys) => {
-    const value = cowValueModel(key),
-        otherParts = otherKeys.map(each => cowValueModel(each));
+    const selector = deget(key),
+        modifier = decow(key),
+        otherParts = otherKeys.map(deget);
 
     return (state, action) => {
-        let newSubState = reducer(value(state), action, ...otherParts.map(value => value(state)));
+        let newSubState = reducer(selector(state), action, ...otherParts.map(eachSelector => eachSelector(state)));
         if (typeof newSubState === "undefined") {
             throw new Error(`The '${key}' reducer must not return undefined.`);
         }
-        return value(state, newSubState);
+        return modifier(newSubState)(state);
     };
 };
 
@@ -17,10 +18,10 @@ export const composeReducers = (...reducers) => (state, action) =>
     reducers.reduce((x, r) => r(x, action), state);
 
 export const subMiddleware = (keyOrSelectorFn, middleware) => {
-    const cow = typeof keyOrSelectorFn === "function" ? keyOrSelectorFn : cowValueModel(keyOrSelectorFn);
+    const selector = typeof keyOrSelectorFn === "function" ? keyOrSelectorFn : deget(keyOrSelectorFn);
     return (store, ...rest) => {
         const {getState} = store;
-        return middleware({...store, getState: () => cow(getState())}, ...rest);
+        return middleware({...store, getState: () => selector(getState())}, ...rest);
     };
 };