native-document 1.0.80 → 1.0.81

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.
@@ -548,6 +548,7 @@ var NativeComponents = (function (exports) {
548
548
  this.$currentValue = value;
549
549
  this.$isCleanedUp = false;
550
550
 
551
+ this.$firstListener = null;
551
552
  this.$listeners = null;
552
553
  this.$watchers = null;
553
554
 
@@ -583,7 +584,7 @@ var NativeComponents = (function (exports) {
583
584
  };
584
585
 
585
586
  ObservableItem.prototype.triggerFirstListener = function(operations) {
586
- this.$listeners[0](this.$currentValue, this.$previousValue, operations || {});
587
+ this.$firstListener(this.$currentValue, this.$previousValue, operations || {});
587
588
  };
588
589
 
589
590
  ObservableItem.prototype.triggerListeners = function(operations) {
@@ -632,22 +633,29 @@ var NativeComponents = (function (exports) {
632
633
  };
633
634
 
634
635
  ObservableItem.prototype.triggerAll = function(operations) {
635
- this.triggerListeners(operations);
636
636
  this.triggerWatchers();
637
+ this.triggerListeners(operations);
637
638
  };
638
639
 
639
640
  ObservableItem.prototype.triggerWatchersAndFirstListener = function(operations) {
640
- this.triggerListeners(operations);
641
641
  this.triggerWatchers();
642
+ this.triggerListeners(operations);
642
643
  };
643
644
 
644
645
  ObservableItem.prototype.assocTrigger = function() {
646
+ this.$firstListener = null;
645
647
  if(this.$watchers?.size && this.$listeners?.length) {
646
648
  this.trigger = (this.$listeners.length === 1) ? this.triggerWatchersAndFirstListener : this.triggerAll;
647
649
  return;
648
650
  }
649
651
  if(this.$listeners?.length) {
650
- this.trigger = (this.$listeners.length === 1) ? this.triggerFirstListener : this.triggerListeners;
652
+ if(this.$listeners.length === 1) {
653
+ this.$firstListener = this.$listeners[0];
654
+ this.trigger = this.triggerFirstListener;
655
+ }
656
+ else {
657
+ this.trigger = this.triggerListeners;
658
+ }
651
659
  return;
652
660
  }
653
661
  if(this.$watchers?.size) {
@@ -2300,7 +2308,7 @@ var NativeComponents = (function (exports) {
2300
2308
 
2301
2309
  mutationMethods.forEach((method) => {
2302
2310
  ObservableArray.prototype[method] = function(...values) {
2303
- const result = this.$currentValue[method](...values);
2311
+ const result = this.$currentValue[method].apply(this.$currentValue, values);
2304
2312
  this.trigger({ action: method, args: values, result });
2305
2313
  return result;
2306
2314
  };
@@ -2308,7 +2316,7 @@ var NativeComponents = (function (exports) {
2308
2316
 
2309
2317
  noMutationMethods.forEach((method) => {
2310
2318
  ObservableArray.prototype[method] = function(...values) {
2311
- return this.$currentValue[method](...values);
2319
+ return this.$currentValue[method].apply(this.$currentValue, values);
2312
2320
  };
2313
2321
  });
2314
2322
 
@@ -2326,7 +2334,7 @@ var NativeComponents = (function (exports) {
2326
2334
  };
2327
2335
 
2328
2336
  ObservableArray.prototype.merge = function(values) {
2329
- this.$currentValue.push(...values);
2337
+ this.$currentValue.push.apply(this.$currentValue, values);
2330
2338
  this.trigger({ action: 'merge', args: values });
2331
2339
  };
2332
2340
 
@@ -2402,7 +2410,7 @@ var NativeComponents = (function (exports) {
2402
2410
  const deps = Array.isArray(predicate.dependencies)
2403
2411
  ? predicate.dependencies
2404
2412
  : [predicate.dependencies];
2405
- observableDependencies.push(...deps);
2413
+ observableDependencies.push.apply(observableDependencies, deps);
2406
2414
  }
2407
2415
  } else if(typeof predicate === 'function') {
2408
2416
  filterCallbacks[key] = predicate;
@@ -322,6 +322,7 @@ var NativeDocument = (function (exports) {
322
322
  this.$currentValue = value;
323
323
  this.$isCleanedUp = false;
324
324
 
325
+ this.$firstListener = null;
325
326
  this.$listeners = null;
326
327
  this.$watchers = null;
327
328
 
@@ -357,7 +358,7 @@ var NativeDocument = (function (exports) {
357
358
  };
358
359
 
359
360
  ObservableItem.prototype.triggerFirstListener = function(operations) {
360
- this.$listeners[0](this.$currentValue, this.$previousValue, operations || {});
361
+ this.$firstListener(this.$currentValue, this.$previousValue, operations || {});
361
362
  };
362
363
 
363
364
  ObservableItem.prototype.triggerListeners = function(operations) {
@@ -406,22 +407,29 @@ var NativeDocument = (function (exports) {
406
407
  };
407
408
 
408
409
  ObservableItem.prototype.triggerAll = function(operations) {
409
- this.triggerListeners(operations);
410
410
  this.triggerWatchers();
411
+ this.triggerListeners(operations);
411
412
  };
412
413
 
413
414
  ObservableItem.prototype.triggerWatchersAndFirstListener = function(operations) {
414
- this.triggerListeners(operations);
415
415
  this.triggerWatchers();
416
+ this.triggerListeners(operations);
416
417
  };
417
418
 
418
419
  ObservableItem.prototype.assocTrigger = function() {
420
+ this.$firstListener = null;
419
421
  if(this.$watchers?.size && this.$listeners?.length) {
420
422
  this.trigger = (this.$listeners.length === 1) ? this.triggerWatchersAndFirstListener : this.triggerAll;
421
423
  return;
422
424
  }
423
425
  if(this.$listeners?.length) {
424
- this.trigger = (this.$listeners.length === 1) ? this.triggerFirstListener : this.triggerListeners;
426
+ if(this.$listeners.length === 1) {
427
+ this.$firstListener = this.$listeners[0];
428
+ this.trigger = this.triggerFirstListener;
429
+ }
430
+ else {
431
+ this.trigger = this.triggerListeners;
432
+ }
425
433
  return;
426
434
  }
427
435
  if(this.$watchers?.size) {
@@ -2147,14 +2155,6 @@ var NativeDocument = (function (exports) {
2147
2155
  return null;
2148
2156
  };
2149
2157
 
2150
- const findByPath = (root, path) => {
2151
- let target = root;
2152
- for (let i = 0, len = path.length; i < len; i++) {
2153
- target = target.childNodes[path[i]];
2154
- }
2155
- return target;
2156
- };
2157
-
2158
2158
  const $hydrateFn = function(hydrateFunction, targetType, element, property) {
2159
2159
  if(!cloneBindingsDataCache.has(element)) {
2160
2160
  // { classes, styles, attributes, value, attach }
@@ -2180,27 +2180,43 @@ var NativeDocument = (function (exports) {
2180
2180
  }
2181
2181
  };
2182
2182
 
2183
+
2184
+ const applyBindingTreePath = (root, target, data, path) => {
2185
+ let newTarget = null;
2186
+ if(path.fn) {
2187
+ newTarget = path.fn(data, target, root);
2188
+ }
2189
+ if(path.children) {
2190
+ for(let i = 0, length = path.children.length; i < length; i++) {
2191
+ const currentPath = path.children[i];
2192
+ const pathTargetNode = target.childNodes[currentPath.index];
2193
+ applyBindingTreePath(root, pathTargetNode, data, currentPath);
2194
+ }
2195
+ }
2196
+ return newTarget;
2197
+ };
2198
+
2183
2199
  function TemplateCloner($fn) {
2184
2200
  let $node = null;
2185
2201
  let $hasBindingData = false;
2186
2202
 
2187
- const $bindingPaths = [];
2203
+ const $bindingTreePath = {
2204
+ fn: null,
2205
+ children: [],
2206
+ };
2188
2207
 
2189
- const clone = (node, data, path) => {
2208
+ const clone = (node, data, currentPath) => {
2190
2209
  const bindDingData = cloneBindingsDataCache.get(node);
2191
2210
  if(node.nodeType === 3) {
2192
2211
  if(bindDingData && bindDingData.value) {
2193
- $bindingPaths.push({
2194
- path: [...path],
2195
- fn: (data, targetNode, currentRoot) => {
2196
- const newNode = bindDingData.value(data);
2197
- targetNode.replaceWith(newNode);
2198
- if (targetNode === currentRoot) {
2199
- return newNode;
2200
- }
2201
- return null;
2212
+ currentPath.fn = (data, targetNode, currentRoot) => {
2213
+ const newNode = bindDingData.value(data);
2214
+ if (targetNode === currentRoot) {
2215
+ return newNode;
2202
2216
  }
2203
- });
2217
+ targetNode.replaceWith(newNode);
2218
+ return null;
2219
+ };
2204
2220
  return bindDingData.value(data);
2205
2221
  }
2206
2222
  return node.cloneNode(true);
@@ -2212,35 +2228,35 @@ var NativeDocument = (function (exports) {
2212
2228
  if(bindDingData) {
2213
2229
  bindAttributes(nodeCloned, bindDingData, data);
2214
2230
  bindAttachMethods(nodeCloned, bindDingData, data);
2215
- $bindingPaths.push({
2216
- path: [...path],
2217
- fn: (data, targetNode) => {
2218
- bindAttributes(targetNode, bindDingData, data);
2219
- bindAttachMethods(targetNode, bindDingData, data);
2220
- }
2221
- });
2231
+ currentPath.fn = (data, targetNode) => {
2232
+ bindAttributes(targetNode, bindDingData, data);
2233
+ bindAttachMethods(targetNode, bindDingData, data);
2234
+ };
2222
2235
  }
2223
2236
  const childNodes = node.childNodes;
2237
+ const bindingPathChildren = [];
2224
2238
  for(let i = 0, length = childNodes.length; i < length; i++) {
2225
2239
  const childNode = childNodes[i];
2226
- path.push(i);
2240
+ const path = { index: i, fn: null };
2227
2241
  const childNodeCloned = clone(childNode, data, path);
2228
- path.pop();
2242
+ if(path.children || path.fn) {
2243
+ bindingPathChildren.push(path);
2244
+ }
2229
2245
  nodeCloned.appendChild(childNodeCloned);
2230
2246
  }
2247
+ if(bindingPathChildren.length) {
2248
+ currentPath.children = currentPath.children || [];
2249
+ currentPath.children = bindingPathChildren;
2250
+ }
2231
2251
  return nodeCloned;
2232
2252
  };
2233
2253
 
2234
2254
  const cloneWithBindingPaths = (data) => {
2235
2255
  let root = $node.cloneNode(true);
2236
2256
 
2237
- for (let i = 0, len = $bindingPaths.length; i < len; i++) {
2238
- const binding = $bindingPaths[i];
2239
- const target = findByPath(root, binding.path);
2240
- const newRoot = binding.fn(data, target, root);
2241
- if(newRoot) {
2242
- root = newRoot;
2243
- }
2257
+ const newRoot = applyBindingTreePath(root, root, data, $bindingTreePath);
2258
+ if(newRoot) {
2259
+ root = newRoot;
2244
2260
  }
2245
2261
 
2246
2262
  return root;
@@ -2253,7 +2269,7 @@ var NativeDocument = (function (exports) {
2253
2269
  return $node.cloneNode(true);
2254
2270
  }
2255
2271
 
2256
- const firstClone = clone($node, data, []);
2272
+ const firstClone = clone($node, data, $bindingTreePath);
2257
2273
  this.clone = cloneWithBindingPaths;
2258
2274
  return firstClone;
2259
2275
  };
@@ -2897,7 +2913,7 @@ var NativeDocument = (function (exports) {
2897
2913
 
2898
2914
  mutationMethods.forEach((method) => {
2899
2915
  ObservableArray.prototype[method] = function(...values) {
2900
- const result = this.$currentValue[method](...values);
2916
+ const result = this.$currentValue[method].apply(this.$currentValue, values);
2901
2917
  this.trigger({ action: method, args: values, result });
2902
2918
  return result;
2903
2919
  };
@@ -2905,7 +2921,7 @@ var NativeDocument = (function (exports) {
2905
2921
 
2906
2922
  noMutationMethods.forEach((method) => {
2907
2923
  ObservableArray.prototype[method] = function(...values) {
2908
- return this.$currentValue[method](...values);
2924
+ return this.$currentValue[method].apply(this.$currentValue, values);
2909
2925
  };
2910
2926
  });
2911
2927
 
@@ -2923,7 +2939,7 @@ var NativeDocument = (function (exports) {
2923
2939
  };
2924
2940
 
2925
2941
  ObservableArray.prototype.merge = function(values) {
2926
- this.$currentValue.push(...values);
2942
+ this.$currentValue.push.apply(this.$currentValue, values);
2927
2943
  this.trigger({ action: 'merge', args: values });
2928
2944
  };
2929
2945
 
@@ -2999,7 +3015,7 @@ var NativeDocument = (function (exports) {
2999
3015
  const deps = Array.isArray(predicate.dependencies)
3000
3016
  ? predicate.dependencies
3001
3017
  : [predicate.dependencies];
3002
- observableDependencies.push(...deps);
3018
+ observableDependencies.push.apply(observableDependencies, deps);
3003
3019
  }
3004
3020
  } else if(typeof predicate === 'function') {
3005
3021
  filterCallbacks[key] = predicate;