redux-persist-transform-filter
Advanced tools
Comparing version 0.0.8 to 0.0.9
@@ -6,2 +6,5 @@ 'use strict'; | ||
}); | ||
exports.default = createFilter; | ||
exports.createWhitelistFilter = createWhitelistFilter; | ||
exports.createBlacklistFilter = createBlacklistFilter; | ||
exports.persistFilter = persistFilter; | ||
@@ -19,9 +22,15 @@ | ||
var _lodash5 = require('lodash.unset'); | ||
var _lodash6 = _interopRequireDefault(_lodash5); | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
exports.default = function (reducerName, inboundPaths, outboundPaths) { | ||
function createFilter(reducerName, inboundPaths, outboundPaths) { | ||
var transformType = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : 'whitelist'; | ||
return (0, _reduxPersist.createTransform)( | ||
// inbound | ||
function (inboundState, key) { | ||
return inboundPaths ? persistFilter(inboundState, inboundPaths) : inboundState; | ||
return inboundPaths ? persistFilter(inboundState, inboundPaths, transformType) : inboundState; | ||
}, | ||
@@ -31,8 +40,17 @@ | ||
function (outboundState, key) { | ||
return outboundPaths ? persistFilter(outboundState, outboundPaths) : outboundState; | ||
}, { whitelist: [reducerName] }); | ||
return outboundPaths ? persistFilter(outboundState, outboundPaths, transformType) : outboundState; | ||
}, { 'whitelist': [reducerName] }); | ||
}; | ||
function createWhitelistFilter(reducerName, inboundPaths, outboundPaths) { | ||
return createFilter(reducerName, inboundPaths, outboundPaths, 'whitelist'); | ||
} | ||
function createBlacklistFilter(reducerName, inboundPaths, outboundPaths) { | ||
return createFilter(reducerName, inboundPaths, outboundPaths, 'blacklist'); | ||
} | ||
function persistFilter(state) { | ||
var paths = arguments.length <= 1 || arguments[1] === undefined ? [] : arguments[1]; | ||
var paths = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : []; | ||
var transformType = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 'whitelist'; | ||
@@ -46,11 +64,24 @@ var subset = {}; | ||
paths.forEach(function (path) { | ||
var value = (0, _lodash2.default)(state, path); | ||
if (transformType === 'whitelist') { | ||
paths.forEach(function (path) { | ||
var value = (0, _lodash2.default)(state, path); | ||
if (typeof value !== 'undefined') { | ||
(0, _lodash4.default)(subset, path, value); | ||
} | ||
}); | ||
if (typeof value !== 'undefined') { | ||
(0, _lodash4.default)(subset, path, value); | ||
} | ||
}); | ||
} else if (transformType === 'blacklist') { | ||
subset = Object.assign({}, state); | ||
paths.forEach(function (path) { | ||
var value = (0, _lodash2.default)(state, path); | ||
if (typeof value !== 'undefined') { | ||
(0, _lodash6.default)(subset, path); | ||
} | ||
}); | ||
} else { | ||
subset = state; | ||
} | ||
return subset; | ||
} |
{ | ||
"name": "redux-persist-transform-filter", | ||
"version": "0.0.8", | ||
"version": "0.0.9", | ||
"description": "Filter transformator for redux-persist", | ||
@@ -9,3 +9,3 @@ "main": "dist/index.js", | ||
"build": "mkdir -p dist && babel index.js -o dist/index.js", | ||
"release": "npm test && npm build && release-it" | ||
"release": "npm test && npm run build && release-it" | ||
}, | ||
@@ -12,0 +12,0 @@ "repository": { |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
7922
115