remerge
Advanced tools
Comparing version 0.0.2 to 0.0.3
65
index.js
@@ -19,6 +19,4 @@ 'use strict'; | ||
var _shallowCopy = require('shallow-copy'); | ||
var _utils = require('./utils'); | ||
var _shallowCopy2 = _interopRequireDefault(_shallowCopy); | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
@@ -67,7 +65,27 @@ | ||
var _initial = function _initial(map) { | ||
if (!map) { | ||
return undefined; | ||
} else if (_lodash2.default.isFunction(map)) { | ||
return undefined; | ||
} else if (map['_'] !== undefined) { | ||
return map['_']; | ||
} | ||
var newMap = {}; | ||
for (var key in map) { | ||
if (!_getAccessorKey(key)) { | ||
var result = _initial(map[key]); | ||
if (result !== undefined) { | ||
newMap[key] = result; | ||
} | ||
} | ||
} | ||
return Object.keys(newMap).length > 0 ? newMap : null; | ||
}; | ||
var _process = function _process(_map, state, action) { | ||
var currentPath = action.type.split('.', 1)[0]; | ||
var newState = (0, _shallowCopy2.default)(state); | ||
var newState = _lodash2.default.clone(state); | ||
@@ -93,6 +111,13 @@ var _iteratorNormalCompletion = true; | ||
return child(newState, action); | ||
} else { | ||
} else if (accessorKeyName) { | ||
var smallerMap = child; | ||
var smallerState = accessorKeyName ? newState[key][action[accessorKeyName]] : newState[key]; | ||
var smallerState = undefined; | ||
if ((0, _utils.isMap)(newState[key])) { | ||
smallerState = newState[key].get(action[accessorKeyName]); | ||
} else { | ||
smallerState = newState[key][action[accessorKeyName]]; | ||
} | ||
var smallerAction = _extends({}, action, { | ||
@@ -103,9 +128,20 @@ type: action.type.split('.').splice(1).join(".") | ||
if (accessorKeyName) { | ||
var collection = (0, _shallowCopy2.default)(newState[key]); | ||
var collection = _lodash2.default.clone(newState[key]); | ||
if ((0, _utils.isMap)(newState[key])) { | ||
collection.set(action[accessorKeyName], newSmallerState); | ||
} else { | ||
collection[action[accessorKeyName]] = newSmallerState; | ||
newState[key] = collection; | ||
} else { | ||
newState[key] = newSmallerState; | ||
} | ||
newState[key] = collection; | ||
} else { | ||
var smallerMap = child; | ||
var smallerState = newState[key]; | ||
var smallerAction = _extends({}, action, { | ||
type: action.type.split('.').splice(1).join(".") | ||
}); | ||
var newSmallerState = _process(smallerMap, smallerState, smallerAction); | ||
newState[key] = newSmallerState; | ||
} | ||
@@ -132,5 +168,10 @@ } | ||
var initialState = _initial(map); | ||
var computedMap = _preprocess(map); | ||
return function (state, action) { | ||
if (state === undefined) { | ||
return initialState; | ||
} | ||
return _process(computedMap, state, action); | ||
@@ -137,0 +178,0 @@ }; |
@@ -14,3 +14,6 @@ "use strict"; | ||
*/ | ||
var arrayInsertReducer = exports.arrayInsertReducer = function arrayInsertReducer(state, action) { | ||
var arrayInsertReducer = exports.arrayInsertReducer = function arrayInsertReducer() { | ||
var state = arguments.length <= 0 || arguments[0] === undefined ? [] : arguments[0]; | ||
var action = arguments[1]; | ||
var index = action.insertIndex == undefined ? state.length : action.insertIndex; | ||
@@ -17,0 +20,0 @@ return [].concat(_toConsumableArray(state.slice(0, index)), [action.data], _toConsumableArray(state.slice(index))); |
{ | ||
"name": "remerge", | ||
"version": "0.0.2", | ||
"version": "0.0.3", | ||
"description": "State simplified.", | ||
@@ -42,4 +42,3 @@ "main": "index.js", | ||
"dependencies": { | ||
"lodash": "^4.5.1", | ||
"shallow-copy": "0.0.1" | ||
"lodash": "^4.5.1" | ||
}, | ||
@@ -46,0 +45,0 @@ "ava": { |
15706
1
9
219
- Removedshallow-copy@0.0.1
- Removedshallow-copy@0.0.1(transitive)