@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.
- package/dist/batch.cjs +12 -5
- package/dist/batch.js +13 -6
- package/dist/computed.cjs +17 -25
- package/dist/computed.js +19 -27
- package/dist/effect.cjs +0 -2
- package/dist/effect.js +0 -2
- package/dist/is.cjs +4 -0
- package/dist/is.js +4 -0
- package/dist/mora.full.js +120 -74
- package/dist/reactive.cjs +39 -0
- package/dist/reactive.js +39 -0
- package/dist/signal.cjs +9 -22
- package/dist/signal.js +10 -23
- package/dist/subscription.cjs +32 -0
- package/dist/subscription.js +32 -0
- package/package.json +1 -1
- package/src/batch.ts +14 -6
- package/src/computed.ts +48 -67
- package/src/effect.ts +0 -2
- package/src/is.ts +5 -0
- package/src/reactive.ts +53 -0
- package/src/signal.ts +44 -64
- package/src/subscription.ts +47 -0
- package/types/batch.d.cts +46 -0
- package/types/batch.d.ts +3 -0
- package/types/computed.d.cts +35 -11
- package/types/computed.d.ts +7 -13
- package/types/effect.d.cts +0 -1
- package/types/effect.d.ts +0 -1
- package/types/index.d.cts +44 -24
- package/types/is.d.cts +38 -17
- package/types/is.d.ts +2 -0
- package/types/reactive.d.cts +49 -0
- package/types/reactive.d.ts +25 -0
- package/types/signal.d.cts +41 -2
- package/types/signal.d.ts +2 -7
- package/types/subscription.d.cts +52 -0
- package/types/subscription.d.ts +14 -0
package/types/computed.d.cts
CHANGED
|
@@ -6,33 +6,57 @@ declare class Effect {
|
|
|
6
6
|
private readonly state;
|
|
7
7
|
constructor(callback: GenericCallback);
|
|
8
8
|
}
|
|
9
|
-
export type
|
|
10
|
-
computeds: Set<Computed<unknown>>;
|
|
9
|
+
export type ComputedEffect = {
|
|
11
10
|
dirty: boolean;
|
|
12
|
-
|
|
13
|
-
effects: Set<Effect>;
|
|
14
|
-
value: Value;
|
|
11
|
+
instance: Effect;
|
|
15
12
|
};
|
|
16
13
|
export type InternalComputed = {
|
|
17
|
-
readonly
|
|
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
|
|
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
|
-
*
|
|
58
|
+
* Unsubscribe from changes
|
|
35
59
|
*/
|
|
36
|
-
export
|
|
60
|
+
export type Unsubscribe = () => void;
|
|
37
61
|
|
|
38
62
|
export {};
|
package/types/computed.d.ts
CHANGED
|
@@ -1,27 +1,21 @@
|
|
|
1
1
|
import { type Effect } from './effect';
|
|
2
|
-
type
|
|
3
|
-
|
|
2
|
+
import { Reactive, type ReactiveState } from './reactive';
|
|
3
|
+
type ComputedEffect = {
|
|
4
4
|
dirty: boolean;
|
|
5
|
-
|
|
6
|
-
effects: Set<Effect>;
|
|
7
|
-
value: Value;
|
|
5
|
+
instance: Effect;
|
|
8
6
|
};
|
|
9
7
|
export type InternalComputed = {
|
|
10
|
-
readonly
|
|
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
|
|
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
|
package/types/effect.d.cts
CHANGED
package/types/effect.d.ts
CHANGED
package/types/index.d.cts
CHANGED
|
@@ -1,54 +1,74 @@
|
|
|
1
1
|
// Generated by dts-bundle-generator v9.5.1
|
|
2
2
|
|
|
3
|
-
export
|
|
3
|
+
export type GenericCallback = (...args: any[]) => any;
|
|
4
|
+
export declare class Effect {
|
|
4
5
|
private readonly $mora;
|
|
5
6
|
private readonly state;
|
|
6
|
-
constructor(
|
|
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
|
-
*
|
|
33
|
+
* Subscribe to changes
|
|
17
34
|
*/
|
|
18
|
-
|
|
35
|
+
subscribe(callback: (value: Value) => void): Unsubscribe;
|
|
19
36
|
/**
|
|
20
|
-
*
|
|
37
|
+
* Unsubscribe from changes
|
|
21
38
|
*/
|
|
22
|
-
|
|
39
|
+
unsubscribe(callback: (value: Value) => void): void;
|
|
23
40
|
}
|
|
24
|
-
export
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
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
|
-
*
|
|
53
|
+
* Unsubscribe from changes
|
|
33
54
|
*/
|
|
34
|
-
export
|
|
35
|
-
export declare class
|
|
36
|
-
|
|
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
|
-
*
|
|
63
|
+
* Set the value
|
|
45
64
|
*/
|
|
46
|
-
|
|
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
|
-
|
|
3
|
+
export type GenericCallback = (...args: any[]) => any;
|
|
4
|
+
declare class Effect {
|
|
4
5
|
private readonly $mora;
|
|
5
6
|
private readonly state;
|
|
6
|
-
constructor(
|
|
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
|
-
*
|
|
25
|
+
* Subscribe to changes
|
|
17
26
|
*/
|
|
18
|
-
|
|
27
|
+
subscribe(callback: (value: Value) => void): Unsubscribe;
|
|
19
28
|
/**
|
|
20
|
-
*
|
|
29
|
+
* Unsubscribe from changes
|
|
21
30
|
*/
|
|
22
|
-
|
|
31
|
+
unsubscribe(callback: (value: Value) => void): void;
|
|
23
32
|
}
|
|
24
|
-
export type
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
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
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
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
|
-
*
|
|
55
|
+
* Set the value
|
|
40
56
|
*/
|
|
41
|
-
|
|
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
|
+
};
|
package/types/signal.d.cts
CHANGED
|
@@ -1,17 +1,56 @@
|
|
|
1
1
|
// Generated by dts-bundle-generator v9.5.1
|
|
2
2
|
|
|
3
|
-
export
|
|
3
|
+
export type GenericCallback = (...args: any[]) => any;
|
|
4
|
+
declare class Effect {
|
|
4
5
|
private readonly $mora;
|
|
5
6
|
private readonly state;
|
|
6
|
-
constructor(
|
|
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
|
-
|
|
2
|
-
|
|
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;
|