berkeleys-redux-utils
Advanced tools
Comparing version 2.0.0 to 2.1.0
@@ -0,1 +1,11 @@ | ||
<a name="2.1.0"></a> | ||
# [2.1.0](https://github.com/BerkeleyTrue/berkeleys-redux-utils/compare/v2.0.0...v2.1.0) (2017-09-05) | ||
### Features | ||
* **combineReducers:** Throw when double combinedReducers ([a280c38](https://github.com/BerkeleyTrue/berkeleys-redux-utils/commit/a280c38)) | ||
<a name="2.0.0"></a> | ||
@@ -2,0 +12,0 @@ # [2.0.0](https://github.com/BerkeleyTrue/berkeleys-redux-utils/compare/v1.0.0...v2.0.0) (2017-09-05) |
@@ -19,2 +19,3 @@ 'use strict'; | ||
var isCombinedReducer = Symbol('@@isCombinedReducer'); | ||
var isEmpty = Symbol('@@isEmpty'); | ||
@@ -30,2 +31,4 @@ function combineReducers() { | ||
if (reducer && reducer[isCombinedReducer]) { | ||
// if is an empty combinedReducer, filter out | ||
!!reducer[isEmpty] ? process.env.NODE_ENV !== 'production' ? (0, _invariant2.default)(false, '\nfound a combined reducer that has already been cleared.\ncheck the reducer with the name ' + reducer[isEmpty] + '\n') : (0, _invariant2.default)(false) : void 0; | ||
_reducer = reducer.getCached(); | ||
@@ -36,2 +39,3 @@ reducer.clearCache(); | ||
}, []); | ||
reducers.forEach(function (reducer) { | ||
@@ -46,4 +50,6 @@ !(typeof reducer === 'function') ? process.env.NODE_ENV !== 'production' ? (0, _invariant2.default)(false, 'reducers should be functions but found ' + reducer) : (0, _invariant2.default)(false) : void 0; | ||
finalReducer.clearCache = function () { | ||
var names = Array.from(cache.keys()).join('|'); | ||
cache.clear(); | ||
cache = null; | ||
finalReducer[isEmpty] = names; | ||
}; | ||
@@ -50,0 +56,0 @@ finalReducer.getCached = function () { |
{ | ||
"name": "berkeleys-redux-utils", | ||
"version": "2.0.0", | ||
"version": "2.1.0", | ||
"main": "lib/index.js", | ||
@@ -5,0 +5,0 @@ "scripts": { |
@@ -6,2 +6,3 @@ import invariant from 'invariant'; | ||
const isCombinedReducer = Symbol('@@isCombinedReducer'); | ||
const isEmpty = Symbol('@@isEmpty'); | ||
@@ -13,2 +14,10 @@ export default function combineReducers(...reducers) { | ||
if (reducer && reducer[isCombinedReducer]) { | ||
// if is an empty combinedReducer, filter out | ||
invariant( | ||
!reducer[isEmpty], | ||
` | ||
found a combined reducer that has already been cleared. | ||
check the reducer with the name ${reducer[isEmpty]} | ||
`, | ||
); | ||
_reducer = reducer.getCached(); | ||
@@ -19,2 +28,3 @@ reducer.clearCache(); | ||
}, []); | ||
reducers.forEach(reducer => { | ||
@@ -36,4 +46,6 @@ invariant( | ||
finalReducer.clearCache = () => { | ||
const names = Array.from(cache.keys()).join('|'); | ||
cache.clear(); | ||
cache = null; | ||
finalReducer[isEmpty] = names; | ||
}; | ||
@@ -40,0 +52,0 @@ finalReducer.getCached = () => Array.from(cache.values()); |
38823
598
17