@webkrafters/react-observable-context 4.0.0 → 4.1.0-alpha.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -3,12 +3,16 @@ Object.defineProperty(exports, "__esModule", {
3
3
  value: true
4
4
  });
5
5
  exports.arrangePropertyPaths = arrangePropertyPaths;
6
+ exports.getProperty = exports.clonedeep = void 0;
7
+ exports.isDataContainer = isDataContainer;
6
8
  exports.makeReadonly = makeReadonly;
7
9
  exports.mapPathsToObject = mapPathsToObject;
8
- var _lodash = _interopRequireDefault(require("lodash.get"));
9
- var _lodash2 = _interopRequireDefault(require("lodash.has"));
10
+ var _lodash = _interopRequireDefault(require("lodash.clonedeepwith"));
11
+ var _lodash2 = _interopRequireDefault(require("lodash.get"));
10
12
  var _lodash3 = _interopRequireDefault(require("lodash.isplainobject"));
13
+ var _clonedeepEligibilityCheck = _interopRequireDefault(require("./clonedeep-eligibility-check"));
11
14
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
15
+ function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }
12
16
  function _createForOfIteratorHelper(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (!it) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e) { throw _e; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var normalCompletion = true, didErr = false, err; return { s: function s() { it = it.call(o); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e2) { didErr = true; err = _e2; }, f: function f() { try { if (!normalCompletion && it["return"] != null) it["return"](); } finally { if (didErr) throw err; } } }; }
13
17
  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); }
14
18
  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; }
@@ -58,6 +62,122 @@ function arrangePropertyPaths(propertyPaths) {
58
62
  return Object.keys(superPathTokensMap);
59
63
  }
60
64
  ;
