1 | "use strict";
|
2 |
|
3 | Object.defineProperty(exports, "__esModule", {
|
4 | value: true
|
5 | });
|
6 | exports.getNamePath = getNamePath;
|
7 | exports.containsNamePath = containsNamePath;
|
8 | exports.setValues = setValues;
|
9 | exports.matchNamePath = matchNamePath;
|
10 |
|
11 | var _typeUtil = require("./typeUtil");
|
12 |
|
13 | function _extends() { _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
|
14 |
|
15 | function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }
|
16 |
|
17 | function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
|
18 |
|
19 | function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
|
20 |
|
21 | function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && Symbol.iterator in Object(iter)) return Array.from(iter); }
|
22 |
|
23 | function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); }
|
24 |
|
25 | function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; }
|
26 |
|
27 | function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
|
28 |
|
29 |
|
30 |
|
31 |
|
32 |
|
33 |
|
34 |
|
35 |
|
36 | function getNamePath(path) {
|
37 | return (0, _typeUtil.toArray)(path);
|
38 | }
|
39 |
|
40 | function containsNamePath(namePathList, namePath) {
|
41 | return namePathList && namePathList.some(function (path) {
|
42 | return matchNamePath(path, namePath);
|
43 | });
|
44 | }
|
45 |
|
46 | function isObject(obj) {
|
47 | return _typeof(obj) === 'object' && obj !== null && Object.getPrototypeOf(obj) === Object.prototype;
|
48 | }
|
49 |
|
50 |
|
51 |
|
52 |
|
53 |
|
54 |
|
55 | function internalSetValues(store, values) {
|
56 | var newStore = Array.isArray(store) ? _toConsumableArray(store) : _extends({}, store);
|
57 |
|
58 | if (!values) {
|
59 | return newStore;
|
60 | }
|
61 |
|
62 | Object.keys(values).forEach(function (key) {
|
63 | var prevValue = newStore[key];
|
64 | var value = values[key];
|
65 |
|
66 | var recursive = isObject(prevValue) && isObject(value);
|
67 | newStore[key] = recursive ? internalSetValues(prevValue, value || {}) : value;
|
68 | });
|
69 | return newStore;
|
70 | }
|
71 |
|
72 | function setValues(store) {
|
73 | for (var _len = arguments.length, restValues = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
|
74 | restValues[_key - 1] = arguments[_key];
|
75 | }
|
76 |
|
77 | return restValues.reduce(function (current, newStore) {
|
78 | return internalSetValues(current, newStore);
|
79 | }, store);
|
80 | }
|
81 |
|
82 | function matchNamePath(namePath, changedNamePath) {
|
83 | if (!namePath || !changedNamePath || namePath.length !== changedNamePath.length) {
|
84 | return false;
|
85 | }
|
86 |
|
87 | return namePath.every(function (nameUnit, i) {
|
88 | return changedNamePath[i] === nameUnit;
|
89 | });
|
90 | } |
\ | No newline at end of file |