native-document 1.0.122 → 1.0.123

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.
@@ -363,16 +363,16 @@ var NativeComponents = (function (exports) {
363
363
  // });
364
364
  };
365
365
 
366
- let DebugManager$2 = {};
366
+ let DebugManager$1 = {};
367
367
  {
368
- DebugManager$2 = {
368
+ DebugManager$1 = {
369
369
  log() {},
370
370
  warn() {},
371
371
  error() {},
372
372
  disable() {}
373
373
  };
374
374
  }
375
- var DebugManager$1 = DebugManager$2;
375
+ var DebugManager$2 = DebugManager$1;
376
376
 
377
377
  /**
378
378
  *
@@ -386,6 +386,7 @@ var NativeComponents = (function (exports) {
386
386
  this.unSubscriptions = [];
387
387
  }
388
388
 
389
+ ObservableChecker.prototype.__$Observable = true;
389
390
  ObservableChecker.prototype.__$isObservableChecker = true;
390
391
 
391
392
  /**
@@ -846,17 +847,17 @@ var NativeComponents = (function (exports) {
846
847
  const method = methods[name];
847
848
 
848
849
  if (typeof method !== 'function') {
849
- DebugManager$1.warn('NDElement.extend', `"${name}" is not a function, skipping`);
850
+ DebugManager$2.warn('NDElement.extend', `"${name}" is not a function, skipping`);
850
851
  continue;
851
852
  }
852
853
 
853
854
  if (protectedMethods.has(name)) {
854
- DebugManager$1.error('NDElement.extend', `Cannot override protected method "${name}"`);
855
+ DebugManager$2.error('NDElement.extend', `Cannot override protected method "${name}"`);
855
856
  throw new NativeDocumentError(`Cannot override protected method "${name}"`);
856
857
  }
857
858
 
858
859
  if (NDElement.prototype[name]) {
859
- DebugManager$1.warn('NDElement.extend', `Overwriting existing prototype method "${name}"`);
860
+ DebugManager$2.warn('NDElement.extend', `Overwriting existing prototype method "${name}"`);
860
861
  }
861
862
 
862
863
  NDElement.prototype[name] = method;
@@ -1081,7 +1082,7 @@ var NativeComponents = (function (exports) {
1081
1082
  }
1082
1083
  }
1083
1084
  if (cleanedCount > 0) {
1084
- DebugManager$1.log('Memory Auto Clean', `🧹 Cleaned ${cleanedCount} orphaned observables`);
1085
+ DebugManager$2.log('Memory Auto Clean', `🧹 Cleaned ${cleanedCount} orphaned observables`);
1085
1086
  }
1086
1087
  }
1087
1088
  };
@@ -1099,6 +1100,7 @@ var NativeComponents = (function (exports) {
1099
1100
  this.$observer = observer;
1100
1101
  };
1101
1102
 
1103
+ ObservableWhen.prototype.__$Observable = true;
1102
1104
  ObservableWhen.prototype.__$isObservableWhen = true;
1103
1105
 
1104
1106
  /**
@@ -1404,6 +1406,7 @@ var NativeComponents = (function (exports) {
1404
1406
  configurable: true,
1405
1407
  });
1406
1408
 
1409
+ ObservableItem.prototype.__$Observable = true;
1407
1410
  ObservableItem.prototype.__$isObservable = true;
1408
1411
  const noneTrigger = function() {};
1409
1412
 
@@ -1969,7 +1972,17 @@ var NativeComponents = (function (exports) {
1969
1972
  */
1970
1973
  const bindClassAttribute = (element, data) => {
1971
1974
  for(const className in data) {
1972
- data[className].bindClassProperty(element, className);
1975
+ const value = data[className];
1976
+ if(value.__$Observable) {
1977
+ element.classes.toggle(className, value.val());
1978
+ value.subscribe((shouldAdd) => element.classes.toggle(className, shouldAdd));
1979
+ continue;
1980
+ }
1981
+ if(value.$hydrate) {
1982
+ value.$hydrate(element, className);
1983
+ continue;
1984
+ }
1985
+ element.classes.toggle(className, value);
1973
1986
  }
1974
1987
  };
1975
1988
 
@@ -2228,20 +2241,6 @@ var NativeComponents = (function (exports) {
2228
2241
  bindAttributeWithObservable(element, attributeName, this);
2229
2242
  };
2230
2243
 
2231
- ObservableItem.prototype.bindClassProperty = function(element, className) {
2232
- element.classes.toggle(className, this.val());
2233
- this.subscribe((shouldAdd) => element.classes.toggle(className, shouldAdd));
2234
- };
2235
-
2236
- ObservableWhen.prototype.bindClassProperty = function(element, className) {
2237
- element.classes.toggle(className, this.isActive());
2238
- this.subscribe((shouldAdd) => element.classes.toggle(className, shouldAdd));
2239
- };
2240
-
2241
- Boolean.prototype.bindClassProperty = function(element, className) {
2242
- element.classes.toggle(className, this);
2243
- };
2244
-
2245
2244
  let $textNodeCache = null;
2246
2245
 
2247
2246
  const ElementCreator = {
@@ -3073,22 +3072,19 @@ var NativeComponents = (function (exports) {
3073
3072
  }
3074
3073
  }
3075
3074
  if(this.$classes) {
3075
+ const cache = {};
3076
3076
  const keys = Object.keys(this.$classes);
3077
3077
 
3078
3078
  if(keys.length === 1) {
3079
3079
  const key = keys[0];
3080
3080
  const callback = this.$classes[key];
3081
3081
  steps.push((clonedNode, data) => {
3082
- callback.apply(null, data).bindClassProperty(clonedNode, key);
3082
+ cache[key] = callback.apply(null, data);
3083
+ ElementCreator.processClassAttribute(clonedNode, cache);
3083
3084
  });
3084
3085
  } else {
3085
- const properties = this.$classes;
3086
- const keysLength = keys.length;
3087
3086
  steps.push((clonedNode, data) => {
3088
- for(let i = 0; i < keysLength; i++) {
3089
- const key = keys[i];
3090
- properties[key].apply(null, data).bindClassProperty(clonedNode, key);
3091
- }
3087
+ ElementCreator.processClassAttribute(clonedNode, buildProperties(cache, this.$classes, data));
3092
3088
  });
3093
3089
  }
3094
3090
  }
@@ -3952,7 +3948,7 @@ var NativeComponents = (function (exports) {
3952
3948
  const $getStoreOrThrow = (method, name) => {
3953
3949
  const item = $stores.get(name);
3954
3950
  if (!item) {
3955
- DebugManager$1.error('Store', `Store.${method}('${name}') : store not found. Did you call Store.create('${name}') first?`);
3951
+ DebugManager$2.error('Store', `Store.${method}('${name}') : store not found. Did you call Store.create('${name}') first?`);
3956
3952
  throw new NativeDocumentError(
3957
3953
  `Store.${method}('${name}') : store not found.`
3958
3954
  );
@@ -3965,7 +3961,7 @@ var NativeComponents = (function (exports) {
3965
3961
  */
3966
3962
  const $applyReadOnly = (observer, name, context) => {
3967
3963
  const readOnlyError = (method) => () => {
3968
- DebugManager$1.error('Store', `Store.${context}('${name}') is read-only. '${method}()' is not allowed.`);
3964
+ DebugManager$2.error('Store', `Store.${context}('${name}') is read-only. '${method}()' is not allowed.`);
3969
3965
  throw new NativeDocumentError(
3970
3966
  `Store.${context}('${name}') is read-only.`
3971
3967
  );
@@ -3996,7 +3992,7 @@ var NativeComponents = (function (exports) {
3996
3992
  */
3997
3993
  create(name, value) {
3998
3994
  if ($stores.has(name)) {
3999
- DebugManager$1.warn('Store', `Store.create('${name}') : a store with this name already exists. Use Store.get('${name}') to retrieve it.`);
3995
+ DebugManager$2.warn('Store', `Store.create('${name}') : a store with this name already exists. Use Store.get('${name}') to retrieve it.`);
4000
3996
  throw new NativeDocumentError(
4001
3997
  `Store.create('${name}') : a store with this name already exists.`
4002
3998
  );
@@ -4017,7 +4013,7 @@ var NativeComponents = (function (exports) {
4017
4013
  */
4018
4014
  createResettable(name, value) {
4019
4015
  if ($stores.has(name)) {
4020
- DebugManager$1.warn('Store', `Store.createResettable('${name}') : a store with this name already exists.`);
4016
+ DebugManager$2.warn('Store', `Store.createResettable('${name}') : a store with this name already exists.`);
4021
4017
  throw new NativeDocumentError(
4022
4018
  `Store.createResettable('${name}') : a store with this name already exists.`
4023
4019
  );
@@ -4053,7 +4049,7 @@ var NativeComponents = (function (exports) {
4053
4049
  */
4054
4050
  createComposed(name, computation, dependencies) {
4055
4051
  if ($stores.has(name)) {
4056
- DebugManager$1.warn('Store', `Store.createComposed('${name}') : a store with this name already exists.`);
4052
+ DebugManager$2.warn('Store', `Store.createComposed('${name}') : a store with this name already exists.`);
4057
4053
  throw new NativeDocumentError(
4058
4054
  `Store.createComposed('${name}') : a store with this name already exists.`
4059
4055
  );
@@ -4076,7 +4072,7 @@ var NativeComponents = (function (exports) {
4076
4072
  }
4077
4073
  const depItem = $stores.get(depName);
4078
4074
  if (!depItem) {
4079
- DebugManager$1.error('Store', `Store.createComposed('${name}') : dependency '${depName}' not found. Create it first.`);
4075
+ DebugManager$2.error('Store', `Store.createComposed('${name}') : dependency '${depName}' not found. Create it first.`);
4080
4076
  throw new NativeDocumentError(
4081
4077
  `Store.createComposed('${name}') : dependency store '${depName}' not found.`
4082
4078
  );
@@ -4110,13 +4106,13 @@ var NativeComponents = (function (exports) {
4110
4106
  reset(name) {
4111
4107
  const item = $getStoreOrThrow('reset', name);
4112
4108
  if (item.composed) {
4113
- DebugManager$1.error('Store', `Store.reset('${name}') : composed stores cannot be reset. Their value is derived from dependencies.`);
4109
+ DebugManager$2.error('Store', `Store.reset('${name}') : composed stores cannot be reset. Their value is derived from dependencies.`);
4114
4110
  throw new NativeDocumentError(
4115
4111
  `Store.reset('${name}') : composed stores cannot be reset.`
4116
4112
  );
4117
4113
  }
4118
4114
  if (!item.resettable) {
4119
- DebugManager$1.error('Store', `Store.reset('${name}') : this store is not resettable. Use Store.createResettable('${name}', value) instead of Store.create().`);
4115
+ DebugManager$2.error('Store', `Store.reset('${name}') : this store is not resettable. Use Store.createResettable('${name}', value) instead of Store.create().`);
4120
4116
  throw new NativeDocumentError(
4121
4117
  `Store.reset('${name}') : this store is not resettable. Use Store.createResettable('${name}', value) instead of Store.create().`
4122
4118
  );
@@ -4137,7 +4133,7 @@ var NativeComponents = (function (exports) {
4137
4133
  const item = $getStoreOrThrow('use', name);
4138
4134
 
4139
4135
  if (item.composed) {
4140
- DebugManager$1.error('Store', `Store.use('${name}') : composed stores are read-only. Use Store.follow('${name}') instead.`);
4136
+ DebugManager$2.error('Store', `Store.use('${name}') : composed stores are read-only. Use Store.follow('${name}') instead.`);
4141
4137
  throw new NativeDocumentError(
4142
4138
  `Store.use('${name}') : composed stores are read-only. Use Store.follow('${name}') instead.`
4143
4139
  );
@@ -4204,7 +4200,7 @@ var NativeComponents = (function (exports) {
4204
4200
  get(name) {
4205
4201
  const item = $stores.get(name);
4206
4202
  if (!item) {
4207
- DebugManager$1.warn('Store', `Store.get('${name}') : store not found.`);
4203
+ DebugManager$2.warn('Store', `Store.get('${name}') : store not found.`);
4208
4204
  return null;
4209
4205
  }
4210
4206
  return item.observer;
@@ -4226,7 +4222,7 @@ var NativeComponents = (function (exports) {
4226
4222
  delete(name) {
4227
4223
  const item = $stores.get(name);
4228
4224
  if (!item) {
4229
- DebugManager$1.warn('Store', `Store.delete('${name}') : store not found, nothing to delete.`);
4225
+ DebugManager$2.warn('Store', `Store.delete('${name}') : store not found, nothing to delete.`);
4230
4226
  return;
4231
4227
  }
4232
4228
  item.subscribers.forEach(follower => follower.destroy());
@@ -4328,7 +4324,7 @@ var NativeComponents = (function (exports) {
4328
4324
  return undefined;
4329
4325
  },
4330
4326
  set(target, prop, value) {
4331
- DebugManager$1.error('Store', `Forbidden: You cannot overwrite the store key '${String(prop)}'. Use .use('${String(prop)}').set(value) instead.`);
4327
+ DebugManager$2.error('Store', `Forbidden: You cannot overwrite the store key '${String(prop)}'. Use .use('${String(prop)}').set(value) instead.`);
4332
4328
  throw new NativeDocumentError(`Store structure is immutable. Use .set() on the observable.`);
4333
4329
  },
4334
4330
  deleteProperty(target, prop) {
@@ -58,6 +58,7 @@ var NativeDocument = (function (exports) {
58
58
  this.unSubscriptions = [];
59
59
  }
60
60
 
61
+ ObservableChecker.prototype.__$Observable = true;
61
62
  ObservableChecker.prototype.__$isObservableChecker = true;
62
63
 
63
64
  /**
@@ -884,6 +885,7 @@ var NativeDocument = (function (exports) {
884
885
  this.$observer = observer;
885
886
  };
886
887
 
888
+ ObservableWhen.prototype.__$Observable = true;
887
889
  ObservableWhen.prototype.__$isObservableWhen = true;
888
890
 
889
891
  /**
@@ -1190,6 +1192,7 @@ var NativeDocument = (function (exports) {
1190
1192
  configurable: true,
1191
1193
  });
1192
1194
 
1195
+ ObservableItem.prototype.__$Observable = true;
1193
1196
  ObservableItem.prototype.__$isObservable = true;
1194
1197
  const noneTrigger = function() {};
1195
1198
 
@@ -1788,7 +1791,17 @@ var NativeDocument = (function (exports) {
1788
1791
  */
1789
1792
  const bindClassAttribute = (element, data) => {
1790
1793
  for(const className in data) {
1791
- data[className].bindClassProperty(element, className);
1794
+ const value = data[className];
1795
+ if(value.__$Observable) {
1796
+ element.classes.toggle(className, value.val());
1797
+ value.subscribe((shouldAdd) => element.classes.toggle(className, shouldAdd));
1798
+ continue;
1799
+ }
1800
+ if(value.$hydrate) {
1801
+ value.$hydrate(element, className);
1802
+ continue;
1803
+ }
1804
+ element.classes.toggle(className, value);
1792
1805
  }
1793
1806
  };
1794
1807
 
@@ -2068,24 +2081,6 @@ var NativeDocument = (function (exports) {
2068
2081
  this.$hydrate(element, attributeName);
2069
2082
  };
2070
2083
 
2071
- ObservableItem.prototype.bindClassProperty = function(element, className) {
2072
- element.classes.toggle(className, this.val());
2073
- this.subscribe((shouldAdd) => element.classes.toggle(className, shouldAdd));
2074
- };
2075
-
2076
- ObservableWhen.prototype.bindClassProperty = function(element, className) {
2077
- element.classes.toggle(className, this.isActive());
2078
- this.subscribe((shouldAdd) => element.classes.toggle(className, shouldAdd));
2079
- };
2080
-
2081
- TemplateBinding.prototype.bindClassProperty = function(element, className) {
2082
- this.$hydrate(element, className);
2083
- };
2084
-
2085
- Boolean.prototype.bindClassProperty = function(element, className) {
2086
- element.classes.toggle(className, this);
2087
- };
2088
-
2089
2084
  let $textNodeCache = null;
2090
2085
 
2091
2086
  const ElementCreator = {
@@ -3046,22 +3041,19 @@ var NativeDocument = (function (exports) {
3046
3041
  }
3047
3042
  }
3048
3043
  if(this.$classes) {
3044
+ const cache = {};
3049
3045
  const keys = Object.keys(this.$classes);
3050
3046
 
3051
3047
  if(keys.length === 1) {
3052
3048
  const key = keys[0];
3053
3049
  const callback = this.$classes[key];
3054
3050
  steps.push((clonedNode, data) => {
3055
- callback.apply(null, data).bindClassProperty(clonedNode, key);
3051
+ cache[key] = callback.apply(null, data);
3052
+ ElementCreator.processClassAttribute(clonedNode, cache);
3056
3053
  });
3057
3054
  } else {
3058
- const properties = this.$classes;
3059
- const keysLength = keys.length;
3060
3055
  steps.push((clonedNode, data) => {
3061
- for(let i = 0; i < keysLength; i++) {
3062
- const key = keys[i];
3063
- properties[key].apply(null, data).bindClassProperty(clonedNode, key);
3064
- }
3056
+ ElementCreator.processClassAttribute(clonedNode, buildProperties(cache, this.$classes, data));
3065
3057
  });
3066
3058
  }
3067
3059
  }
@@ -5094,7 +5086,6 @@ var NativeDocument = (function (exports) {
5094
5086
  function ForEachArray(data, callback, configs = {}) {
5095
5087
  const element = Anchor('ForEach Array', configs.isParentUniqueChild);
5096
5088
  const blockEnd = element.endElement();
5097
- element.startElement();
5098
5089
 
5099
5090
  let cache = new Map();
5100
5091
  let lastNumberOfItems = 0;
@@ -5142,7 +5133,7 @@ var NativeDocument = (function (exports) {
5142
5133
  };
5143
5134
 
5144
5135
  const createAndCache = (item) => {
5145
- const child = ElementCreator.getChild(callback(item, null));
5136
+ const child = callback(item, null);
5146
5137
  {
5147
5138
  if(!child) {
5148
5139
  throw new NativeDocumentError("ForEachArray child can't be null or undefined!");
@@ -5154,7 +5145,7 @@ var NativeDocument = (function (exports) {
5154
5145
 
5155
5146
  const createWithIndexAndCache = (item, indexKey) => {
5156
5147
  const indexObserver = Observable(indexKey);
5157
- const child = ElementCreator.getChild(callback(item, indexObserver));
5148
+ const child = callback(item, indexObserver);
5158
5149
  {
5159
5150
  if(!child) {
5160
5151
  throw new NativeDocumentError("ForEachArray child can't be null or undefined!");