shablon 0.0.1-rc.6 → 0.0.1-rc.7

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.
package/package.json CHANGED
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "0.0.1-rc.6",
2
+ "version": "0.0.1-rc.7",
3
3
  "name": "shablon",
4
4
  "description": "No-build JavaScript framework for Single-page applications",
5
5
  "author": "Gani Georgiev",
package/src/state.js CHANGED
@@ -12,7 +12,7 @@ let pathsSubsSym = Symbol();
12
12
  let unwatchedSym = Symbol();
13
13
  let onRemoveSym = Symbol();
14
14
  let skipSym = Symbol();
15
- let evictedSym = Symbol();
15
+ let detachedSym = Symbol();
16
16
 
17
17
  let pathSeparator = "/";
18
18
 
@@ -244,18 +244,17 @@ function createProxy(obj, pathWatcherIds) {
244
244
  Object.defineProperty(obj, prop, { writable: true, enumerable: false });
245
245
  }
246
246
 
247
- // evicted child?
247
+ // detached child?
248
+ let isDetached;
248
249
  if (!obj[skipSym] && obj[parentSym]) {
249
250
  let props = [];
250
251
  let activeObj = obj;
251
252
 
252
- let isEvicted = false;
253
-
254
253
  // travel up to the root proxy
255
254
  // (aka. x.a.b*.c -> x)
256
255
  while (activeObj?.[parentSym]) {
257
- if (activeObj[evictedSym]) {
258
- isEvicted = true;
256
+ if (activeObj[detachedSym]) {
257
+ isDetached = true;
259
258
  }
260
259
 
261
260
  props.push(activeObj[parentSym][1]);
@@ -268,9 +267,9 @@ function createProxy(obj, pathWatcherIds) {
268
267
  // (we want: x.a.b(old).c -> x -> x.a.b(new).c)
269
268
  //
270
269
  // note: this technically could "leak" but for our case it should be fine
271
- // because the evicted object will become again garbage collectable
270
+ // because the detached object will become again garbage collectable
272
271
  // once the related watcher(s) are removed
273
- if (isEvicted) {
272
+ if (isDetached) {
274
273
  for (let i = props.length - 1; i >= 0; i--) {
275
274
  activeObj[skipSym] = true;
276
275
  let item = activeObj?.[props[i]];
@@ -321,16 +320,21 @@ function createProxy(obj, pathWatcherIds) {
321
320
 
322
321
  let propPaths = [currentPath];
323
322
 
324
- // always construct all parent paths ("x.a.b.c" => ["a", "a.b", "a.b.c"])
325
- // because a store child object can be passed as argument to a function
326
- // and in that case the parents proxy get trap will not be invoked,
327
- // and their path will not be registered
328
- if (obj[parentSym]) {
329
- let parts = currentPath.split(pathSeparator);
330
- while (parts.pop() && parts.length) {
331
- propPaths.push(parts.join(pathSeparator));
332
- }
333
- }
323
+ // ---
324
+ // NB! Disable for now because of the nonblocking and delayed
325
+ // nature of the current MutationObserver implementation for the `onunmount` hook
326
+ // leading to unexpected and delayed watch calls in methods like `Array.map`.
327
+ // ---
328
+ // if (isDetached) {
329
+ // // always construct all parent paths ("x.a.b.c" => ["a", "a.b", "a.b.c"])
330
+ // // because a store child object can be passed as argument to a function
331
+ // // and in that case the parents proxy get trap will not be invoked,
332
+ // // and their path will not be registered
333
+ // let parts = currentPath.split(pathSeparator);
334
+ // while (parts.pop() && parts.length) {
335
+ // propPaths.push(parts.join(pathSeparator));
336
+ // }
337
+ // }
334
338
 
335
339
  // initialize a watcher paths tracking set (if not already)
336
340
  activeWatcher[pathsSubsSym] = activeWatcher[pathsSubsSym] || new Set();
@@ -381,9 +385,9 @@ function createProxy(obj, pathWatcherIds) {
381
385
 
382
386
  let oldValue = obj[prop];
383
387
 
384
- // mark as "evicted" in case a proxy child object/array is being replaced
388
+ // mark as "detached" in case a proxy child object/array is being replaced
385
389
  if (oldValue?.[parentSym]) {
386
- oldValue[evictedSym] = true;
390
+ oldValue[detachedSym] = true;
387
391
  }
388
392
 
389
393
  // update the stored parent reference in case of index change (e.g. unshift)
package/src/template.js CHANGED
@@ -117,10 +117,12 @@ function tag(tagName, attrs = {}, ...children) {
117
117
  return;
118
118
  }
119
119
 
120
+ const result = val(el, attr)
121
+
120
122
  if (useSetAttr) {
121
- el.setAttribute(attr, val(el));
123
+ el.setAttribute(attr, result);
122
124
  } else {
123
- el[attr] = val(el);
125
+ el[attr] = result;
124
126
  }
125
127
  });
126
128
  }