native-document 1.0.283 → 1.0.284

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.
@@ -89,13 +89,13 @@ const ComponentRegistry = (function() {
89
89
  factoryWrapper.originalFactory = factory;
90
90
  return factoryWrapper;
91
91
  },
92
- update(id, newFactory, globalId) {
92
+ update(id, newFactory, globalId, componentName) {
93
93
  const component = registry.get(id);
94
94
  if(!component) {
95
95
  DebugManager.warn(`[HMR] Component ${id} not found`);
96
96
  return;
97
97
  }
98
- DebugManager.log(`[HMR] Updating ${component.instances.size} instance(s) of ${id}`);
98
+ DebugManager.log(`[HMR] Updating ${component.instances.size} instance(s) of ${componentName}`);
99
99
  const oldFactory = component.factory;
100
100
  if(typeof newFactory !== 'function') {
101
101
  DebugManager.log('[HMR] Updating factory is not a function : ', newFactory);
@@ -27,16 +27,18 @@ if (import.meta.hot) {
27
27
  const updateComponents = (newModule) => {
28
28
  try {
29
29
  let defaultId = '${id}';
30
+ let defaultName = defaultId;
30
31
  for(const component of componentIds) {
31
32
  if(newModule[component.name]) {
32
- ComponentRegistry.update(component.id, newModule[component.name], '${id}');
33
+ ComponentRegistry.update(component.id, newModule[component.name], '${id}', component.name);
33
34
  }
34
35
  if(component.isDefault) {
35
36
  defaultId = component.id;
37
+ defaultName = component.name;
36
38
  }
37
39
  }
38
40
  if(newModule.default) {
39
- ComponentRegistry.update(defaultId, newModule.default, '${id}');
41
+ ComponentRegistry.update(defaultId, newModule.default, '${id}', defaultName);
40
42
  }
41
43
  // console.log('[HMR Browser] ✓ Update successful');
42
44
  } catch (error) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "native-document",
3
- "version": "1.0.283",
3
+ "version": "1.0.284",
4
4
  "description": "A reactive JavaScript framework that preserves native DOM simplicity without sacrificing modern features",
5
5
  "author": "AfroCodeur <https://github.com/afrocodeur>",
6
6
  "license": "MIT",
@@ -241,6 +241,39 @@ Observable.value = function(data) {
241
241
  return data;
242
242
  };
243
243
 
244
+ /**
245
+ * For boolean states: Selects a value based on whether the observable is truthy or falsy.
246
+ *
247
+ * @param {*} whenTrue - Value returned when the observable is truthy
248
+ * @param {*} [whenFalse=null] - Value returned when the observable is falsy
249
+ * @returns {ObservableItem}
250
+ *
251
+ * @example
252
+ * isCollapsed.pick('/logos/icon.svg', '/logos/logo.svg')
253
+ */
254
+ ObservableItem.prototype.pick = function(whenTrue, whenFalse = null) {
255
+ return this.format((value) => (value ? whenTrue : whenFalse));
256
+ };
257
+
258
+ /**
259
+ * For pattern matching: Maps the current value to a matching key in a dictionary object.
260
+ *
261
+ * @param {Record<string|number|boolean, *>} cases - Dictionary mapping values to outcomes
262
+ * @param {*} [fallback=null] - Default value returned if no key matches
263
+ * @returns {ObservableItem}
264
+ *
265
+ * @example
266
+ * theme.match({ dark: '#000', light: '#fff' }, '#fff')
267
+ */
268
+ ObservableItem.prototype.match = function(cases, fallback = null) {
269
+ return this.format((value) => {
270
+ if (value in cases) {
271
+ return cases[value];
272
+ }
273
+ return fallback;
274
+ });
275
+ };
276
+
244
277
  Observable.object = Observable.init;
245
278
  Observable.json = Observable.init;
246
279
 
@@ -24,19 +24,19 @@ export const bindClassAttribute = (element, data) => {
24
24
  element.classes.toggle(currentValue, true);
25
25
  lastClass = currentValue;
26
26
  });
27
- return;
27
+ continue;
28
28
  }
29
29
  }
30
30
 
31
31
  if (value.__$Observable) {
32
32
  element.classes.toggle(className, value.val());
33
33
  value.subscribe((shouldAdd) => element.classes.toggle(className, shouldAdd));
34
- return;
34
+ continue;
35
35
  }
36
36
 
37
37
  if (value.$hydrate) {
38
38
  value.$hydrate(element, className, 'class');
39
- return;
39
+ continue;
40
40
  }
41
41
 
42
42
  element.classes.toggle(className, value);
@@ -64,4 +64,5 @@ export interface ObservableQueryInstance<T = any> {
64
64
  set(dataset: Dataset<T>): this;
65
65
  delete(): this;
66
66
  push(value: any): this;
67
+ unshift(value: any): this;
67
68
  }