@oscarpalmer/mora 0.11.1 → 0.13.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/array.cjs +130 -0
- package/dist/array.js +130 -0
- package/dist/computed.cjs +1 -1
- package/dist/computed.js +1 -1
- package/dist/index.cjs +2 -0
- package/dist/index.js +2 -0
- package/dist/mora.full.js +234 -87
- package/dist/reactive.cjs +12 -0
- package/dist/reactive.js +12 -0
- package/dist/signal.cjs +9 -32
- package/dist/signal.js +4 -27
- package/dist/value.cjs +38 -0
- package/dist/value.js +38 -0
- package/package.json +1 -1
- package/src/array.ts +201 -0
- package/src/computed.ts +1 -1
- package/src/index.ts +2 -0
- package/src/reactive.ts +19 -0
- package/src/signal.ts +7 -34
- package/src/value.ts +47 -0
- package/types/array.d.cts +101 -0
- package/types/array.d.ts +41 -0
- package/types/batch.d.cts +22 -10
- package/types/computed.d.cts +22 -10
- package/types/computed.d.ts +1 -1
- package/types/index.d.cts +67 -12
- package/types/index.d.ts +2 -0
- package/types/is.d.cts +23 -11
- package/types/reactive.d.cts +22 -10
- package/types/reactive.d.ts +12 -0
- package/types/signal.d.cts +26 -11
- package/types/signal.d.ts +4 -1
- package/types/subscription.d.cts +25 -13
- package/types/value.d.cts +64 -0
- package/types/value.d.ts +4 -0
package/types/batch.d.cts
CHANGED
|
@@ -10,13 +10,26 @@ declare class Computed<Value> extends Reactive<Value> {
|
|
|
10
10
|
private readonly effect;
|
|
11
11
|
constructor(callback: () => Value);
|
|
12
12
|
/**
|
|
13
|
-
*
|
|
13
|
+
* @inheritdoc
|
|
14
14
|
*/
|
|
15
15
|
get(): Value;
|
|
16
16
|
}
|
|
17
|
+
declare class Subscription<Value> {
|
|
18
|
+
state: ReactiveState<Value>;
|
|
19
|
+
callback: GenericCallback;
|
|
20
|
+
constructor(state: ReactiveState<Value>, callback: GenericCallback);
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Unsubscribe from changes
|
|
24
|
+
*/
|
|
25
|
+
export type Unsubscribe = () => void;
|
|
17
26
|
declare abstract class Reactive<Value> {
|
|
18
27
|
protected readonly state: ReactiveState<Value>;
|
|
19
28
|
constructor(name: string, value: Value);
|
|
29
|
+
/**
|
|
30
|
+
* Get the value
|
|
31
|
+
*/
|
|
32
|
+
abstract get(): Value;
|
|
20
33
|
/**
|
|
21
34
|
* Get the value _(without reactivity)_
|
|
22
35
|
*/
|
|
@@ -25,6 +38,14 @@ declare abstract class Reactive<Value> {
|
|
|
25
38
|
* Subscribe to changes
|
|
26
39
|
*/
|
|
27
40
|
subscribe(callback: (value: Value) => void): Unsubscribe;
|
|
41
|
+
/**
|
|
42
|
+
* JSON representation of the value
|
|
43
|
+
*/
|
|
44
|
+
toJSON(): Value;
|
|
45
|
+
/**
|
|
46
|
+
* String representation of the value
|
|
47
|
+
*/
|
|
48
|
+
toString(): string;
|
|
28
49
|
/**
|
|
29
50
|
* Unsubscribe from changes
|
|
30
51
|
*/
|
|
@@ -36,15 +57,6 @@ export type ReactiveState<Value> = {
|
|
|
36
57
|
subscriptions: Map<(value: Value) => void, Subscription<Value>>;
|
|
37
58
|
value: Value;
|
|
38
59
|
};
|
|
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
60
|
export declare function flushEffects(): void;
|
|
49
61
|
/**
|
|
50
62
|
* Start batching effects _(use `stopBatch` to flush and run batched effects)_
|
package/types/computed.d.cts
CHANGED
|
@@ -19,7 +19,7 @@ export declare class Computed<Value> extends Reactive<Value> {
|
|
|
19
19
|
private readonly effect;
|
|
20
20
|
constructor(callback: () => Value);
|
|
21
21
|
/**
|
|
22
|
-
*
|
|
22
|
+
* @inheritdoc
|
|
23
23
|
*/
|
|
24
24
|
get(): Value;
|
|
25
25
|
}
|
|
@@ -27,9 +27,22 @@ export declare class Computed<Value> extends Reactive<Value> {
|
|
|
27
27
|
* Create a computed value
|
|
28
28
|
*/
|
|
29
29
|
export declare function computed<Value>(callback: () => Value): Computed<Value>;
|
|
30
|
+
declare class Subscription<Value> {
|
|
31
|
+
state: ReactiveState<Value>;
|
|
32
|
+
callback: GenericCallback;
|
|
33
|
+
constructor(state: ReactiveState<Value>, callback: GenericCallback);
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* Unsubscribe from changes
|
|
37
|
+
*/
|
|
38
|
+
export type Unsubscribe = () => void;
|
|
30
39
|
declare abstract class Reactive<Value> {
|
|
31
40
|
protected readonly state: ReactiveState<Value>;
|
|
32
41
|
constructor(name: string, value: Value);
|
|
42
|
+
/**
|
|
43
|
+
* Get the value
|
|
44
|
+
*/
|
|
45
|
+
abstract get(): Value;
|
|
33
46
|
/**
|
|
34
47
|
* Get the value _(without reactivity)_
|
|
35
48
|
*/
|
|
@@ -38,6 +51,14 @@ declare abstract class Reactive<Value> {
|
|
|
38
51
|
* Subscribe to changes
|
|
39
52
|
*/
|
|
40
53
|
subscribe(callback: (value: Value) => void): Unsubscribe;
|
|
54
|
+
/**
|
|
55
|
+
* JSON representation of the value
|
|
56
|
+
*/
|
|
57
|
+
toJSON(): Value;
|
|
58
|
+
/**
|
|
59
|
+
* String representation of the value
|
|
60
|
+
*/
|
|
61
|
+
toString(): string;
|
|
41
62
|
/**
|
|
42
63
|
* Unsubscribe from changes
|
|
43
64
|
*/
|
|
@@ -49,14 +70,5 @@ export type ReactiveState<Value> = {
|
|
|
49
70
|
subscriptions: Map<(value: Value) => void, Subscription<Value>>;
|
|
50
71
|
value: Value;
|
|
51
72
|
};
|
|
52
|
-
declare class Subscription<Value> {
|
|
53
|
-
state: ReactiveState<Value>;
|
|
54
|
-
callback: GenericCallback;
|
|
55
|
-
constructor(state: ReactiveState<Value>, callback: GenericCallback);
|
|
56
|
-
}
|
|
57
|
-
/**
|
|
58
|
-
* Unsubscribe from changes
|
|
59
|
-
*/
|
|
60
|
-
export type Unsubscribe = () => void;
|
|
61
73
|
|
|
62
74
|
export {};
|
package/types/computed.d.ts
CHANGED
package/types/index.d.cts
CHANGED
|
@@ -14,7 +14,7 @@ export declare class Computed<Value> extends Reactive<Value> {
|
|
|
14
14
|
private readonly effect;
|
|
15
15
|
constructor(callback: () => Value);
|
|
16
16
|
/**
|
|
17
|
-
*
|
|
17
|
+
* @inheritdoc
|
|
18
18
|
*/
|
|
19
19
|
get(): Value;
|
|
20
20
|
}
|
|
@@ -22,9 +22,22 @@ export declare class Computed<Value> extends Reactive<Value> {
|
|
|
22
22
|
* Create a computed value
|
|
23
23
|
*/
|
|
24
24
|
export declare function computed<Value>(callback: () => Value): Computed<Value>;
|
|
25
|
-
declare
|
|
25
|
+
declare class Subscription<Value> {
|
|
26
|
+
state: ReactiveState<Value>;
|
|
27
|
+
callback: GenericCallback;
|
|
28
|
+
constructor(state: ReactiveState<Value>, callback: GenericCallback);
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Unsubscribe from changes
|
|
32
|
+
*/
|
|
33
|
+
export type Unsubscribe = () => void;
|
|
34
|
+
export declare abstract class Reactive<Value> {
|
|
26
35
|
protected readonly state: ReactiveState<Value>;
|
|
27
36
|
constructor(name: string, value: Value);
|
|
37
|
+
/**
|
|
38
|
+
* Get the value
|
|
39
|
+
*/
|
|
40
|
+
abstract get(): Value;
|
|
28
41
|
/**
|
|
29
42
|
* Get the value _(without reactivity)_
|
|
30
43
|
*/
|
|
@@ -33,6 +46,14 @@ declare abstract class Reactive<Value> {
|
|
|
33
46
|
* Subscribe to changes
|
|
34
47
|
*/
|
|
35
48
|
subscribe(callback: (value: Value) => void): Unsubscribe;
|
|
49
|
+
/**
|
|
50
|
+
* JSON representation of the value
|
|
51
|
+
*/
|
|
52
|
+
toJSON(): Value;
|
|
53
|
+
/**
|
|
54
|
+
* String representation of the value
|
|
55
|
+
*/
|
|
56
|
+
toString(): string;
|
|
36
57
|
/**
|
|
37
58
|
* Unsubscribe from changes
|
|
38
59
|
*/
|
|
@@ -44,19 +65,10 @@ export type ReactiveState<Value> = {
|
|
|
44
65
|
subscriptions: Map<(value: Value) => void, Subscription<Value>>;
|
|
45
66
|
value: Value;
|
|
46
67
|
};
|
|
47
|
-
declare class Subscription<Value> {
|
|
48
|
-
state: ReactiveState<Value>;
|
|
49
|
-
callback: GenericCallback;
|
|
50
|
-
constructor(state: ReactiveState<Value>, callback: GenericCallback);
|
|
51
|
-
}
|
|
52
|
-
/**
|
|
53
|
-
* Unsubscribe from changes
|
|
54
|
-
*/
|
|
55
|
-
export type Unsubscribe = () => void;
|
|
56
68
|
export declare class Signal<Value> extends Reactive<Value> {
|
|
57
69
|
constructor(value: Value);
|
|
58
70
|
/**
|
|
59
|
-
*
|
|
71
|
+
* @inheritdoc
|
|
60
72
|
*/
|
|
61
73
|
get(): Value;
|
|
62
74
|
/**
|
|
@@ -68,6 +80,9 @@ export declare class Signal<Value> extends Reactive<Value> {
|
|
|
68
80
|
*/
|
|
69
81
|
update(callback: (value: Value) => Value): void;
|
|
70
82
|
}
|
|
83
|
+
/**
|
|
84
|
+
* Create a reactive value
|
|
85
|
+
*/
|
|
71
86
|
export declare function signal<Value>(value: Value): Signal<Value>;
|
|
72
87
|
/**
|
|
73
88
|
* Is the value a computed signal?
|
|
@@ -82,6 +97,46 @@ export declare function isReactive(value: unknown): value is Reactive<unknown>;
|
|
|
82
97
|
* Is the value a signal?
|
|
83
98
|
*/
|
|
84
99
|
export declare function isSignal(value: unknown): value is Signal<unknown>;
|
|
100
|
+
export declare class ReactiveArray<Item> extends Reactive<Item[]> {
|
|
101
|
+
#private;
|
|
102
|
+
/**
|
|
103
|
+
* The length of the array
|
|
104
|
+
*/
|
|
105
|
+
get length(): number;
|
|
106
|
+
/**
|
|
107
|
+
* Set the length of the array
|
|
108
|
+
*/
|
|
109
|
+
set length(value: number);
|
|
110
|
+
constructor(value: Item[]);
|
|
111
|
+
/**
|
|
112
|
+
* @inheritdoc
|
|
113
|
+
*/
|
|
114
|
+
get(): Item[];
|
|
115
|
+
/**
|
|
116
|
+
* @inheritdoc
|
|
117
|
+
*/
|
|
118
|
+
peek(): Item[];
|
|
119
|
+
/**
|
|
120
|
+
* Get the length of the array _(without reactivity)_
|
|
121
|
+
*/
|
|
122
|
+
peek(length: true): number;
|
|
123
|
+
/**
|
|
124
|
+
* Set the value
|
|
125
|
+
*/
|
|
126
|
+
set(value: Item[]): void;
|
|
127
|
+
/**
|
|
128
|
+
* Set the value at an index
|
|
129
|
+
*/
|
|
130
|
+
set(index: number, value: Item): void;
|
|
131
|
+
/**
|
|
132
|
+
* Set the length of the array
|
|
133
|
+
*/
|
|
134
|
+
set(property: "length", value: number): void;
|
|
135
|
+
}
|
|
136
|
+
/**
|
|
137
|
+
* Create a reactive array
|
|
138
|
+
*/
|
|
139
|
+
export declare function array<Item>(value: Item[]): ReactiveArray<Item>;
|
|
85
140
|
/**
|
|
86
141
|
* Start batching effects _(use `stopBatch` to flush and run batched effects)_
|
|
87
142
|
*/
|
package/types/index.d.ts
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
|
+
export { array, type ReactiveArray } from './array';
|
|
1
2
|
export { startBatch, stopBatch } from './batch';
|
|
2
3
|
export { computed, type Computed } from './computed';
|
|
3
4
|
export { effect, type Effect } from './effect';
|
|
4
5
|
export { isComputed, isEffect, isReactive, isSignal } from './is';
|
|
6
|
+
export type { Reactive } from './reactive';
|
|
5
7
|
export { signal, type Signal } from './signal';
|
package/types/is.d.cts
CHANGED
|
@@ -10,13 +10,26 @@ declare class Computed<Value> extends Reactive<Value> {
|
|
|
10
10
|
private readonly effect;
|
|
11
11
|
constructor(callback: () => Value);
|
|
12
12
|
/**
|
|
13
|
-
*
|
|
13
|
+
* @inheritdoc
|
|
14
14
|
*/
|
|
15
15
|
get(): Value;
|
|
16
16
|
}
|
|
17
|
+
declare class Subscription<Value> {
|
|
18
|
+
state: ReactiveState<Value>;
|
|
19
|
+
callback: GenericCallback;
|
|
20
|
+
constructor(state: ReactiveState<Value>, callback: GenericCallback);
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Unsubscribe from changes
|
|
24
|
+
*/
|
|
25
|
+
export type Unsubscribe = () => void;
|
|
17
26
|
declare abstract class Reactive<Value> {
|
|
18
27
|
protected readonly state: ReactiveState<Value>;
|
|
19
28
|
constructor(name: string, value: Value);
|
|
29
|
+
/**
|
|
30
|
+
* Get the value
|
|
31
|
+
*/
|
|
32
|
+
abstract get(): Value;
|
|
20
33
|
/**
|
|
21
34
|
* Get the value _(without reactivity)_
|
|
22
35
|
*/
|
|
@@ -25,6 +38,14 @@ declare abstract class Reactive<Value> {
|
|
|
25
38
|
* Subscribe to changes
|
|
26
39
|
*/
|
|
27
40
|
subscribe(callback: (value: Value) => void): Unsubscribe;
|
|
41
|
+
/**
|
|
42
|
+
* JSON representation of the value
|
|
43
|
+
*/
|
|
44
|
+
toJSON(): Value;
|
|
45
|
+
/**
|
|
46
|
+
* String representation of the value
|
|
47
|
+
*/
|
|
48
|
+
toString(): string;
|
|
28
49
|
/**
|
|
29
50
|
* Unsubscribe from changes
|
|
30
51
|
*/
|
|
@@ -36,19 +57,10 @@ export type ReactiveState<Value> = {
|
|
|
36
57
|
subscriptions: Map<(value: Value) => void, Subscription<Value>>;
|
|
37
58
|
value: Value;
|
|
38
59
|
};
|
|
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
60
|
declare class Signal<Value> extends Reactive<Value> {
|
|
49
61
|
constructor(value: Value);
|
|
50
62
|
/**
|
|
51
|
-
*
|
|
63
|
+
* @inheritdoc
|
|
52
64
|
*/
|
|
53
65
|
get(): Value;
|
|
54
66
|
/**
|
package/types/reactive.d.cts
CHANGED
|
@@ -10,13 +10,26 @@ declare class Computed<Value> extends Reactive<Value> {
|
|
|
10
10
|
private readonly effect;
|
|
11
11
|
constructor(callback: () => Value);
|
|
12
12
|
/**
|
|
13
|
-
*
|
|
13
|
+
* @inheritdoc
|
|
14
14
|
*/
|
|
15
15
|
get(): Value;
|
|
16
16
|
}
|
|
17
|
+
declare class Subscription<Value> {
|
|
18
|
+
state: ReactiveState<Value>;
|
|
19
|
+
callback: GenericCallback;
|
|
20
|
+
constructor(state: ReactiveState<Value>, callback: GenericCallback);
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Unsubscribe from changes
|
|
24
|
+
*/
|
|
25
|
+
export type Unsubscribe = () => void;
|
|
17
26
|
export declare abstract class Reactive<Value> {
|
|
18
27
|
protected readonly state: ReactiveState<Value>;
|
|
19
28
|
constructor(name: string, value: Value);
|
|
29
|
+
/**
|
|
30
|
+
* Get the value
|
|
31
|
+
*/
|
|
32
|
+
abstract get(): Value;
|
|
20
33
|
/**
|
|
21
34
|
* Get the value _(without reactivity)_
|
|
22
35
|
*/
|
|
@@ -25,6 +38,14 @@ export declare abstract class Reactive<Value> {
|
|
|
25
38
|
* Subscribe to changes
|
|
26
39
|
*/
|
|
27
40
|
subscribe(callback: (value: Value) => void): Unsubscribe;
|
|
41
|
+
/**
|
|
42
|
+
* JSON representation of the value
|
|
43
|
+
*/
|
|
44
|
+
toJSON(): Value;
|
|
45
|
+
/**
|
|
46
|
+
* String representation of the value
|
|
47
|
+
*/
|
|
48
|
+
toString(): string;
|
|
28
49
|
/**
|
|
29
50
|
* Unsubscribe from changes
|
|
30
51
|
*/
|
|
@@ -36,14 +57,5 @@ export type ReactiveState<Value> = {
|
|
|
36
57
|
subscriptions: Map<(value: Value) => void, Subscription<Value>>;
|
|
37
58
|
value: Value;
|
|
38
59
|
};
|
|
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
60
|
|
|
49
61
|
export {};
|
package/types/reactive.d.ts
CHANGED
|
@@ -4,6 +4,10 @@ import { type Subscription, type Unsubscribe } from './subscription';
|
|
|
4
4
|
export declare abstract class Reactive<Value> {
|
|
5
5
|
protected readonly state: ReactiveState<Value>;
|
|
6
6
|
constructor(name: string, value: Value);
|
|
7
|
+
/**
|
|
8
|
+
* Get the value
|
|
9
|
+
*/
|
|
10
|
+
abstract get(): Value;
|
|
7
11
|
/**
|
|
8
12
|
* Get the value _(without reactivity)_
|
|
9
13
|
*/
|
|
@@ -12,6 +16,14 @@ export declare abstract class Reactive<Value> {
|
|
|
12
16
|
* Subscribe to changes
|
|
13
17
|
*/
|
|
14
18
|
subscribe(callback: (value: Value) => void): Unsubscribe;
|
|
19
|
+
/**
|
|
20
|
+
* JSON representation of the value
|
|
21
|
+
*/
|
|
22
|
+
toJSON(): Value;
|
|
23
|
+
/**
|
|
24
|
+
* String representation of the value
|
|
25
|
+
*/
|
|
26
|
+
toString(): string;
|
|
15
27
|
/**
|
|
16
28
|
* Unsubscribe from changes
|
|
17
29
|
*/
|
package/types/signal.d.cts
CHANGED
|
@@ -10,13 +10,26 @@ declare class Computed<Value> extends Reactive<Value> {
|
|
|
10
10
|
private readonly effect;
|
|
11
11
|
constructor(callback: () => Value);
|
|
12
12
|
/**
|
|
13
|
-
*
|
|
13
|
+
* @inheritdoc
|
|
14
14
|
*/
|
|
15
15
|
get(): Value;
|
|
16
16
|
}
|
|
17
|
+
declare class Subscription<Value> {
|
|
18
|
+
state: ReactiveState<Value>;
|
|
19
|
+
callback: GenericCallback;
|
|
20
|
+
constructor(state: ReactiveState<Value>, callback: GenericCallback);
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Unsubscribe from changes
|
|
24
|
+
*/
|
|
25
|
+
export type Unsubscribe = () => void;
|
|
17
26
|
declare abstract class Reactive<Value> {
|
|
18
27
|
protected readonly state: ReactiveState<Value>;
|
|
19
28
|
constructor(name: string, value: Value);
|
|
29
|
+
/**
|
|
30
|
+
* Get the value
|
|
31
|
+
*/
|
|
32
|
+
abstract get(): Value;
|
|
20
33
|
/**
|
|
21
34
|
* Get the value _(without reactivity)_
|
|
22
35
|
*/
|
|
@@ -25,6 +38,14 @@ declare abstract class Reactive<Value> {
|
|
|
25
38
|
* Subscribe to changes
|
|
26
39
|
*/
|
|
27
40
|
subscribe(callback: (value: Value) => void): Unsubscribe;
|
|
41
|
+
/**
|
|
42
|
+
* JSON representation of the value
|
|
43
|
+
*/
|
|
44
|
+
toJSON(): Value;
|
|
45
|
+
/**
|
|
46
|
+
* String representation of the value
|
|
47
|
+
*/
|
|
48
|
+
toString(): string;
|
|
28
49
|
/**
|
|
29
50
|
* Unsubscribe from changes
|
|
30
51
|
*/
|
|
@@ -36,19 +57,10 @@ export type ReactiveState<Value> = {
|
|
|
36
57
|
subscriptions: Map<(value: Value) => void, Subscription<Value>>;
|
|
37
58
|
value: Value;
|
|
38
59
|
};
|
|
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
60
|
export declare class Signal<Value> extends Reactive<Value> {
|
|
49
61
|
constructor(value: Value);
|
|
50
62
|
/**
|
|
51
|
-
*
|
|
63
|
+
* @inheritdoc
|
|
52
64
|
*/
|
|
53
65
|
get(): Value;
|
|
54
66
|
/**
|
|
@@ -60,6 +72,9 @@ export declare class Signal<Value> extends Reactive<Value> {
|
|
|
60
72
|
*/
|
|
61
73
|
update(callback: (value: Value) => Value): void;
|
|
62
74
|
}
|
|
75
|
+
/**
|
|
76
|
+
* Create a reactive value
|
|
77
|
+
*/
|
|
63
78
|
export declare function signal<Value>(value: Value): Signal<Value>;
|
|
64
79
|
|
|
65
80
|
export {};
|
package/types/signal.d.ts
CHANGED
|
@@ -2,7 +2,7 @@ import { Reactive } from './reactive';
|
|
|
2
2
|
export declare class Signal<Value> extends Reactive<Value> {
|
|
3
3
|
constructor(value: Value);
|
|
4
4
|
/**
|
|
5
|
-
*
|
|
5
|
+
* @inheritdoc
|
|
6
6
|
*/
|
|
7
7
|
get(): Value;
|
|
8
8
|
/**
|
|
@@ -14,4 +14,7 @@ export declare class Signal<Value> extends Reactive<Value> {
|
|
|
14
14
|
*/
|
|
15
15
|
update(callback: (value: Value) => Value): void;
|
|
16
16
|
}
|
|
17
|
+
/**
|
|
18
|
+
* Create a reactive value
|
|
19
|
+
*/
|
|
17
20
|
export declare function signal<Value>(value: Value): Signal<Value>;
|
package/types/subscription.d.cts
CHANGED
|
@@ -10,13 +10,29 @@ declare class Computed<Value> extends Reactive<Value> {
|
|
|
10
10
|
private readonly effect;
|
|
11
11
|
constructor(callback: () => Value);
|
|
12
12
|
/**
|
|
13
|
-
*
|
|
13
|
+
* @inheritdoc
|
|
14
14
|
*/
|
|
15
15
|
get(): Value;
|
|
16
16
|
}
|
|
17
|
+
export declare class Subscription<Value> {
|
|
18
|
+
state: ReactiveState<Value>;
|
|
19
|
+
callback: GenericCallback;
|
|
20
|
+
constructor(state: ReactiveState<Value>, callback: GenericCallback);
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Unsubscribe from changes
|
|
24
|
+
*/
|
|
25
|
+
export type Unsubscribe = () => void;
|
|
26
|
+
export declare function noop(): void;
|
|
27
|
+
export declare function subscribe<Value>(state: ReactiveState<Value>, callback: (value: Value) => void): Unsubscribe;
|
|
28
|
+
export declare function unsubscribe<Value>(state: ReactiveState<Value>, callback: (value: Value) => void): void;
|
|
17
29
|
declare abstract class Reactive<Value> {
|
|
18
30
|
protected readonly state: ReactiveState<Value>;
|
|
19
31
|
constructor(name: string, value: Value);
|
|
32
|
+
/**
|
|
33
|
+
* Get the value
|
|
34
|
+
*/
|
|
35
|
+
abstract get(): Value;
|
|
20
36
|
/**
|
|
21
37
|
* Get the value _(without reactivity)_
|
|
22
38
|
*/
|
|
@@ -25,6 +41,14 @@ declare abstract class Reactive<Value> {
|
|
|
25
41
|
* Subscribe to changes
|
|
26
42
|
*/
|
|
27
43
|
subscribe(callback: (value: Value) => void): Unsubscribe;
|
|
44
|
+
/**
|
|
45
|
+
* JSON representation of the value
|
|
46
|
+
*/
|
|
47
|
+
toJSON(): Value;
|
|
48
|
+
/**
|
|
49
|
+
* String representation of the value
|
|
50
|
+
*/
|
|
51
|
+
toString(): string;
|
|
28
52
|
/**
|
|
29
53
|
* Unsubscribe from changes
|
|
30
54
|
*/
|
|
@@ -36,17 +60,5 @@ export type ReactiveState<Value> = {
|
|
|
36
60
|
subscriptions: Map<(value: Value) => void, Subscription<Value>>;
|
|
37
61
|
value: Value;
|
|
38
62
|
};
|
|
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
63
|
|
|
52
64
|
export {};
|
|
@@ -0,0 +1,64 @@
|
|
|
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
|
+
* @inheritdoc
|
|
14
|
+
*/
|
|
15
|
+
get(): Value;
|
|
16
|
+
}
|
|
17
|
+
declare class Subscription<Value> {
|
|
18
|
+
state: ReactiveState<Value>;
|
|
19
|
+
callback: GenericCallback;
|
|
20
|
+
constructor(state: ReactiveState<Value>, callback: GenericCallback);
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Unsubscribe from changes
|
|
24
|
+
*/
|
|
25
|
+
export type Unsubscribe = () => void;
|
|
26
|
+
declare abstract class Reactive<Value> {
|
|
27
|
+
protected readonly state: ReactiveState<Value>;
|
|
28
|
+
constructor(name: string, value: Value);
|
|
29
|
+
/**
|
|
30
|
+
* Get the value
|
|
31
|
+
*/
|
|
32
|
+
abstract get(): Value;
|
|
33
|
+
/**
|
|
34
|
+
* Get the value _(without reactivity)_
|
|
35
|
+
*/
|
|
36
|
+
peek(): Value;
|
|
37
|
+
/**
|
|
38
|
+
* Subscribe to changes
|
|
39
|
+
*/
|
|
40
|
+
subscribe(callback: (value: Value) => void): Unsubscribe;
|
|
41
|
+
/**
|
|
42
|
+
* JSON representation of the value
|
|
43
|
+
*/
|
|
44
|
+
toJSON(): Value;
|
|
45
|
+
/**
|
|
46
|
+
* String representation of the value
|
|
47
|
+
*/
|
|
48
|
+
toString(): string;
|
|
49
|
+
/**
|
|
50
|
+
* Unsubscribe from changes
|
|
51
|
+
*/
|
|
52
|
+
unsubscribe(callback: (value: Value) => void): void;
|
|
53
|
+
}
|
|
54
|
+
export type ReactiveState<Value> = {
|
|
55
|
+
computeds: Set<Computed<unknown>>;
|
|
56
|
+
effects: Set<Effect>;
|
|
57
|
+
subscriptions: Map<(value: Value) => void, Subscription<Value>>;
|
|
58
|
+
value: Value;
|
|
59
|
+
};
|
|
60
|
+
export declare function emitValue<Value>(state: ReactiveState<Value>): void;
|
|
61
|
+
export declare function getValue<Value>(state: ReactiveState<Value>): Value;
|
|
62
|
+
export declare function setValue<Value>(state: ReactiveState<Value>, value: Value): void;
|
|
63
|
+
|
|
64
|
+
export {};
|
package/types/value.d.ts
ADDED
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import type { ReactiveState } from './reactive';
|
|
2
|
+
export declare function emitValue<Value>(state: ReactiveState<Value>): void;
|
|
3
|
+
export declare function getValue<Value>(state: ReactiveState<Value>): Value;
|
|
4
|
+
export declare function setValue<Value>(state: ReactiveState<Value>, value: Value): void;
|