-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
ykomissarov
committed
Jun 13, 2018
1 parent
47119e6
commit 266159e
Showing
8 changed files
with
947 additions
and
193 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,12 @@ | ||
{ | ||
"extends": "airbnb" | ||
"extends": "airbnb-base", | ||
"parser": "babel-eslint", | ||
"parserOptions": { | ||
"ecmaVersion": 7, | ||
"sourceType": "module" | ||
}, | ||
"rules": { | ||
"indent": [2, 4, {"SwitchCase": 1, "ignoredNodes": ["ConditionalExpression"]}], | ||
"object-curly-spacing": ["error", "never"] | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,41 +1,37 @@ | ||
import invariant from 'invariant'; | ||
|
||
const composeReducers = (...reducers) => { | ||
|
||
invariant(reducers.length, 'At least one reducer is required'); | ||
reducers.forEach((r, index) => invariant(typeof r === 'function', '%s reducer is not a function', index)); | ||
reducers.forEach((r, index) => | ||
invariant(typeof r === 'function', '%s reducer is not a function', index)); | ||
|
||
if (reducers.length === 1) { | ||
return (state, action) => reducers[0](state, action); | ||
} else if (reducers.length === 2) { | ||
return (state, action) => { | ||
if (!state) { | ||
const first = reducers[0](undefined, action); | ||
return {...first, ...reducers[1](undefined, action)} | ||
} else { | ||
const first = reducers[0](state, action); | ||
return reducers[1](first, action); | ||
return {...first, ...reducers[1](undefined, action)}; | ||
} | ||
const first = reducers[0](state, action); | ||
return reducers[1](first, action); | ||
}; | ||
} else { | ||
return (state, action) => { | ||
if (!state) { | ||
return reducers.reduce( | ||
(accumulator, currentReducer) => ({ | ||
...accumulator, | ||
...currentReducer(state, action) | ||
}), | ||
state, | ||
); | ||
} else { | ||
return reducers.reduce( | ||
(accumulator, currentReducer) => currentReducer(accumulator, action), | ||
state, | ||
); | ||
} | ||
|
||
} | ||
} | ||
return (state, action) => { | ||
if (!state) { | ||
return reducers.reduce( | ||
(accumulator, currentReducer) => ({ | ||
...accumulator, | ||
...currentReducer(undefined, action), | ||
}), | ||
state, | ||
); | ||
} | ||
return reducers.reduce( | ||
(accumulator, currentReducer) => currentReducer(accumulator, action), | ||
state, | ||
); | ||
}; | ||
}; | ||
|
||
export default composeReducers; | ||
export default composeReducers; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.