native-document 1.0.33 → 1.0.35

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.
@@ -265,9 +265,12 @@ var NativeDocument = (function (exports) {
265
265
 
266
266
  if($watchers.has($currentValue)) {
267
267
  const $currentValueCallbacks = $watchers.get($currentValue);
268
- if(!Validator.isArray($currentValueCallbacks)) {
269
- $currentValueCallbacks.set ? $currentValueCallbacks.set(true) : $currentValueCallbacks(true);
270
- } else {
268
+ if(typeof $currentValueCallbacks === "function") {
269
+ $currentValueCallbacks(true);
270
+ } else if ($currentValueCallbacks.set) {
271
+ $currentValueCallbacks.set(true);
272
+ }
273
+ else {
271
274
  $currentValueCallbacks.forEach(callback => {
272
275
  callback.set ? callback.set(true) : callback(true);
273
276
  });
@@ -276,7 +279,9 @@ var NativeDocument = (function (exports) {
276
279
  if($watchers.has($previousValue)) {
277
280
  const $previousValueCallbacks = $watchers.get($previousValue);
278
281
  if(typeof $previousValueCallbacks === "function") {
279
- $previousValueCallbacks.set ? $previousValueCallbacks.set(false) : $previousValueCallbacks(false);
282
+ $previousValueCallbacks(false);
283
+ } else if($previousValueCallbacks.set) {
284
+ $previousValueCallbacks.set(false);
280
285
  } else {
281
286
  $previousValueCallbacks.forEach(callback => {
282
287
  callback.set ? callback.set(false) : callback(false);
@@ -847,21 +852,26 @@ var NativeDocument = (function (exports) {
847
852
  element.nativeInsertBefore = element.insertBefore;
848
853
  element.nativeAppendChild = element.appendChild;
849
854
 
855
+ const isParentUniqueChild = (parent) => {
856
+ console.log('on passwr ici ', isUniqueChild || (parent.firstChild === anchorStart && parent.lastChild === anchorEnd));
857
+ return isUniqueChild || (parent.firstChild === anchorStart && parent.lastChild === anchorEnd);
858
+ };
859
+
850
860
  const insertBefore = function(parent, child, target) {
851
861
  const element = Validator.isElement(child) ? child : ElementCreator.getChild(child);
852
862
  if(parent === element) {
853
863
  parent.nativeInsertBefore(element, target);
854
864
  return;
855
865
  }
856
- if(isUniqueChild || target === anchorEnd) {
857
- parent.append(element, target);
866
+ if(isParentUniqueChild(parent)) {
867
+ parent.append(element, anchorEnd);
858
868
  return;
859
869
  }
860
870
  parent.insertBefore(element, target);
861
871
  };
862
872
 
863
873
  element.appendElement = function(child, before = null) {
864
- if(isUniqueChild) {
874
+ if(isParentUniqueChild(anchorEnd.parentNode)) {
865
875
  (before && before !== anchorEnd)
866
876
  ? anchorEnd.parentNode.insertBefore(child, anchorEnd)
867
877
  : anchorEnd.parentNode.append(child, anchorEnd);
@@ -889,7 +899,7 @@ var NativeDocument = (function (exports) {
889
899
  if(parent === element) {
890
900
  return;
891
901
  }
892
- if(isUniqueChild || (parent.firstChild === anchorStart && parent.lastChild === anchorEnd)) {
902
+ if(isParentUniqueChild(parent)) {
893
903
  parent.replaceChildren(anchorStart, anchorEnd);
894
904
  return;
895
905
  }
@@ -908,7 +918,7 @@ var NativeDocument = (function (exports) {
908
918
  if(parent === element) {
909
919
  return;
910
920
  }
911
- if(isUniqueChild) {
921
+ if(isParentUniqueChild(parent)) {
912
922
  parent.replaceChildren(anchorEnd, anchorEnd);
913
923
  return;
914
924
  }
@@ -931,7 +941,7 @@ var NativeDocument = (function (exports) {
931
941
  if(!parent) {
932
942
  return;
933
943
  }
934
- if(isUniqueChild || (parent.firstChild === anchorStart && parent.lastChild === anchorEnd)) {
944
+ if(isParentUniqueChild(parent)) {
935
945
  parent.replaceChildren(anchorStart, child, anchorEnd);
936
946
  return;
937
947
  }
@@ -1543,7 +1553,9 @@ var NativeDocument = (function (exports) {
1543
1553
  if(!$node) {
1544
1554
  $node = $fn(this);
1545
1555
  }
1546
- return clone($node, data);
1556
+ const cloneNode = clone($node, data);
1557
+ PluginsManager.emit('NodeTemplateInstanceCreated', cloneNode);
1558
+ return cloneNode;
1547
1559
  };
1548
1560
 
1549
1561
  const createBinding = (hydrateFunction, target) => {
@@ -1585,10 +1597,12 @@ var NativeDocument = (function (exports) {
1585
1597
 
1586
1598
  function useCache(fn) {
1587
1599
  let $cache = null;
1600
+ PluginsManager.emit('NodeTemplateStored', fn);
1588
1601
 
1589
1602
  return function(...args) {
1590
1603
  if(!$cache) {
1591
1604
  $cache = new TemplateCloner(fn);
1605
+ PluginsManager.emit('NodeTemplateCreated', $cache);
1592
1606
  }
1593
1607
 
1594
1608
  return $cache.clone(args);