@oscarpalmer/mora 0.9.0 → 0.11.0

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.
@@ -6,33 +6,57 @@ declare class Effect {
6
6
  private readonly state;
7
7
  constructor(callback: GenericCallback);
8
8
  }
9
- export type ComputedState<Value> = {
10
- computeds: Set<Computed<unknown>>;
9
+ export type ComputedEffect = {
11
10
  dirty: boolean;
12
- effect: Effect;
13
- effects: Set<Effect>;
14
- value: Value;
11
+ instance: Effect;
15
12
  };
16
13
  export type InternalComputed = {
17
- readonly state: ComputedState<unknown>;
14
+ readonly effect: ComputedEffect;
15
+ readonly state: ReactiveState<unknown>;
18
16
  };
19
17
  export declare let activeComputed: Computed<unknown> | undefined;
20
- export declare class Computed<Value> {
21
- private readonly $mora;
22
- private readonly state;
18
+ export declare class Computed<Value> extends Reactive<Value> {
19
+ private readonly effect;
23
20
  constructor(callback: () => Value);
24
21
  /**
25
22
  * Get the value
26
23
  */
27
24
  get(): Value;
25
+ }
26
+ /**
27
+ * Create a computed value
28
+ */
29
+ export declare function computed<Value>(callback: () => Value): Computed<Value>;
30
+ declare abstract class Reactive<Value> {
31
+ protected readonly state: ReactiveState<Value>;
32
+ constructor(name: string, value: Value);
28
33
  /**
29
34
  * Get the value _(without reactivity)_
30
35
  */
31
36
  peek(): Value;
37
+ /**
38
+ * Subscribe to changes
39
+ */
40
+ subscribe(callback: (value: Value) => void): Unsubscribe;
41
+ /**
42
+ * Unsubscribe from changes
43
+ */
44
+ unsubscribe(callback: (value: Value) => void): void;
45
+ }
46
+ export type ReactiveState<Value> = {
47
+ computeds: Set<Computed<unknown>>;
48
+ effects: Set<Effect>;
49
+ subscriptions: Map<(value: Value) => void, Subscription<Value>>;
50
+ value: Value;
51
+ };
52
+ declare class Subscription<Value> {
53
+ state: ReactiveState<Value>;
54
+ callback: GenericCallback;
55
+ constructor(state: ReactiveState<Value>, callback: GenericCallback);
32
56
  }
33
57
  /**
34
- * Create a computed value
58
+ * Unsubscribe from changes
35
59
  */
36
- export declare function computed<Value>(callback: () => Value): Computed<Value>;
60
+ export type Unsubscribe = () => void;
37
61
 
38
62
  export {};
@@ -1,27 +1,21 @@
1
1
  import { type Effect } from './effect';
2
- type ComputedState<Value> = {
3
- computeds: Set<Computed<unknown>>;
2
+ import { Reactive, type ReactiveState } from './reactive';
3
+ type ComputedEffect = {
4
4
  dirty: boolean;
5
- effect: Effect;
6
- effects: Set<Effect>;
7
- value: Value;
5
+ instance: Effect;
8
6
  };
9
7
  export type InternalComputed = {
10
- readonly state: ComputedState<unknown>;
8
+ readonly effect: ComputedEffect;
9
+ readonly state: ReactiveState<unknown>;
11
10
  };
12
11
  export declare let activeComputed: Computed<unknown> | undefined;
13
- export declare class Computed<Value> {
14
- private readonly $mora;
15
- private readonly state;
12
+ export declare class Computed<Value> extends Reactive<Value> {
13
+ private readonly effect;
16
14
  constructor(callback: () => Value);
17
15
  /**
18
16
  * Get the value
19
17
  */
20
18
  get(): Value;
21
- /**
22
- * Get the value _(without reactivity)_
23
- */
24
- peek(): Value;
25
19
  }
26
20
  /**
27
21
  * Create a computed value
@@ -12,6 +12,5 @@ export declare function runEffect(effect: Effect): void;
12
12
  */
13
13
  export declare function effect(callback: GenericCallback): Effect;
14
14
  export declare let activeEffect: Effect | undefined;
15
- export declare const dirtyEffects: Set<Effect>;
16
15
 
17
16
  export {};
package/types/effect.d.ts CHANGED
@@ -10,4 +10,3 @@ export declare function runEffect(effect: Effect): void;
10
10
  */
11
11
  export declare function effect(callback: GenericCallback): Effect;
12
12
  export declare let activeEffect: Effect | undefined;
13
- export declare const dirtyEffects: Set<Effect>;
package/types/index.d.cts CHANGED
@@ -1,54 +1,74 @@
1
1
  // Generated by dts-bundle-generator v9.5.1
2
2
 
3
- export declare class Signal<Value> {
3
+ export type GenericCallback = (...args: any[]) => any;
4
+ export declare class Effect {
4
5
  private readonly $mora;
5
6
  private readonly state;
6
- constructor(value: Value);
7
+ constructor(callback: GenericCallback);
8
+ }
9
+ /**
10
+ * Create an effect
11
+ */
12
+ export declare function effect(callback: GenericCallback): Effect;
13
+ export declare class Computed<Value> extends Reactive<Value> {
14
+ private readonly effect;
15
+ constructor(callback: () => Value);
7
16
  /**
8
17
  * Get the value
9
18
  */
10
19
  get(): Value;
20
+ }
21
+ /**
22
+ * Create a computed value
23
+ */
24
+ export declare function computed<Value>(callback: () => Value): Computed<Value>;
25
+ declare abstract class Reactive<Value> {
26
+ protected readonly state: ReactiveState<Value>;
27
+ constructor(name: string, value: Value);
11
28
  /**
12
29
  * Get the value _(without reactivity)_
13
30
  */
14
31
  peek(): Value;
15
32
  /**
16
- * Set the value
33
+ * Subscribe to changes
17
34
  */
18
- set(value: Value): void;
35
+ subscribe(callback: (value: Value) => void): Unsubscribe;
19
36
  /**
20
- * Update the value
37
+ * Unsubscribe from changes
21
38
  */
22
- update(callback: (value: Value) => Value): void;
39
+ unsubscribe(callback: (value: Value) => void): void;
23
40
  }
24
- export declare function signal<Value>(value: Value): Signal<Value>;
25
- export type GenericCallback = (...args: any[]) => any;
26
- export declare class Effect {
27
- private readonly $mora;
28
- private readonly state;
29
- constructor(callback: GenericCallback);
41
+ export type ReactiveState<Value> = {
42
+ computeds: Set<Computed<unknown>>;
43
+ effects: Set<Effect>;
44
+ subscriptions: Map<(value: Value) => void, Subscription<Value>>;
45
+ value: Value;
46
+ };
47
+ declare class Subscription<Value> {
48
+ state: ReactiveState<Value>;
49
+ callback: GenericCallback;
50
+ constructor(state: ReactiveState<Value>, callback: GenericCallback);
30
51
  }
31
52
  /**
32
- * Create an effect
53
+ * Unsubscribe from changes
33
54
  */
34
- export declare function effect(callback: GenericCallback): Effect;
35
- export declare class Computed<Value> {
36
- private readonly $mora;
37
- private readonly state;
38
- constructor(callback: () => Value);
55
+ export type Unsubscribe = () => void;
56
+ export declare class Signal<Value> extends Reactive<Value> {
57
+ constructor(value: Value);
39
58
  /**
40
59
  * Get the value
41
60
  */
42
61
  get(): Value;
43
62
  /**
44
- * Get the value _(without reactivity)_
63
+ * Set the value
45
64
  */
46
- peek(): Value;
65
+ set(value: Value): void;
66
+ /**
67
+ * Update the value
68
+ */
69
+ update(callback: (value: Value) => Value): void;
47
70
  }
48
- /**
49
- * Create a computed value
50
- */
51
- export declare function computed<Value>(callback: () => Value): Computed<Value>;
71
+ export declare function signal<Value>(value: Value): Signal<Value>;
52
72
  /**
53
73
  * Is the value a computed signal?
54
74
  */
package/types/is.d.cts CHANGED
@@ -1,44 +1,64 @@
1
1
  // Generated by dts-bundle-generator v9.5.1
2
2
 
3
- declare class Signal<Value> {
3
+ export type GenericCallback = (...args: any[]) => any;
4
+ declare class Effect {
4
5
  private readonly $mora;
5
6
  private readonly state;
6
- constructor(value: Value);
7
+ constructor(callback: GenericCallback);
8
+ }
9
+ declare class Computed<Value> extends Reactive<Value> {
10
+ private readonly effect;
11
+ constructor(callback: () => Value);
7
12
  /**
8
13
  * Get the value
9
14
  */
10
15
  get(): Value;
16
+ }
17
+ declare abstract class Reactive<Value> {
18
+ protected readonly state: ReactiveState<Value>;
19
+ constructor(name: string, value: Value);
11
20
  /**
12
21
  * Get the value _(without reactivity)_
13
22
  */
14
23
  peek(): Value;
15
24
  /**
16
- * Set the value
25
+ * Subscribe to changes
17
26
  */
18
- set(value: Value): void;
27
+ subscribe(callback: (value: Value) => void): Unsubscribe;
19
28
  /**
20
- * Update the value
29
+ * Unsubscribe from changes
21
30
  */
22
- update(callback: (value: Value) => Value): void;
31
+ unsubscribe(callback: (value: Value) => void): void;
23
32
  }
24
- export type GenericCallback = (...args: any[]) => any;
25
- declare class Effect {
26
- private readonly $mora;
27
- private readonly state;
28
- constructor(callback: GenericCallback);
33
+ export type ReactiveState<Value> = {
34
+ computeds: Set<Computed<unknown>>;
35
+ effects: Set<Effect>;
36
+ subscriptions: Map<(value: Value) => void, Subscription<Value>>;
37
+ value: Value;
38
+ };
39
+ declare class Subscription<Value> {
40
+ state: ReactiveState<Value>;
41
+ callback: GenericCallback;
42
+ constructor(state: ReactiveState<Value>, callback: GenericCallback);
29
43
  }
30
- declare class Computed<Value> {
31
- private readonly $mora;
32
- private readonly state;
33
- constructor(callback: () => Value);
44
+ /**
45
+ * Unsubscribe from changes
46
+ */
47
+ export type Unsubscribe = () => void;
48
+ declare class Signal<Value> extends Reactive<Value> {
49
+ constructor(value: Value);
34
50
  /**
35
51
  * Get the value
36
52
  */
37
53
  get(): Value;
38
54
  /**
39
- * Get the value _(without reactivity)_
55
+ * Set the value
40
56
  */
41
- peek(): Value;
57
+ set(value: Value): void;
58
+ /**
59
+ * Update the value
60
+ */
61
+ update(callback: (value: Value) => Value): void;
42
62
  }
43
63
  /**
44
64
  * Is the value a computed signal?
@@ -48,6 +68,7 @@ export declare function isComputed(value: unknown): value is Computed<unknown>;
48
68
  * Is the value an effect?
49
69
  */
50
70
  export declare function isEffect(value: unknown): value is Effect;
71
+ export declare function isReactive(value: unknown): value is Reactive<unknown>;
51
72
  /**
52
73
  * Is the value a signal?
53
74
  */
package/types/is.d.ts CHANGED
@@ -1,5 +1,6 @@
1
1
  import type { Computed } from './computed';
2
2
  import type { Effect } from './effect';
3
+ import type { Reactive } from './reactive';
3
4
  import type { Signal } from './signal';
4
5
  /**
5
6
  * Is the value a computed signal?
@@ -9,6 +10,7 @@ export declare function isComputed(value: unknown): value is Computed<unknown>;
9
10
  * Is the value an effect?
10
11
  */
11
12
  export declare function isEffect(value: unknown): value is Effect;
13
+ export declare function isReactive(value: unknown): value is Reactive<unknown>;
12
14
  /**
13
15
  * Is the value a signal?
14
16
  */
@@ -0,0 +1,49 @@
1
+ // Generated by dts-bundle-generator v9.5.1
2
+
3
+ export type GenericCallback = (...args: any[]) => any;
4
+ declare class Effect {
5
+ private readonly $mora;
6
+ private readonly state;
7
+ constructor(callback: GenericCallback);
8
+ }
9
+ declare class Computed<Value> extends Reactive<Value> {
10
+ private readonly effect;
11
+ constructor(callback: () => Value);
12
+ /**
13
+ * Get the value
14
+ */
15
+ get(): Value;
16
+ }
17
+ export declare abstract class Reactive<Value> {
18
+ protected readonly state: ReactiveState<Value>;
19
+ constructor(name: string, value: Value);
20
+ /**
21
+ * Get the value _(without reactivity)_
22
+ */
23
+ peek(): Value;
24
+ /**
25
+ * Subscribe to changes
26
+ */
27
+ subscribe(callback: (value: Value) => void): Unsubscribe;
28
+ /**
29
+ * Unsubscribe from changes
30
+ */
31
+ unsubscribe(callback: (value: Value) => void): void;
32
+ }
33
+ export type ReactiveState<Value> = {
34
+ computeds: Set<Computed<unknown>>;
35
+ effects: Set<Effect>;
36
+ subscriptions: Map<(value: Value) => void, Subscription<Value>>;
37
+ value: Value;
38
+ };
39
+ declare class Subscription<Value> {
40
+ state: ReactiveState<Value>;
41
+ callback: GenericCallback;
42
+ constructor(state: ReactiveState<Value>, callback: GenericCallback);
43
+ }
44
+ /**
45
+ * Unsubscribe from changes
46
+ */
47
+ export type Unsubscribe = () => void;
48
+
49
+ export {};
@@ -0,0 +1,25 @@
1
+ import type { Computed } from './computed';
2
+ import type { Effect } from './effect';
3
+ import { type Subscription, type Unsubscribe } from './subscription';
4
+ export declare abstract class Reactive<Value> {
5
+ protected readonly state: ReactiveState<Value>;
6
+ constructor(name: string, value: Value);
7
+ /**
8
+ * Get the value _(without reactivity)_
9
+ */
10
+ peek(): Value;
11
+ /**
12
+ * Subscribe to changes
13
+ */
14
+ subscribe(callback: (value: Value) => void): Unsubscribe;
15
+ /**
16
+ * Unsubscribe from changes
17
+ */
18
+ unsubscribe(callback: (value: Value) => void): void;
19
+ }
20
+ export type ReactiveState<Value> = {
21
+ computeds: Set<Computed<unknown>>;
22
+ effects: Set<Effect>;
23
+ subscriptions: Map<(value: Value) => void, Subscription<Value>>;
24
+ value: Value;
25
+ };
@@ -1,17 +1,56 @@
1
1
  // Generated by dts-bundle-generator v9.5.1
2
2
 
3
- export declare class Signal<Value> {
3
+ export type GenericCallback = (...args: any[]) => any;
4
+ declare class Effect {
4
5
  private readonly $mora;
5
6
  private readonly state;
6
- constructor(value: Value);
7
+ constructor(callback: GenericCallback);
8
+ }
9
+ declare class Computed<Value> extends Reactive<Value> {
10
+ private readonly effect;
11
+ constructor(callback: () => Value);
7
12
  /**
8
13
  * Get the value
9
14
  */
10
15
  get(): Value;
16
+ }
17
+ declare abstract class Reactive<Value> {
18
+ protected readonly state: ReactiveState<Value>;
19
+ constructor(name: string, value: Value);
11
20
  /**
12
21
  * Get the value _(without reactivity)_
13
22
  */
14
23
  peek(): Value;
24
+ /**
25
+ * Subscribe to changes
26
+ */
27
+ subscribe(callback: (value: Value) => void): Unsubscribe;
28
+ /**
29
+ * Unsubscribe from changes
30
+ */
31
+ unsubscribe(callback: (value: Value) => void): void;
32
+ }
33
+ export type ReactiveState<Value> = {
34
+ computeds: Set<Computed<unknown>>;
35
+ effects: Set<Effect>;
36
+ subscriptions: Map<(value: Value) => void, Subscription<Value>>;
37
+ value: Value;
38
+ };
39
+ declare class Subscription<Value> {
40
+ state: ReactiveState<Value>;
41
+ callback: GenericCallback;
42
+ constructor(state: ReactiveState<Value>, callback: GenericCallback);
43
+ }
44
+ /**
45
+ * Unsubscribe from changes
46
+ */
47
+ export type Unsubscribe = () => void;
48
+ export declare class Signal<Value> extends Reactive<Value> {
49
+ constructor(value: Value);
50
+ /**
51
+ * Get the value
52
+ */
53
+ get(): Value;
15
54
  /**
16
55
  * Set the value
17
56
  */
package/types/signal.d.ts CHANGED
@@ -1,15 +1,10 @@
1
- export declare class Signal<Value> {
2
- private readonly $mora;
3
- private readonly state;
1
+ import { Reactive } from './reactive';
2
+ export declare class Signal<Value> extends Reactive<Value> {
4
3
  constructor(value: Value);
5
4
  /**
6
5
  * Get the value
7
6
  */
8
7
  get(): Value;
9
- /**
10
- * Get the value _(without reactivity)_
11
- */
12
- peek(): Value;
13
8
  /**
14
9
  * Set the value
15
10
  */
@@ -0,0 +1,52 @@
1
+ // Generated by dts-bundle-generator v9.5.1
2
+
3
+ export type GenericCallback = (...args: any[]) => any;
4
+ declare class Effect {
5
+ private readonly $mora;
6
+ private readonly state;
7
+ constructor(callback: GenericCallback);
8
+ }
9
+ declare class Computed<Value> extends Reactive<Value> {
10
+ private readonly effect;
11
+ constructor(callback: () => Value);
12
+ /**
13
+ * Get the value
14
+ */
15
+ get(): Value;
16
+ }
17
+ declare abstract class Reactive<Value> {
18
+ protected readonly state: ReactiveState<Value>;
19
+ constructor(name: string, value: Value);
20
+ /**
21
+ * Get the value _(without reactivity)_
22
+ */
23
+ peek(): Value;
24
+ /**
25
+ * Subscribe to changes
26
+ */
27
+ subscribe(callback: (value: Value) => void): Unsubscribe;
28
+ /**
29
+ * Unsubscribe from changes
30
+ */
31
+ unsubscribe(callback: (value: Value) => void): void;
32
+ }
33
+ export type ReactiveState<Value> = {
34
+ computeds: Set<Computed<unknown>>;
35
+ effects: Set<Effect>;
36
+ subscriptions: Map<(value: Value) => void, Subscription<Value>>;
37
+ value: Value;
38
+ };
39
+ export declare class Subscription<Value> {
40
+ state: ReactiveState<Value>;
41
+ callback: GenericCallback;
42
+ constructor(state: ReactiveState<Value>, callback: GenericCallback);
43
+ }
44
+ /**
45
+ * Unsubscribe from changes
46
+ */
47
+ export type Unsubscribe = () => void;
48
+ export declare function noop(): void;
49
+ export declare function subscribe<Value>(state: ReactiveState<Value>, callback: (value: Value) => void): Unsubscribe;
50
+ export declare function unsubscribe<Value>(state: ReactiveState<Value>, callback: (value: Value) => void): void;
51
+
52
+ export {};
@@ -0,0 +1,14 @@
1
+ import type { GenericCallback } from '@oscarpalmer/atoms/models';
2
+ import type { ReactiveState } from './reactive';
3
+ export declare class Subscription<Value> {
4
+ state: ReactiveState<Value>;
5
+ callback: GenericCallback;
6
+ constructor(state: ReactiveState<Value>, callback: GenericCallback);
7
+ }
8
+ /**
9
+ * Unsubscribe from changes
10
+ */
11
+ export type Unsubscribe = () => void;
12
+ export declare function noop(): void;
13
+ export declare function subscribe<Value>(state: ReactiveState<Value>, callback: (value: Value) => void): Unsubscribe;
14
+ export declare function unsubscribe<Value>(state: ReactiveState<Value>, callback: (value: Value) => void): void;