vivth 0.11.1 → 0.11.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "vivth",
3
- "version": "0.11.1",
3
+ "version": "0.11.2",
4
4
  "description": "extremely simple signal as library primitives",
5
5
  "main": "index.mjs",
6
6
  "types": "./types/index.d.mts",
package/src/class/$.mjs CHANGED
@@ -38,7 +38,7 @@ export class $ {
38
38
  $.effects.set(this, new Set());
39
39
  };
40
40
  /**
41
- * @type {()=>void}
41
+ * @type {(arg0:{remove$:()=>void})=>void}
42
42
  */
43
43
  effect;
44
44
  /**
@@ -49,9 +49,9 @@ export class $ {
49
49
  new PingFIFO(async () => {
50
50
  $.isRegistering = true;
51
51
  if (isAsync(effect)) {
52
- await effect();
52
+ await effect({ remove$: this.remove$ });
53
53
  } else {
54
- effect();
54
+ effect({ remove$: this.remove$ });
55
55
  }
56
56
  $.isRegistering = false;
57
57
  const signalInstances = $.activeSignal;
@@ -16,17 +16,22 @@ import { isAsync } from '../common.mjs';
16
16
  */
17
17
  export class Derived extends Signal {
18
18
  /**
19
- * @param {()=>V} derivedFunction
19
+ * @param {(arg0:{remove$:()=>void})=>V} derivedFunction
20
20
  */
21
21
  constructor(derivedFunction) {
22
- // @ts-expect-error
23
- super(0);
22
+ super(undefined);
24
23
  const real = isAsync(derivedFunction)
25
- ? async () => {
26
- super.value = await derivedFunction();
24
+ ? /**
25
+ * @param {{remove$:()=>void}} options
26
+ */
27
+ async (options) => {
28
+ super.value = await derivedFunction(options);
27
29
  }
28
- : () => {
29
- super.value = derivedFunction();
30
+ : /**
31
+ * @param {{remove$:()=>void}} options
32
+ */
33
+ (options) => {
34
+ super.value = derivedFunction(options);
30
35
  };
31
36
  new $(real);
32
37
  }
@@ -94,6 +94,6 @@ export class Signal {
94
94
  if (!this.subscribed) {
95
95
  return;
96
96
  }
97
- this.subscribed.forEach(($_) => $_.effect());
97
+ this.subscribed.forEach(($_) => $_.effect({ remove$: $_.remove$ }));
98
98
  };
99
99
  }
@@ -32,7 +32,9 @@ export class $ {
32
32
  */
33
33
  remove$: () => void;
34
34
  /**
35
- * @type {()=>void}
35
+ * @type {(arg0:{remove$:()=>void})=>void}
36
36
  */
37
- effect: () => void;
37
+ effect: (arg0: {
38
+ remove$: () => void;
39
+ }) => void;
38
40
  }
@@ -10,8 +10,10 @@
10
10
  */
11
11
  export class Derived<V> extends Signal<V> {
12
12
  /**
13
- * @param {()=>V} derivedFunction
13
+ * @param {(arg0:{remove$:()=>void})=>V} derivedFunction
14
14
  */
15
- constructor(derivedFunction: () => V);
15
+ constructor(derivedFunction: (arg0: {
16
+ remove$: () => void;
17
+ }) => V);
16
18
  }
17
19
  import { Signal } from './Signal.mjs';