native-document 1.0.31 → 1.0.33

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.
@@ -264,14 +264,24 @@ var NativeDocument = (function (exports) {
264
264
  const $currentValue = this.$currentValue;
265
265
 
266
266
  if($watchers.has($currentValue)) {
267
- $watchers.get($currentValue).forEach(callback => {
268
- callback.set ? callback.set(true) : callback(true);
269
- });
267
+ const $currentValueCallbacks = $watchers.get($currentValue);
268
+ if(!Validator.isArray($currentValueCallbacks)) {
269
+ $currentValueCallbacks.set ? $currentValueCallbacks.set(true) : $currentValueCallbacks(true);
270
+ } else {
271
+ $currentValueCallbacks.forEach(callback => {
272
+ callback.set ? callback.set(true) : callback(true);
273
+ });
274
+ }
270
275
  }
271
276
  if($watchers.has($previousValue)) {
272
- $watchers.get($previousValue).forEach(callback => {
273
- callback.set ? callback.set(false) : callback(false);
274
- });
277
+ const $previousValueCallbacks = $watchers.get($previousValue);
278
+ if(typeof $previousValueCallbacks === "function") {
279
+ $previousValueCallbacks.set ? $previousValueCallbacks.set(false) : $previousValueCallbacks(false);
280
+ } else {
281
+ $previousValueCallbacks.forEach(callback => {
282
+ callback.set ? callback.set(false) : callback(false);
283
+ });
284
+ }
275
285
  }
276
286
  };
277
287
 
@@ -309,6 +319,7 @@ var NativeDocument = (function (exports) {
309
319
  this.$currentValue = newValue;
310
320
  PluginsManager.emit('ObservableBeforeChange', this);
311
321
  this.trigger();
322
+ this.$previousValue = null;
312
323
  PluginsManager.emit('ObservableAfterChange', this);
313
324
  };
314
325
 
@@ -322,7 +333,9 @@ var NativeDocument = (function (exports) {
322
333
  this.$currentValue = null;
323
334
  if(this.$watchers) {
324
335
  for (const [_, watchValueList] of this.$watchers) {
325
- watchValueList.splice(0);
336
+ if(Validator.isArray(watchValueList)) {
337
+ watchValueList.splice(0);
338
+ }
326
339
  }
327
340
  }
328
341
  this.$watchers?.clear();
@@ -368,17 +381,25 @@ var NativeDocument = (function (exports) {
368
381
  this.$watchers = this.$watchers ?? new Map();
369
382
 
370
383
  let watchValueList = this.$watchers.get(value);
384
+
371
385
  if(!watchValueList) {
372
- watchValueList = [];
386
+ this.$watchers.set(value, callback);
387
+ } else if(!Validator.isArray(watchValueList)) {
388
+ watchValueList = [watchValueList];
373
389
  this.$watchers.set(value, watchValueList);
390
+ return;
391
+ } else {
392
+ watchValueList.push(callback);
374
393
  }
375
394
 
376
- watchValueList.push(callback);
377
395
  this.assocTrigger();
378
396
  return () => {
379
397
  const index = watchValueList.indexOf(callback);
380
398
  watchValueList?.splice(index, 1);
381
- if(watchValueList.size === 0) {
399
+ if(watchValueList.size === 1) {
400
+ this.$watchers.set(value, watchValueList[0]);
401
+ }
402
+ else if(watchValueList.size === 0) {
382
403
  this.$watchers?.delete(value);
383
404
  watchValueList = null;
384
405
  }
@@ -691,6 +712,11 @@ var NativeDocument = (function (exports) {
691
712
 
692
713
  NDElement.prototype.node = NDElement.prototype.htmlElement;
693
714
 
715
+ NDElement.prototype.attach = function(methodName, bindingHydrator) {
716
+ bindingHydrator.$hydrate(this.$element, methodName);
717
+ return this.$element;
718
+ };
719
+
694
720
  const Validator = {
695
721
  isObservable(value) {
696
722
  return value instanceof ObservableItem || value instanceof ObservableChecker || value?.__$isObservable;
@@ -809,7 +835,7 @@ var NativeDocument = (function (exports) {
809
835
  }
810
836
  };
811
837
 
812
- function Anchor(name) {
838
+ function Anchor(name, isUniqueChild = false) {
813
839
  const element = document.createDocumentFragment();
814
840
 
815
841
  const anchorStart = document.createComment('Anchor Start : '+name);
@@ -822,14 +848,25 @@ var NativeDocument = (function (exports) {
822
848
  element.nativeAppendChild = element.appendChild;
823
849
 
824
850
  const insertBefore = function(parent, child, target) {
851
+ const element = Validator.isElement(child) ? child : ElementCreator.getChild(child);
825
852
  if(parent === element) {
826
- parent.nativeInsertBefore(ElementCreator.getChild(child), target);
853
+ parent.nativeInsertBefore(element, target);
827
854
  return;
828
855
  }
829
- parent.insertBefore(ElementCreator.getChild(child), target);
856
+ if(isUniqueChild || target === anchorEnd) {
857
+ parent.append(element, target);
858
+ return;
859
+ }
860
+ parent.insertBefore(element, target);
830
861
  };
831
862
 
832
863
  element.appendElement = function(child, before = null) {
864
+ if(isUniqueChild) {
865
+ (before && before !== anchorEnd)
866
+ ? anchorEnd.parentNode.insertBefore(child, anchorEnd)
867
+ : anchorEnd.parentNode.append(child, anchorEnd);
868
+ return;
869
+ }
833
870
  if(anchorEnd.parentNode === element) {
834
871
  anchorEnd.parentNode.nativeInsertBefore(child, before || anchorEnd);
835
872
  return;
@@ -844,14 +881,6 @@ var NativeDocument = (function (exports) {
844
881
  return;
845
882
  }
846
883
  before = before ?? anchorEnd;
847
- if(Validator.isArray(child)) {
848
- const fragment = document.createDocumentFragment();
849
- for(let i = 0, length = child.length; i < length; i++) {
850
- fragment.appendChild(ElementCreator.getChild(child[i]));
851
- }
852
- insertBefore(parent, fragment, before);
853
- return element;
854
- }
855
884
  insertBefore(parent, child, before);
856
885
  };
857
886
 
@@ -860,7 +889,7 @@ var NativeDocument = (function (exports) {
860
889
  if(parent === element) {
861
890
  return;
862
891
  }
863
- if(parent.firstChild === anchorStart && parent.lastChild === anchorEnd) {
892
+ if(isUniqueChild || (parent.firstChild === anchorStart && parent.lastChild === anchorEnd)) {
864
893
  parent.replaceChildren(anchorStart, anchorEnd);
865
894
  return;
866
895
  }
@@ -879,6 +908,10 @@ var NativeDocument = (function (exports) {
879
908
  if(parent === element) {
880
909
  return;
881
910
  }
911
+ if(isUniqueChild) {
912
+ parent.replaceChildren(anchorEnd, anchorEnd);
913
+ return;
914
+ }
882
915
  let itemToRemove = anchorStart.nextSibling, tempItem;
883
916
  while(itemToRemove !== anchorEnd) {
884
917
  tempItem = itemToRemove.nextSibling;
@@ -898,7 +931,7 @@ var NativeDocument = (function (exports) {
898
931
  if(!parent) {
899
932
  return;
900
933
  }
901
- if(parent.firstChild === anchorStart && parent.lastChild === anchorEnd) {
934
+ if(isUniqueChild || (parent.firstChild === anchorStart && parent.lastChild === anchorEnd)) {
902
935
  parent.replaceChildren(anchorStart, child, anchorEnd);
903
936
  return;
904
937
  }
@@ -995,6 +1028,10 @@ var NativeDocument = (function (exports) {
995
1028
  });
996
1029
  continue;
997
1030
  }
1031
+ if(value.$hydrate) {
1032
+ value.$hydrate(element, className);
1033
+ continue;
1034
+ }
998
1035
  element.classList.toggle(className, value);
999
1036
  }
1000
1037
  }
@@ -1142,11 +1179,22 @@ var NativeDocument = (function (exports) {
1142
1179
  */
1143
1180
  createObservableNode(parent, observable) {
1144
1181
  const text = ElementCreator.createTextNode();
1145
- observable.subscribe(value => text.nodeValue = String(value));
1182
+ observable.subscribe(value => text.nodeValue = value);
1146
1183
  text.nodeValue = observable.val();
1147
1184
  parent && parent.appendChild(text);
1148
1185
  return text;
1149
1186
  },
1187
+ /**
1188
+ *
1189
+ * @param {HTMLElement|DocumentFragment} parent
1190
+ * @param {{$hydrate: Function}} item
1191
+ * @returns {Text}
1192
+ */
1193
+ createHydratableNode(parent, item) {
1194
+ const text = ElementCreator.createTextNode();
1195
+ item.$hydrate(text);
1196
+ return text;
1197
+ },
1150
1198
 
1151
1199
  /**
1152
1200
  *
@@ -1156,7 +1204,7 @@ var NativeDocument = (function (exports) {
1156
1204
  */
1157
1205
  createStaticTextNode(parent, value) {
1158
1206
  let text = ElementCreator.createTextNode();
1159
- text.nodeValue = String(value);
1207
+ text.nodeValue = value;
1160
1208
  parent && parent.appendChild(text);
1161
1209
  return text;
1162
1210
  },
@@ -1225,6 +1273,9 @@ var NativeDocument = (function (exports) {
1225
1273
  PluginsManager.emit('BeforeProcessComponent', child);
1226
1274
  return this.getChild(child());
1227
1275
  }
1276
+ if(child?.$hydrate) {
1277
+ return ElementCreator.createHydratableNode(null, child);
1278
+ }
1228
1279
  return ElementCreator.createStaticTextNode(null, child);
1229
1280
  },
1230
1281
  /**
@@ -1270,6 +1321,9 @@ var NativeDocument = (function (exports) {
1270
1321
  }
1271
1322
  }
1272
1323
 
1324
+ exports.withValidation = (fn) => fn;
1325
+ exports.ArgTypes = {};
1326
+
1273
1327
  /**
1274
1328
  *
1275
1329
  * @type {{string: (function(*): {name: *, type: string, validate: function(*): boolean}),
@@ -1287,88 +1341,93 @@ var NativeDocument = (function (exports) {
1287
1341
  * validate: function(*): boolean})
1288
1342
  * }}
1289
1343
  */
1290
- const ArgTypes = {
1291
- string: (name) => ({ name, type: 'string', validate: (v) => Validator.isString(v) }),
1292
- number: (name) => ({ name, type: 'number', validate: (v) => Validator.isNumber(v) }),
1293
- boolean: (name) => ({ name, type: 'boolean', validate: (v) => Validator.isBoolean(v) }),
1294
- observable: (name) => ({ name, type: 'observable', validate: (v) => Validator.isObservable(v) }),
1295
- element: (name) => ({ name, type: 'element', validate: (v) => Validator.isElement(v) }),
1296
- function: (name) => ({ name, type: 'function', validate: (v) => Validator.isFunction(v) }),
1297
- object: (name) => ({ name, type: 'object', validate: (v) => (Validator.isObject(v)) }),
1298
- objectNotNull: (name) => ({ name, type: 'object', validate: (v) => (Validator.isObject(v) && v !== null) }),
1299
- children: (name) => ({ name, type: 'children', validate: (v) => Validator.validateChildren(v) }),
1300
- attributes: (name) => ({ name, type: 'attributes', validate: (v) => Validator.validateAttributes(v) }),
1301
-
1302
- // Optional arguments
1303
- optional: (argType) => ({ ...argType, optional: true }),
1304
-
1305
- // Union types
1306
- oneOf: (name, ...argTypes) => ({
1307
- name,
1308
- type: 'oneOf',
1309
- types: argTypes,
1310
- validate: (v) => argTypes.some(type => type.validate(v))
1311
- })
1312
- };
1344
+ {
1345
+ exports.ArgTypes = {
1346
+ string: (name) => ({ name, type: 'string', validate: (v) => Validator.isString(v) }),
1347
+ number: (name) => ({ name, type: 'number', validate: (v) => Validator.isNumber(v) }),
1348
+ boolean: (name) => ({ name, type: 'boolean', validate: (v) => Validator.isBoolean(v) }),
1349
+ observable: (name) => ({ name, type: 'observable', validate: (v) => Validator.isObservable(v) }),
1350
+ element: (name) => ({ name, type: 'element', validate: (v) => Validator.isElement(v) }),
1351
+ function: (name) => ({ name, type: 'function', validate: (v) => Validator.isFunction(v) }),
1352
+ object: (name) => ({ name, type: 'object', validate: (v) => (Validator.isObject(v)) }),
1353
+ objectNotNull: (name) => ({ name, type: 'object', validate: (v) => (Validator.isObject(v) && v !== null) }),
1354
+ children: (name) => ({ name, type: 'children', validate: (v) => Validator.validateChildren(v) }),
1355
+ attributes: (name) => ({ name, type: 'attributes', validate: (v) => Validator.validateAttributes(v) }),
1356
+
1357
+ // Optional arguments
1358
+ optional: (argType) => ({ ...argType, optional: true }),
1359
+
1360
+ // Union types
1361
+ oneOf: (name, ...argTypes) => ({
1362
+ name,
1363
+ type: 'oneOf',
1364
+ types: argTypes,
1365
+ validate: (v) => argTypes.some(type => type.validate(v))
1366
+ })
1367
+ };
1313
1368
 
1314
- /**
1315
- *
1316
- * @param {Array} args
1317
- * @param {Array} argSchema
1318
- * @param {string} fnName
1319
- */
1320
- const validateArgs = (args, argSchema, fnName = 'Function') => {
1321
- if (!argSchema) return;
1322
1369
 
1323
- const errors = [];
1370
+ /**
1371
+ *
1372
+ * @param {Array} args
1373
+ * @param {Array} argSchema
1374
+ * @param {string} fnName
1375
+ */
1376
+ const validateArgs = (args, argSchema, fnName = 'Function') => {
1377
+ if (!argSchema) return;
1378
+
1379
+ const errors = [];
1324
1380
 
1325
- // Check the number of arguments
1326
- const requiredCount = argSchema.filter(arg => !arg.optional).length;
1327
- if (args.length < requiredCount) {
1328
- errors.push(`${fnName}: Expected at least ${requiredCount} arguments, got ${args.length}`);
1329
- }
1381
+ // Check the number of arguments
1382
+ const requiredCount = argSchema.filter(arg => !arg.optional).length;
1383
+ if (args.length < requiredCount) {
1384
+ errors.push(`${fnName}: Expected at least ${requiredCount} arguments, got ${args.length}`);
1385
+ }
1330
1386
 
1331
- // Validate each argument
1332
- argSchema.forEach((schema, index) => {
1333
- const position = index + 1;
1334
- const value = args[index];
1387
+ // Validate each argument
1388
+ argSchema.forEach((schema, index) => {
1389
+ const position = index + 1;
1390
+ const value = args[index];
1391
+
1392
+ if (value === undefined) {
1393
+ if (!schema.optional) {
1394
+ errors.push(`${fnName}: Missing required argument '${schema.name}' at position ${position}`);
1395
+ }
1396
+ return;
1397
+ }
1335
1398
 
1336
- if (value === undefined) {
1337
- if (!schema.optional) {
1338
- errors.push(`${fnName}: Missing required argument '${schema.name}' at position ${position}`);
1399
+ if (!schema.validate(value)) {
1400
+ const valueTypeOf = value?.constructor?.name || typeof value;
1401
+ errors.push(`${fnName}: Invalid argument '${schema.name}' at position ${position}, expected ${schema.type}, got ${valueTypeOf}`);
1339
1402
  }
1340
- return;
1341
- }
1403
+ });
1342
1404
 
1343
- if (!schema.validate(value)) {
1344
- const valueTypeOf = value?.constructor?.name || typeof value;
1345
- errors.push(`${fnName}: Invalid argument '${schema.name}' at position ${position}, expected ${schema.type}, got ${valueTypeOf}`);
1405
+ if (errors.length > 0) {
1406
+ throw new ArgTypesError(`Argument validation failed`, errors);
1346
1407
  }
1347
- });
1408
+ };
1348
1409
 
1349
- if (errors.length > 0) {
1350
- throw new ArgTypesError(`Argument validation failed`, errors);
1351
- }
1352
- };
1353
1410
 
1354
- /**
1355
- * @param {Function} fn
1356
- * @param {Array} argSchema
1357
- * @param {string} fnName
1358
- * @returns {Function}
1359
- */
1360
- const withValidation = (fn, argSchema, fnName = 'Function') => {
1361
- if(!Validator.isArray(argSchema)) {
1362
- throw new NativeDocumentError('withValidation : argSchema must be an array');
1363
- }
1364
- return function(...args) {
1365
- validateArgs(args, argSchema, fn.name || fnName);
1366
- return fn.apply(this, args);
1411
+
1412
+ /**
1413
+ * @param {Function} fn
1414
+ * @param {Array} argSchema
1415
+ * @param {string} fnName
1416
+ * @returns {Function}
1417
+ */
1418
+ exports.withValidation = (fn, argSchema, fnName = 'Function') => {
1419
+ if(!Validator.isArray(argSchema)) {
1420
+ throw new NativeDocumentError('withValidation : argSchema must be an array');
1421
+ }
1422
+ return function(...args) {
1423
+ validateArgs(args, argSchema, fn.name || fnName);
1424
+ return fn.apply(this, args);
1425
+ };
1367
1426
  };
1368
- };
1427
+ }
1369
1428
 
1370
1429
  const normalizeComponentArgs = function(props, children = null) {
1371
- if(!Validator.isJson(props)) {
1430
+ if(!Validator.isJson(props) || props?.$hydrate) {
1372
1431
  const temp = children;
1373
1432
  children = props;
1374
1433
  props = temp;
@@ -1376,6 +1435,29 @@ var NativeDocument = (function (exports) {
1376
1435
  return { props, children };
1377
1436
  };
1378
1437
 
1438
+ /**
1439
+ *
1440
+ * @param {*} value
1441
+ * @returns {Text}
1442
+ */
1443
+ const createTextNode = function(value) {
1444
+ return (Validator.isObservable(value))
1445
+ ? ElementCreator.createObservableNode(null, value)
1446
+ : ElementCreator.createStaticTextNode(null, value);
1447
+ };
1448
+
1449
+
1450
+ function createHtmlElement($tagName, _attributes, _children = null, customWrapper) {
1451
+ const { props: attributes, children = null } = normalizeComponentArgs(_attributes, _children);
1452
+ const element = ElementCreator.createElement($tagName);
1453
+ const finalElement = (typeof customWrapper === 'function') ? customWrapper(element) : element;
1454
+
1455
+ ElementCreator.processAttributes(finalElement, attributes);
1456
+ ElementCreator.processChildren(children, finalElement);
1457
+
1458
+ return ElementCreator.setup(finalElement, attributes, customWrapper);
1459
+ }
1460
+
1379
1461
  /**
1380
1462
  *
1381
1463
  * @param {string} name
@@ -1383,26 +1465,154 @@ var NativeDocument = (function (exports) {
1383
1465
  * @returns {Function}
1384
1466
  */
1385
1467
  function HtmlElementWrapper(name, customWrapper) {
1386
- const $tagName = name.toLowerCase();
1468
+ return (_attributes, _children = null) => createHtmlElement(name.toLowerCase(), _attributes, _children, customWrapper);
1469
+ }
1387
1470
 
1388
- return function(_attributes, _children = null) {
1389
- try {
1390
- const { props: attributes, children = null } = normalizeComponentArgs(_attributes, _children);
1391
- const element = ElementCreator.createElement($tagName);
1392
- const finalElement = (typeof customWrapper === 'function') ? customWrapper(element) : element;
1471
+ const cloneBindingsDataCache = new WeakMap();
1472
+
1473
+
1474
+ const bindAttributes = (node, bindDingData, data) => {
1475
+ if(!bindDingData) {
1476
+ return null;
1477
+ }
1478
+ const attributes = { };
1479
+ if(bindDingData.attributes) {
1480
+ for (const attr in bindDingData.attributes) {
1481
+ attributes[attr] = bindDingData.attributes[attr](...data);
1482
+ }
1483
+ }
1484
+
1485
+ if(bindDingData.classes) {
1486
+ attributes.class = {};
1487
+ for (const className in bindDingData.classes) {
1488
+ attributes.class[className] = bindDingData.classes[className](...data);
1489
+ }
1490
+ }
1491
+
1492
+ if(bindDingData.styles) {
1493
+ attributes.style = {};
1494
+ for (const property in bindDingData.styles) {
1495
+ attributes.style[property] = bindDingData.styles[property](...data);
1496
+ }
1497
+ }
1498
+
1499
+ if(Object.keys(attributes)) {
1500
+ ElementCreator.processAttributes(node, attributes);
1501
+ return attributes;
1502
+ }
1503
+
1504
+ return null;
1505
+ };
1506
+
1507
+
1508
+ const bindAttachesMethods = function(node, bindDingData, data) {
1509
+ if(!bindDingData?.attaches) {
1510
+ return null;
1511
+ }
1512
+ for(const methodName in bindDingData.attaches) {
1513
+ node.nd[methodName](function(...args) {
1514
+ bindDingData.attaches[methodName].call(this, ...[...args, ...data]);
1515
+ });
1516
+ }
1517
+ };
1518
+
1519
+ function TemplateCloner($fn) {
1520
+ let $node = null;
1521
+
1522
+ const clone = (node, data) => {
1523
+ const bindDingData = cloneBindingsDataCache.get(node);
1524
+ if(node instanceof Text) {
1525
+ if(bindDingData?.value) {
1526
+ return bindDingData.value(data);
1527
+ }
1528
+ return node.cloneNode(true);
1529
+ }
1530
+ const nodeCloned = node.cloneNode();
1531
+ bindAttributes(nodeCloned, bindDingData, data);
1532
+ bindAttachesMethods(nodeCloned, bindDingData, data);
1533
+
1534
+ for(let i = 0, length = node.childNodes.length; i < length; i++) {
1535
+ const childNode = node.childNodes[i];
1536
+ const childNodeCloned = clone(childNode, data);
1537
+ nodeCloned.appendChild(childNodeCloned);
1538
+ }
1539
+ return nodeCloned;
1540
+ };
1393
1541
 
1394
- ElementCreator.processAttributes(finalElement, attributes);
1395
- ElementCreator.processChildren(children, finalElement);
1542
+ this.clone = (data) => {
1543
+ if(!$node) {
1544
+ $node = $fn(this);
1545
+ }
1546
+ return clone($node, data);
1547
+ };
1548
+
1549
+ const createBinding = (hydrateFunction, target) => {
1550
+ return {
1551
+ $hydrate : function(element, property) {
1552
+ if(!cloneBindingsDataCache.has(element)) {
1553
+ // { classes, styles, attributes, value, attaches }
1554
+ cloneBindingsDataCache.set(element, {});
1555
+ }
1556
+ const hydrationState = cloneBindingsDataCache.get(element);
1557
+ if(target === 'value') {
1558
+ hydrationState.value = hydrateFunction;
1559
+ return;
1560
+ }
1561
+ hydrationState[target] = hydrationState[target] || {};
1562
+ hydrationState[target][property] = hydrateFunction;
1563
+ }
1564
+ }
1565
+ };
1396
1566
 
1397
- return ElementCreator.setup(finalElement, attributes, customWrapper);
1398
- } catch (error) {
1399
- DebugManager$1.error('ElementCreation', `Error creating ${$tagName}`, error);
1567
+ this.style = (fn) => {
1568
+ return createBinding(fn, 'styles');
1569
+ };
1570
+ this.class = (fn) => {
1571
+ return createBinding(fn, 'classes');
1572
+ };
1573
+ this.value = (fn) => {
1574
+ return createBinding(function(data) {
1575
+ return createTextNode(fn(...data));
1576
+ }, 'value');
1577
+ };
1578
+ this.attr = (fn) => {
1579
+ return createBinding(fn, 'attributes');
1580
+ };
1581
+ this.attach = (fn) => {
1582
+ return createBinding(fn, 'attaches');
1583
+ };
1584
+ }
1585
+
1586
+ function useCache(fn) {
1587
+ let $cache = null;
1588
+
1589
+ return function(...args) {
1590
+ if(!$cache) {
1591
+ $cache = new TemplateCloner(fn);
1400
1592
  }
1593
+
1594
+ return $cache.clone(args);
1401
1595
  };
1402
1596
  }
1403
1597
 
1404
1598
  Function.prototype.args = function(...args) {
1405
- return withValidation(this, args);
1599
+ return exports.withValidation(this, args);
1600
+ };
1601
+
1602
+ Function.prototype.cached = function(...args) {
1603
+ let $cache = null;
1604
+ let getCache = function(){ return $cache; };
1605
+ return () => {
1606
+ if(!$cache) {
1607
+ $cache = this.apply(this, args);
1608
+ if($cache.cloneNode) {
1609
+ getCache = function() { return $cache.cloneNode(true); };
1610
+ } else if($cache.$element) {
1611
+ getCache = function() { return new NDElement($cache.$element.cloneNode(true)); };
1612
+ }
1613
+ }
1614
+ return getCache();
1615
+ };
1406
1616
  };
1407
1617
 
1408
1618
  Function.prototype.errorBoundary = function(callback) {
@@ -1514,7 +1724,8 @@ var NativeDocument = (function (exports) {
1514
1724
  };
1515
1725
 
1516
1726
  observer.merge = function(values) {
1517
- observer.set([...observer.val(), ...values]);
1727
+ observer.$value.push(...values);
1728
+ observer.trigger({ action: 'merge', args: values });
1518
1729
  };
1519
1730
 
1520
1731
  observer.populateAndRender = function(iteration, callback) {
@@ -2009,20 +2220,15 @@ var NativeDocument = (function (exports) {
2009
2220
  cache.delete(keyId);
2010
2221
  }
2011
2222
 
2012
- try {
2013
- const indexObserver = isIndexRequired ? Observable(indexKey) : null;
2014
- let child = ElementCreator.getChild(callback(item, indexObserver));
2015
- cache.set(keyId, {
2016
- keyId,
2017
- child: child,
2018
- indexObserver: (indexObserver ? new WeakRef(indexObserver) : null)
2019
- });
2020
- keysCache.set(item, keyId);
2021
- return child;
2022
- } catch (e) {
2023
- DebugManager$1.error('ForEach', `Error creating element for key ${keyId}` , e);
2024
- throw e;
2025
- }
2223
+ const indexObserver = isIndexRequired ? Observable(indexKey) : null;
2224
+ let child = ElementCreator.getChild(callback(item, indexObserver));
2225
+ cache.set(keyId, {
2226
+ keyId,
2227
+ child: child,
2228
+ indexObserver: (indexObserver ? new WeakRef(indexObserver) : null)
2229
+ });
2230
+ keysCache.set(item, keyId);
2231
+ return child;
2026
2232
  };
2027
2233
  const getChildByKey = function(keyId) {
2028
2234
  const cacheItem = cache.get(keyId);
@@ -2086,11 +2292,7 @@ var NativeDocument = (function (exports) {
2086
2292
  element.appendElement(fragment, blockEnd);
2087
2293
  },
2088
2294
  removeOne(element, index) {
2089
- let child = getItemChild(element);
2090
- if(child) {
2091
- removeCacheItemByKey(getItemKey(element, index), true);
2092
- }
2093
- child = null;
2295
+ removeCacheItemByKey(getItemKey(element, index), true);
2094
2296
  },
2095
2297
  clear,
2096
2298
  merge(items) {
@@ -3376,18 +3578,19 @@ var NativeDocument = (function (exports) {
3376
3578
  Router: Router
3377
3579
  });
3378
3580
 
3379
- exports.ArgTypes = ArgTypes;
3380
3581
  exports.ElementCreator = ElementCreator;
3381
3582
  exports.HtmlElementWrapper = HtmlElementWrapper;
3382
3583
  exports.NDElement = NDElement;
3383
3584
  exports.Observable = Observable;
3384
3585
  exports.Store = Store;
3586
+ exports.TemplateCloner = TemplateCloner;
3385
3587
  exports.classPropertyAccumulator = classPropertyAccumulator;
3588
+ exports.createTextNode = createTextNode;
3386
3589
  exports.cssPropertyAccumulator = cssPropertyAccumulator;
3387
3590
  exports.elements = elements;
3388
3591
  exports.normalizeComponentArgs = normalizeComponentArgs;
3389
3592
  exports.router = router;
3390
- exports.withValidation = withValidation;
3593
+ exports.useCache = useCache;
3391
3594
 
3392
3595
  return exports;
3393
3596