forked from eyscode/redux-localstorage
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcreateSlicer.js
46 lines (37 loc) · 1.27 KB
/
createSlicer.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
'use strict';
Object.defineProperty(exports, '__esModule', {
value: true
});
exports['default'] = createSlicer;
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; }
var _getSubsetJs = require('./getSubset.js');
var _getSubsetJs2 = _interopRequireDefault(_getSubsetJs);
var _utilTypeOfJs = require('./util/typeOf.js');
var _utilTypeOfJs2 = _interopRequireDefault(_utilTypeOfJs);
/**
* @description
* createSlicer inspects the typeof paths and returns an appropriate slicer function.
*
* @param {String|String[]} [paths] The paths argument supplied to persistState.
*
* @return {Function} A slicer function, which returns the subset to store when called with Redux's store state.
*/
function createSlicer(paths) {
switch ((0, _utilTypeOfJs2['default'])(paths)) {
case 'void':
return function (state) {
return state;
};
case 'string':
return function (state) {
return (0, _getSubsetJs2['default'])(state, [paths]);
};
case 'array':
return function (state) {
return (0, _getSubsetJs2['default'])(state, paths);
};
default:
return console.error('Invalid paths argument, should be of type String, Array or Void');
}
}
module.exports = exports['default'];