65
+ var clonedeep = function () {
66
+ var clone = function clone(value) {
67
+ var customizer = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : function (v) {
68
+ if (v === null) {
69
+ return;
70
+ }
71
+ if (_typeof(v) === 'object') {
72
+ if ('clone' in v && typeof v.clone === 'function') {
73
+ return v.clone();
74
+ }
75
+ if ('cloneNode' in v && typeof v.cloneNode === 'function') {
76
+ return v.cloneNode(true);
77
+ }
78
+ }
79
+ if (!(0, _clonedeepEligibilityCheck["default"])(v).isEligible) {
80
+ return v;
81
+ }
82
+ };
83
+ return (0, _lodash["default"])(value, customizer);
84
+ };
85
+ var clonedeep = function clonedeep(value) {
86
+ return clone(value);
87
+ };
88
+ return clonedeep;
89
+ }();
90
+ exports.clonedeep = clonedeep;
91
+ var getProperty = function () {
92
+ var reDelimiter = /[\[\]|\.]+/g;
93
+ var reEndBracketLastChar = /\]$/;
94
+ var reType = /.*\s(\w+)\]$/;
95
+ var fromSource = function fromSource(source, key, defaultValue) {
96
+ var exists = false;
97
+ var index = +key;
98
+ try {
99
+ if (Array.isArray(source)) {
100
+ if (Number.isInteger(index)) {
101
+ if (index < 0) {
102
+ index = source.length + index;
103
+ }
104
+ var _value2 = source[index];
105
+ return {
106
+ _value: _value2,
107
+ exists: index in source,
108
+ index: index,
109
+ key: key,
110
+ source: source,
111
+ value: _value2 !== null && _value2 !== void 0 ? _value2 : defaultValue
112
+ };
113
+ }
114
+ }
115
+ var _value = source[key];
116
+ exists = key in source;
117
+ return {
118
+ _value: _value,
119
+ exists: exists,
120
+ index: index,
121
+ key: key,
122
+ source: source,
123
+ value: _value !== null && _value !== void 0 ? _value : defaultValue
124
+ };
125
+ } catch (e) {
126
+ return {
127
+ _value: defaultValue,
128
+ exists: exists,
129
+ index: index,
130
+ key: key,
131
+ source: source,
132
+ value: defaultValue
133
+ };
134
+ }
135
+ };
136
+ var getImmediateParent = function getImmediateParent(source, parentPath) {
137
+ var pLen = parentPath.length;
138
+ if (!pLen) {
139
+ return source;
140
+ }
141
+ var segmentStart = 0;
142
+ for (var p = segmentStart; p < pLen; p++) {
143
+ var key = parentPath[p];
144
+ var kNum = +key;
145
+ if (Number.isInteger(kNum) && kNum < 0) {
146
+ source = (0, _lodash2["default"])(source, parentPath.slice(segmentStart, p));
147
+ segmentStart = p + 1;
148
+ source = fromSource(source, key).value;
149
+ if (segmentStart === pLen || typeof source === 'undefined') {
150
+ break;
151
+ }
152
+ }
153
+ }
154
+ if (segmentStart === 0) {
155
+ return (0, _lodash2["default"])(source, parentPath);
156
+ }
157
+ if (segmentStart === pLen || typeof source === 'undefined') {
158
+ return source;
159
+ }
160
+ return (0, _lodash2["default"])(source, parentPath.slice(segmentStart, pLen));
161
+ };
162
+ var getInfo = function getInfo(source, path, defaultValue) {
163
+ switch (Object.prototype.toString.call(path).replace(reType, '$1')) {
164
+ case 'String':
165
+ path = path.replace(reEndBracketLastChar, '').split(reDelimiter);
166
+ break;
167
+ case 'Array':
168
+ break;
169
+ default:
170
+ path = [path];
171
+ }
172
+ var key = path.pop();
173
+ return fromSource(getImmediateParent(source, path), key, defaultValue);
174
+ };
175
+ return getInfo;
176
+ }();
177
+ exports.getProperty = getProperty;
178
+ function isDataContainer(v) {
179
+ return (0, _lodash3["default"])(v) || Array.isArray(v);
180
+ }
61
181
  function makeReadonly(v) {
62
182
  var frozen = true;
63
183
  if ((0, _lodash3["default"])(v)) {
@@ -97,10 +217,12 @@ function mapPathsToObject(source, propertyPaths) {
97
217
  try {
98
218
  for (_iterator3.s(); !(_step3 = _iterator3.n()).done;) {
99
219
  var _path2 = _step3.value;
100
- if (!(0, _lodash2["default"])(source, _path2)) {
220
+ var _getProperty = getProperty(source, _path2),
221
+ exists = _getProperty.exists,
222
+ value = _getProperty.value;
223
+ if (!exists) {
101
224
  continue;
102
225
  }
103
- var value = (0, _lodash["default"])(source, _path2);
104
226
  for (var tokens = _path2.split('.'), tLen = tokens.length, t = 0; t < tLen; t++) {
105
227
  var token = tokens[t];
106
228
  if (t + 1 === tLen) {
package/package.json CHANGED
@@ -7,9 +7,8 @@
7
7
  "steveswork <stephen.isienyi@gmail.com> (https://github.com/steveswork)"
8
8
  ],
9
9
  "dependencies": {
10
- "lodash.clonedeep": "^4.5.0",
10
+ "lodash.clonedeepwith": "^4.5.0",
11
11
  "lodash.get": "^4.4.2",
12
- "lodash.has": "^4.5.2",
13
12
  "lodash.isboolean": "^3.0.3",
14
13
  "lodash.isempty": "^4.4.0",
15
14
  "lodash.isequal": "^4.5.0",
@@ -52,6 +51,8 @@
52
51
  "index.js",
53
52
  "dist/utils/index.js",
54
53
  "dist/utils/index.d.ts",
54
+ "dist/utils/clonedeep-eligibility-check.js",
55
+ "dist/utils/clonedeep-eligibility-check.d.ts",
55
56
  "dist/types.d.ts",
56
57
  "dist/model/storage/index.js",
57
58
  "dist/model/storage/index.d.ts",
@@ -61,6 +62,8 @@
61
62
  "dist/model/accessor-cache/index.d.ts",
62
63
  "dist/model/accessor/index.js",
63
64
  "dist/model/accessor/index.d.ts",
65
+ "dist/main/set-state/tag-functions/index.js",
66
+ "dist/main/set-state/tag-functions/index.d.ts",
64
67
  "dist/main/set-state/index.js",
65
68
  "dist/main/set-state/index.d.ts",
66
69
  "dist/main/index.js",
@@ -125,9 +128,10 @@
125
128
  "build": "eslint --fix && rm -rf dist && babel src -d dist && npx -p typescript tsc",
126
129
  "postbuild": "node ./post-builder",
127
130
  "test": "eslint --fix && jest --coverage --updateSnapshot",
131
+ "test:clean": "jest --clearCache",
128
132
  "test:core": "jest --updateSnapshot",
129
133
  "test:watch": "eslint --fix && jest --updateSnapshot --watchAll"
130
134
  },
131
135
  "types": "dist/main/index.d.ts",
132
- "version": "4.0.0"
136
+ "version": "4.1.0-alpha.0"
133
137
  }