@esportsplus/reactivity 0.16.0 → 0.16.2

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/build/system.d.ts CHANGED
@@ -7,7 +7,7 @@ declare const isSignal: (value: unknown) => value is Signal<unknown>;
7
7
  declare const onCleanup: (fn: VoidFunction) => typeof fn;
8
8
  declare const read: <T>(node: Signal<T> | Computed<T>) => T;
9
9
  declare const root: {
10
- <T>(fn: (dispose?: VoidFunction) => T): T;
10
+ <T>(fn: ((dispose: VoidFunction) => T) | (() => T)): T;
11
11
  disposables: number;
12
12
  };
13
13
  declare const set: <T>(signal: Signal<T>, value: T) => void;
package/build/system.js CHANGED
@@ -332,14 +332,23 @@ const read = (node) => {
332
332
  return node.value;
333
333
  };
334
334
  const root = (fn) => {
335
- let d = root.disposables, o = observer, s = scope, self = null, tracking = fn.length;
335
+ let c, d = root.disposables, o = observer, s = scope, self = null, tracking = fn.length, value;
336
336
  observer = null;
337
337
  root.disposables = 0;
338
- scope = tracking ? (self = { cleanup: null }) : null;
339
- let value = fn(tracking ? () => dispose(self) : undefined);
338
+ if (tracking) {
339
+ scope = self = { cleanup: null };
340
+ value = fn(c = () => dispose(self));
341
+ }
342
+ else {
343
+ scope = null;
344
+ value = fn();
345
+ }
340
346
  observer = o;
341
347
  root.disposables = d;
342
348
  scope = s;
349
+ if (c) {
350
+ onCleanup(c);
351
+ }
343
352
  return value;
344
353
  };
345
354
  root.disposables = 0;
package/package.json CHANGED
@@ -12,7 +12,7 @@
12
12
  "private": false,
13
13
  "type": "module",
14
14
  "types": "build/index.d.ts",
15
- "version": "0.16.0",
15
+ "version": "0.16.2",
16
16
  "scripts": {
17
17
  "build": "tsc && tsc-alias",
18
18
  "-": "-"
package/src/system.ts CHANGED
@@ -464,23 +464,35 @@ const read = <T>(node: Signal<T> | Computed<T>): T => {
464
464
  return node.value;
465
465
  };
466
466
 
467
- const root = <T>(fn: (dispose?: VoidFunction) => T) => {
468
- let d = root.disposables,
467
+ const root = <T>(fn: ((dispose: VoidFunction) => T) | (() => T)) => {
468
+ let c,
469
+ d = root.disposables,
469
470
  o = observer,
470
471
  s = scope,
471
472
  self: Computed<unknown> | null = null,
472
- tracking = fn.length;
473
+ tracking = fn.length,
474
+ value: T;
473
475
 
474
476
  observer = null;
475
477
  root.disposables = 0;
476
- scope = tracking ? (self = { cleanup: null } as Computed<unknown>) : null;
477
478
 
478
- let value = fn( tracking ? () => dispose(self!) : undefined);
479
+ if (tracking) {
480
+ scope = self = { cleanup: null } as Computed<unknown>;
481
+ value = (fn as (dispose: VoidFunction) => T)(c = () => dispose(self!));
482
+ }
483
+ else {
484
+ scope = null;
485
+ value = (fn as () => T)();
486
+ }
479
487
 
480
488
  observer = o;
481
489
  root.disposables = d;
482
490
  scope = s;
483
491
 
492
+ if (c) {
493
+ onCleanup(c);
494
+ }
495
+
484
496
  return value;
485
497
  };
486
498