shablon 0.0.1-rc.5 → 0.0.1-rc.6

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.
Files changed (2) hide show
  1. package/package.json +1 -1
  2. package/src/state.js +20 -17
package/package.json CHANGED
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "0.0.1-rc.5",
2
+ "version": "0.0.1-rc.6",
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
@@ -228,6 +228,22 @@ function createProxy(obj, pathWatcherIds) {
228
228
  return obj;
229
229
  }
230
230
 
231
+ // getter?
232
+ let getterProp;
233
+ if (descriptors[prop]?.get) {
234
+ // if not invoked inside a watch function, call the original
235
+ // getter to ensure that an up-to-date value is computed
236
+ if (!activeWatcher) {
237
+ return descriptors[prop]?.get?.call(obj);
238
+ }
239
+
240
+ getterProp = prop;
241
+
242
+ // replace with an internal property so that reactive statements can be cached
243
+ prop = "@@" + prop;
244
+ Object.defineProperty(obj, prop, { writable: true, enumerable: false });
245
+ }
246
+
231
247
  // evicted child?
232
248
  if (!obj[skipSym] && obj[parentSym]) {
233
249
  let props = [];
@@ -277,22 +293,6 @@ function createProxy(obj, pathWatcherIds) {
277
293
  }
278
294
  }
279
295
 
280
- // getter?
281
- let getterProp;
282
- if (descriptors[prop]?.get) {
283
- // if not invoked inside a watch function, call the original
284
- // getter to ensure that an up-to-date value is computed
285
- if (!activeWatcher) {
286
- return descriptors[prop]?.get?.call(obj);
287
- }
288
-
289
- getterProp = prop;
290
-
291
- // replace with an internal "@@prop" property so that
292
- // reactive statements can be cached
293
- prop = "@@" + prop;
294
- }
295
-
296
296
  let propVal = obj[prop];
297
297
 
298
298
  // directly return for functions (pop, push, etc.)
@@ -360,11 +360,14 @@ function createProxy(obj, pathWatcherIds) {
360
360
 
361
361
  let getFunc = descriptors[getterProp].get.bind(obj);
362
362
 
363
- let getWatcher = watch(() => (receiver[prop] = getFunc()));
363
+ let getWatcher = watch(getFunc, (result) => (receiver[prop] = result));
364
364
 
365
365
  getWatcher[onRemoveSym] = () => {
366
366
  descriptors[getterProp]?.watchers?.delete(watcherId);
367
367
  };
368
+
369
+ // update with the cached get value after the above watch initialization
370
+ propVal = obj[prop]
368
371
  }
369
372
  }
370
373