@oscarpalmer/mora 0.18.0 → 0.18.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/dist/helpers/is.cjs +7 -1
- package/dist/helpers/is.js +8 -2
- package/dist/helpers/proxy.cjs +43 -0
- package/dist/helpers/proxy.js +43 -0
- package/dist/helpers/value.cjs +22 -26
- package/dist/helpers/value.js +22 -26
- package/dist/index.cjs +2 -0
- package/dist/index.js +3 -1
- package/dist/mora.full.js +127 -59
- package/dist/node_modules/@oscarpalmer/atoms/dist/internal/is.cjs +17 -0
- package/dist/node_modules/@oscarpalmer/atoms/dist/internal/is.js +17 -0
- package/dist/value/array.cjs +15 -20
- package/dist/value/array.js +16 -21
- package/dist/value/computed.cjs +5 -5
- package/dist/value/computed.js +5 -5
- package/dist/value/reactive.cjs +5 -1
- package/dist/value/reactive.js +5 -1
- package/dist/value/signal.cjs +5 -5
- package/dist/value/signal.js +6 -6
- package/dist/value/store.cjs +36 -0
- package/dist/value/store.js +36 -0
- package/package.json +1 -1
- package/src/helpers/is.ts +1 -1
- package/src/helpers/proxy.ts +0 -1
- package/types/batch.d.cts +14 -7
- package/types/helpers/is.d.cts +66 -10
- package/types/helpers/is.d.ts +4 -0
- package/types/helpers/proxy.d.cts +89 -0
- package/types/helpers/proxy.d.ts +5 -0
- package/types/helpers/value.d.cts +17 -11
- package/types/helpers/value.d.ts +3 -4
- package/types/index.d.cts +71 -13
- package/types/index.d.ts +1 -0
- package/types/subscription.d.cts +16 -9
- package/types/subscription.d.ts +4 -4
- package/types/value/array.d.cts +17 -10
- package/types/value/array.d.ts +4 -4
- package/types/value/computed.d.cts +16 -9
- package/types/value/computed.d.ts +4 -4
- package/types/value/reactive.d.cts +14 -7
- package/types/value/reactive.d.ts +11 -4
- package/types/value/signal.d.cts +16 -9
- package/types/value/signal.d.ts +3 -3
- package/types/value/store.d.cts +119 -0
- package/types/value/store.d.ts +45 -0
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
// Generated by dts-bundle-generator v9.5.1
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* A generic array or object
|
|
5
|
+
*/
|
|
6
|
+
export type ArrayOrPlainObject = unknown[] | Record<PropertyKey, unknown>;
|
|
7
|
+
export type GenericCallback = (...args: any[]) => any;
|
|
8
|
+
declare class Effect {
|
|
9
|
+
private readonly $mora;
|
|
10
|
+
private readonly state;
|
|
11
|
+
constructor(callback: GenericCallback);
|
|
12
|
+
}
|
|
13
|
+
declare class Computed<Value> extends Reactive<Value> {
|
|
14
|
+
private readonly effect;
|
|
15
|
+
constructor(callback: () => Value, options?: ReactiveOptions<Value>);
|
|
16
|
+
/**
|
|
17
|
+
* @inheritdoc
|
|
18
|
+
*/
|
|
19
|
+
get(): Value;
|
|
20
|
+
}
|
|
21
|
+
declare abstract class Reactive<Value, Equal = Value> {
|
|
22
|
+
protected readonly state: ReactiveState<Value, Equal>;
|
|
23
|
+
constructor(name: string, value: Value, options?: ReactiveOptions<Equal>);
|
|
24
|
+
/**
|
|
25
|
+
* Get the value
|
|
26
|
+
*/
|
|
27
|
+
abstract get(): Value;
|
|
28
|
+
/**
|
|
29
|
+
* Get the value _(without reactivity)_
|
|
30
|
+
*/
|
|
31
|
+
peek(): Value;
|
|
32
|
+
/**
|
|
33
|
+
* Subscribe to changes
|
|
34
|
+
*/
|
|
35
|
+
subscribe(callback: (value: Value) => void): Unsubscribe;
|
|
36
|
+
/**
|
|
37
|
+
* JSON representation of the value
|
|
38
|
+
*/
|
|
39
|
+
toJSON(): Value;
|
|
40
|
+
/**
|
|
41
|
+
* String representation of the value
|
|
42
|
+
*/
|
|
43
|
+
toString(): string;
|
|
44
|
+
/**
|
|
45
|
+
* Unsubscribe from changes
|
|
46
|
+
*/
|
|
47
|
+
unsubscribe(callback: (value: Value) => void): void;
|
|
48
|
+
}
|
|
49
|
+
export type ReactiveOptions<Value> = {
|
|
50
|
+
/**
|
|
51
|
+
* Method to compare values for equality
|
|
52
|
+
*/
|
|
53
|
+
equal?: (first: Value, second: Value) => boolean;
|
|
54
|
+
};
|
|
55
|
+
export type ReactiveState<Value, Equal> = {
|
|
56
|
+
computeds: Set<Computed<unknown>>;
|
|
57
|
+
effects: Set<Effect>;
|
|
58
|
+
equal: (first: Equal, second: Equal) => boolean;
|
|
59
|
+
subscriptions: Map<(value: Value) => void, Subscription<Value>>;
|
|
60
|
+
value: Value;
|
|
61
|
+
};
|
|
62
|
+
declare class Subscription<Value> {
|
|
63
|
+
state: ReactiveState<Value, never>;
|
|
64
|
+
callback: GenericCallback;
|
|
65
|
+
constructor(state: ReactiveState<Value, never>, callback: GenericCallback);
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* Unsubscribe from changes
|
|
69
|
+
*/
|
|
70
|
+
export type Unsubscribe = () => void;
|
|
71
|
+
declare class Signal<Value> extends Reactive<Value> {
|
|
72
|
+
constructor(value: Value, options?: ReactiveOptions<Value>);
|
|
73
|
+
/**
|
|
74
|
+
* @inheritdoc
|
|
75
|
+
*/
|
|
76
|
+
get(): Value;
|
|
77
|
+
/**
|
|
78
|
+
* Set the value
|
|
79
|
+
*/
|
|
80
|
+
set(value: Value): void;
|
|
81
|
+
/**
|
|
82
|
+
* Update the value
|
|
83
|
+
*/
|
|
84
|
+
update(callback: (value: Value) => Value): void;
|
|
85
|
+
}
|
|
86
|
+
export declare function setProxyValue(proxy: ArrayOrPlainObject, value: ArrayOrPlainObject): void;
|
|
87
|
+
export declare function setValueInProxy<Value extends ArrayOrPlainObject, Equal>(target: Value, property: PropertyKey, value: unknown, state: ReactiveState<Value, Equal>, isArray: boolean, length?: Signal<number>): boolean;
|
|
88
|
+
|
|
89
|
+
export {};
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import type { ArrayOrPlainObject } from '@oscarpalmer/atoms/models';
|
|
2
|
+
import type { ReactiveState } from '../value/reactive';
|
|
3
|
+
import type { Signal } from '../value/signal';
|
|
4
|
+
export declare function setProxyValue(proxy: ArrayOrPlainObject, value: ArrayOrPlainObject): void;
|
|
5
|
+
export declare function setValueInProxy<Value extends ArrayOrPlainObject, Equal>(target: Value, property: PropertyKey, value: unknown, state: ReactiveState<Value, Equal>, isArray: boolean, length?: Signal<number>): boolean;
|
|
@@ -8,15 +8,15 @@ declare class Effect {
|
|
|
8
8
|
}
|
|
9
9
|
declare class Computed<Value> extends Reactive<Value> {
|
|
10
10
|
private readonly effect;
|
|
11
|
-
constructor(callback: () => Value);
|
|
11
|
+
constructor(callback: () => Value, options?: ReactiveOptions<Value>);
|
|
12
12
|
/**
|
|
13
13
|
* @inheritdoc
|
|
14
14
|
*/
|
|
15
15
|
get(): Value;
|
|
16
16
|
}
|
|
17
|
-
declare abstract class Reactive<Value> {
|
|
18
|
-
protected readonly state: ReactiveState<Value>;
|
|
19
|
-
constructor(name: string, value: Value);
|
|
17
|
+
declare abstract class Reactive<Value, Equal = Value> {
|
|
18
|
+
protected readonly state: ReactiveState<Value, Equal>;
|
|
19
|
+
constructor(name: string, value: Value, options?: ReactiveOptions<Equal>);
|
|
20
20
|
/**
|
|
21
21
|
* Get the value
|
|
22
22
|
*/
|
|
@@ -42,24 +42,30 @@ declare abstract class Reactive<Value> {
|
|
|
42
42
|
*/
|
|
43
43
|
unsubscribe(callback: (value: Value) => void): void;
|
|
44
44
|
}
|
|
45
|
-
export type
|
|
45
|
+
export type ReactiveOptions<Value> = {
|
|
46
|
+
/**
|
|
47
|
+
* Method to compare values for equality
|
|
48
|
+
*/
|
|
49
|
+
equal?: (first: Value, second: Value) => boolean;
|
|
50
|
+
};
|
|
51
|
+
export type ReactiveState<Value, Equal> = {
|
|
46
52
|
computeds: Set<Computed<unknown>>;
|
|
47
53
|
effects: Set<Effect>;
|
|
54
|
+
equal: (first: Equal, second: Equal) => boolean;
|
|
48
55
|
subscriptions: Map<(value: Value) => void, Subscription<Value>>;
|
|
49
56
|
value: Value;
|
|
50
57
|
};
|
|
51
58
|
declare class Subscription<Value> {
|
|
52
|
-
state: ReactiveState<Value>;
|
|
59
|
+
state: ReactiveState<Value, never>;
|
|
53
60
|
callback: GenericCallback;
|
|
54
|
-
constructor(state: ReactiveState<Value>, callback: GenericCallback);
|
|
61
|
+
constructor(state: ReactiveState<Value, never>, callback: GenericCallback);
|
|
55
62
|
}
|
|
56
63
|
/**
|
|
57
64
|
* Unsubscribe from changes
|
|
58
65
|
*/
|
|
59
66
|
export type Unsubscribe = () => void;
|
|
60
|
-
export declare function
|
|
61
|
-
export declare function
|
|
62
|
-
export declare function
|
|
63
|
-
export declare function getValue<Value>(state: ReactiveState<Value>): Value;
|
|
67
|
+
export declare function emitValue<Value>(state: ReactiveState<Value, never>): void;
|
|
68
|
+
export declare function equalArrays<Value>(state: ReactiveState<Value[], Value>, first: Value[], second: Value[]): boolean;
|
|
69
|
+
export declare function getValue<Value>(state: ReactiveState<Value, never>): Value;
|
|
64
70
|
|
|
65
71
|
export {};
|
package/types/helpers/value.d.ts
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import type { ReactiveState } from '../value/reactive';
|
|
2
|
-
export declare function
|
|
3
|
-
export declare function
|
|
4
|
-
export declare function
|
|
5
|
-
export declare function getValue<Value>(state: ReactiveState<Value>): Value;
|
|
2
|
+
export declare function emitValue<Value>(state: ReactiveState<Value, never>): void;
|
|
3
|
+
export declare function equalArrays<Value>(state: ReactiveState<Value[], Value>, first: Value[], second: Value[]): boolean;
|
|
4
|
+
export declare function getValue<Value>(state: ReactiveState<Value, never>): Value;
|
package/types/index.d.cts
CHANGED
|
@@ -1,6 +1,14 @@
|
|
|
1
1
|
// Generated by dts-bundle-generator v9.5.1
|
|
2
2
|
|
|
3
3
|
export type GenericCallback = (...args: any[]) => any;
|
|
4
|
+
/**
|
|
5
|
+
* A useful key type
|
|
6
|
+
*/
|
|
7
|
+
export type Key = number | string;
|
|
8
|
+
/**
|
|
9
|
+
* A generic object
|
|
10
|
+
*/
|
|
11
|
+
export type PlainObject = Record<PropertyKey, unknown>;
|
|
4
12
|
export declare class Effect {
|
|
5
13
|
private readonly $mora;
|
|
6
14
|
private readonly state;
|
|
@@ -12,7 +20,7 @@ export declare class Effect {
|
|
|
12
20
|
export declare function effect(callback: GenericCallback): Effect;
|
|
13
21
|
export declare class Computed<Value> extends Reactive<Value> {
|
|
14
22
|
private readonly effect;
|
|
15
|
-
constructor(callback: () => Value);
|
|
23
|
+
constructor(callback: () => Value, options?: ReactiveOptions<Value>);
|
|
16
24
|
/**
|
|
17
25
|
* @inheritdoc
|
|
18
26
|
*/
|
|
@@ -21,10 +29,10 @@ export declare class Computed<Value> extends Reactive<Value> {
|
|
|
21
29
|
/**
|
|
22
30
|
* Create a computed value
|
|
23
31
|
*/
|
|
24
|
-
export declare function computed<Value>(callback: () => Value): Computed<Value>;
|
|
25
|
-
export declare abstract class Reactive<Value> {
|
|
26
|
-
protected readonly state: ReactiveState<Value>;
|
|
27
|
-
constructor(name: string, value: Value);
|
|
32
|
+
export declare function computed<Value>(callback: () => Value, options?: ReactiveOptions<Value>): Computed<Value>;
|
|
33
|
+
export declare abstract class Reactive<Value, Equal = Value> {
|
|
34
|
+
protected readonly state: ReactiveState<Value, Equal>;
|
|
35
|
+
constructor(name: string, value: Value, options?: ReactiveOptions<Equal>);
|
|
28
36
|
/**
|
|
29
37
|
* Get the value
|
|
30
38
|
*/
|
|
@@ -50,16 +58,23 @@ export declare abstract class Reactive<Value> {
|
|
|
50
58
|
*/
|
|
51
59
|
unsubscribe(callback: (value: Value) => void): void;
|
|
52
60
|
}
|
|
53
|
-
export type
|
|
61
|
+
export type ReactiveOptions<Value> = {
|
|
62
|
+
/**
|
|
63
|
+
* Method to compare values for equality
|
|
64
|
+
*/
|
|
65
|
+
equal?: (first: Value, second: Value) => boolean;
|
|
66
|
+
};
|
|
67
|
+
export type ReactiveState<Value, Equal> = {
|
|
54
68
|
computeds: Set<Computed<unknown>>;
|
|
55
69
|
effects: Set<Effect>;
|
|
70
|
+
equal: (first: Equal, second: Equal) => boolean;
|
|
56
71
|
subscriptions: Map<(value: Value) => void, Subscription<Value>>;
|
|
57
72
|
value: Value;
|
|
58
73
|
};
|
|
59
74
|
declare class Subscription<Value> {
|
|
60
|
-
state: ReactiveState<Value>;
|
|
75
|
+
state: ReactiveState<Value, never>;
|
|
61
76
|
callback: GenericCallback;
|
|
62
|
-
constructor(state: ReactiveState<Value>, callback: GenericCallback);
|
|
77
|
+
constructor(state: ReactiveState<Value, never>, callback: GenericCallback);
|
|
63
78
|
}
|
|
64
79
|
/**
|
|
65
80
|
* Unsubscribe from changes
|
|
@@ -73,7 +88,7 @@ export declare function startBatch(): void;
|
|
|
73
88
|
* Stop batching effects and flush _(run)_ them
|
|
74
89
|
*/
|
|
75
90
|
export declare function stopBatch(): void;
|
|
76
|
-
export declare class ReactiveArray<Item> extends Reactive<Item[]> {
|
|
91
|
+
export declare class ReactiveArray<Item> extends Reactive<Item[], Item> {
|
|
77
92
|
#private;
|
|
78
93
|
/**
|
|
79
94
|
* The length of the array
|
|
@@ -83,7 +98,7 @@ export declare class ReactiveArray<Item> extends Reactive<Item[]> {
|
|
|
83
98
|
* Set the length of the array
|
|
84
99
|
*/
|
|
85
100
|
set length(value: number);
|
|
86
|
-
constructor(value: Item[]);
|
|
101
|
+
constructor(value: Item[], options?: ReactiveOptions<Item>);
|
|
87
102
|
/**
|
|
88
103
|
* Get an indexed item
|
|
89
104
|
*/
|
|
@@ -148,9 +163,9 @@ export declare class ReactiveArray<Item> extends Reactive<Item[]> {
|
|
|
148
163
|
/**
|
|
149
164
|
* Create a reactive array
|
|
150
165
|
*/
|
|
151
|
-
export declare function array<Item>(value: Item[]): ReactiveArray<Item>;
|
|
166
|
+
export declare function array<Item>(value: Item[], options?: ReactiveOptions<Item>): ReactiveArray<Item>;
|
|
152
167
|
export declare class Signal<Value> extends Reactive<Value> {
|
|
153
|
-
constructor(value: Value);
|
|
168
|
+
constructor(value: Value, options?: ReactiveOptions<Value>);
|
|
154
169
|
/**
|
|
155
170
|
* @inheritdoc
|
|
156
171
|
*/
|
|
@@ -167,7 +182,50 @@ export declare class Signal<Value> extends Reactive<Value> {
|
|
|
167
182
|
/**
|
|
168
183
|
* Create a reactive value
|
|
169
184
|
*/
|
|
170
|
-
export declare function signal<Value>(value: Value): Signal<Value>;
|
|
185
|
+
export declare function signal<Value>(value: Value, options?: ReactiveOptions<Value>): Signal<Value>;
|
|
186
|
+
export declare class Store<Value extends PlainObject> extends Reactive<Value, Value> {
|
|
187
|
+
constructor(value: Value, options?: ReactiveOptions<Value>);
|
|
188
|
+
/**
|
|
189
|
+
* @inheritdoc
|
|
190
|
+
*/
|
|
191
|
+
get(): Value;
|
|
192
|
+
/**
|
|
193
|
+
* Get a value by key _(without reactivity)_
|
|
194
|
+
*/
|
|
195
|
+
get(key: keyof Value): Value[keyof Value];
|
|
196
|
+
/**
|
|
197
|
+
* Get a value by key _(without reactivity)_
|
|
198
|
+
*/
|
|
199
|
+
get(key: Key): unknown;
|
|
200
|
+
/**
|
|
201
|
+
* Get the value _(without reactivity)_
|
|
202
|
+
*/
|
|
203
|
+
peek(): Value;
|
|
204
|
+
/**
|
|
205
|
+
* Get a value by key _(without reactivity)_
|
|
206
|
+
*/
|
|
207
|
+
peek(key: keyof Value): Value[keyof Value];
|
|
208
|
+
/**
|
|
209
|
+
* Get a value by key _(without reactivity)_
|
|
210
|
+
*/
|
|
211
|
+
peek(key: Key): unknown;
|
|
212
|
+
/**
|
|
213
|
+
* Set the value
|
|
214
|
+
*/
|
|
215
|
+
set(value?: Value): void;
|
|
216
|
+
/**
|
|
217
|
+
* Set a value by key
|
|
218
|
+
*/
|
|
219
|
+
set(key: keyof Value, value: Value[keyof Value]): void;
|
|
220
|
+
/**
|
|
221
|
+
* Set a value by key
|
|
222
|
+
*/
|
|
223
|
+
set(key: Key, value: unknown): void;
|
|
224
|
+
}
|
|
225
|
+
/**
|
|
226
|
+
* Create a reactive store
|
|
227
|
+
*/
|
|
228
|
+
export declare function store<Value extends PlainObject>(value: Value, options?: ReactiveOptions<Value>): Store<Value>;
|
|
171
229
|
/**
|
|
172
230
|
* Is the value a reactive array?
|
|
173
231
|
*/
|
package/types/index.d.ts
CHANGED
|
@@ -5,3 +5,4 @@ export { array, type ReactiveArray } from './value/array';
|
|
|
5
5
|
export { computed, type Computed } from './value/computed';
|
|
6
6
|
export type { Reactive } from './value/reactive';
|
|
7
7
|
export { signal, type Signal } from './value/signal';
|
|
8
|
+
export { store, type Store } from './value/store';
|
package/types/subscription.d.cts
CHANGED
|
@@ -8,15 +8,15 @@ declare class Effect {
|
|
|
8
8
|
}
|
|
9
9
|
declare class Computed<Value> extends Reactive<Value> {
|
|
10
10
|
private readonly effect;
|
|
11
|
-
constructor(callback: () => Value);
|
|
11
|
+
constructor(callback: () => Value, options?: ReactiveOptions<Value>);
|
|
12
12
|
/**
|
|
13
13
|
* @inheritdoc
|
|
14
14
|
*/
|
|
15
15
|
get(): Value;
|
|
16
16
|
}
|
|
17
|
-
declare abstract class Reactive<Value> {
|
|
18
|
-
protected readonly state: ReactiveState<Value>;
|
|
19
|
-
constructor(name: string, value: Value);
|
|
17
|
+
declare abstract class Reactive<Value, Equal = Value> {
|
|
18
|
+
protected readonly state: ReactiveState<Value, Equal>;
|
|
19
|
+
constructor(name: string, value: Value, options?: ReactiveOptions<Equal>);
|
|
20
20
|
/**
|
|
21
21
|
* Get the value
|
|
22
22
|
*/
|
|
@@ -42,23 +42,30 @@ declare abstract class Reactive<Value> {
|
|
|
42
42
|
*/
|
|
43
43
|
unsubscribe(callback: (value: Value) => void): void;
|
|
44
44
|
}
|
|
45
|
-
export type
|
|
45
|
+
export type ReactiveOptions<Value> = {
|
|
46
|
+
/**
|
|
47
|
+
* Method to compare values for equality
|
|
48
|
+
*/
|
|
49
|
+
equal?: (first: Value, second: Value) => boolean;
|
|
50
|
+
};
|
|
51
|
+
export type ReactiveState<Value, Equal> = {
|
|
46
52
|
computeds: Set<Computed<unknown>>;
|
|
47
53
|
effects: Set<Effect>;
|
|
54
|
+
equal: (first: Equal, second: Equal) => boolean;
|
|
48
55
|
subscriptions: Map<(value: Value) => void, Subscription<Value>>;
|
|
49
56
|
value: Value;
|
|
50
57
|
};
|
|
51
58
|
export declare class Subscription<Value> {
|
|
52
|
-
state: ReactiveState<Value>;
|
|
59
|
+
state: ReactiveState<Value, never>;
|
|
53
60
|
callback: GenericCallback;
|
|
54
|
-
constructor(state: ReactiveState<Value>, callback: GenericCallback);
|
|
61
|
+
constructor(state: ReactiveState<Value, never>, callback: GenericCallback);
|
|
55
62
|
}
|
|
56
63
|
/**
|
|
57
64
|
* Unsubscribe from changes
|
|
58
65
|
*/
|
|
59
66
|
export type Unsubscribe = () => void;
|
|
60
67
|
export declare function noop(): void;
|
|
61
|
-
export declare function subscribe<Value>(state: ReactiveState<Value>, callback: (value: Value) => void): Unsubscribe;
|
|
62
|
-
export declare function unsubscribe<Value>(state: ReactiveState<Value>, callback: (value: Value) => void): void;
|
|
68
|
+
export declare function subscribe<Value>(state: ReactiveState<Value, never>, callback: (value: Value) => void): Unsubscribe;
|
|
69
|
+
export declare function unsubscribe<Value>(state: ReactiveState<Value, never>, callback: (value: Value) => void): void;
|
|
63
70
|
|
|
64
71
|
export {};
|
package/types/subscription.d.ts
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
import type { GenericCallback } from '@oscarpalmer/atoms/models';
|
|
2
2
|
import type { ReactiveState } from './value/reactive';
|
|
3
3
|
export declare class Subscription<Value> {
|
|
4
|
-
state: ReactiveState<Value>;
|
|
4
|
+
state: ReactiveState<Value, never>;
|
|
5
5
|
callback: GenericCallback;
|
|
6
|
-
constructor(state: ReactiveState<Value>, callback: GenericCallback);
|
|
6
|
+
constructor(state: ReactiveState<Value, never>, callback: GenericCallback);
|
|
7
7
|
}
|
|
8
8
|
/**
|
|
9
9
|
* Unsubscribe from changes
|
|
10
10
|
*/
|
|
11
11
|
export type Unsubscribe = () => void;
|
|
12
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;
|
|
13
|
+
export declare function subscribe<Value>(state: ReactiveState<Value, never>, callback: (value: Value) => void): Unsubscribe;
|
|
14
|
+
export declare function unsubscribe<Value>(state: ReactiveState<Value, never>, callback: (value: Value) => void): void;
|
package/types/value/array.d.cts
CHANGED
|
@@ -8,15 +8,15 @@ declare class Effect {
|
|
|
8
8
|
}
|
|
9
9
|
declare class Computed<Value> extends Reactive<Value> {
|
|
10
10
|
private readonly effect;
|
|
11
|
-
constructor(callback: () => Value);
|
|
11
|
+
constructor(callback: () => Value, options?: ReactiveOptions<Value>);
|
|
12
12
|
/**
|
|
13
13
|
* @inheritdoc
|
|
14
14
|
*/
|
|
15
15
|
get(): Value;
|
|
16
16
|
}
|
|
17
|
-
declare abstract class Reactive<Value> {
|
|
18
|
-
protected readonly state: ReactiveState<Value>;
|
|
19
|
-
constructor(name: string, value: Value);
|
|
17
|
+
declare abstract class Reactive<Value, Equal = Value> {
|
|
18
|
+
protected readonly state: ReactiveState<Value, Equal>;
|
|
19
|
+
constructor(name: string, value: Value, options?: ReactiveOptions<Equal>);
|
|
20
20
|
/**
|
|
21
21
|
* Get the value
|
|
22
22
|
*/
|
|
@@ -42,22 +42,29 @@ declare abstract class Reactive<Value> {
|
|
|
42
42
|
*/
|
|
43
43
|
unsubscribe(callback: (value: Value) => void): void;
|
|
44
44
|
}
|
|
45
|
-
export type
|
|
45
|
+
export type ReactiveOptions<Value> = {
|
|
46
|
+
/**
|
|
47
|
+
* Method to compare values for equality
|
|
48
|
+
*/
|
|
49
|
+
equal?: (first: Value, second: Value) => boolean;
|
|
50
|
+
};
|
|
51
|
+
export type ReactiveState<Value, Equal> = {
|
|
46
52
|
computeds: Set<Computed<unknown>>;
|
|
47
53
|
effects: Set<Effect>;
|
|
54
|
+
equal: (first: Equal, second: Equal) => boolean;
|
|
48
55
|
subscriptions: Map<(value: Value) => void, Subscription<Value>>;
|
|
49
56
|
value: Value;
|
|
50
57
|
};
|
|
51
58
|
declare class Subscription<Value> {
|
|
52
|
-
state: ReactiveState<Value>;
|
|
59
|
+
state: ReactiveState<Value, never>;
|
|
53
60
|
callback: GenericCallback;
|
|
54
|
-
constructor(state: ReactiveState<Value>, callback: GenericCallback);
|
|
61
|
+
constructor(state: ReactiveState<Value, never>, callback: GenericCallback);
|
|
55
62
|
}
|
|
56
63
|
/**
|
|
57
64
|
* Unsubscribe from changes
|
|
58
65
|
*/
|
|
59
66
|
export type Unsubscribe = () => void;
|
|
60
|
-
export declare class ReactiveArray<Item> extends Reactive<Item[]> {
|
|
67
|
+
export declare class ReactiveArray<Item> extends Reactive<Item[], Item> {
|
|
61
68
|
#private;
|
|
62
69
|
/**
|
|
63
70
|
* The length of the array
|
|
@@ -67,7 +74,7 @@ export declare class ReactiveArray<Item> extends Reactive<Item[]> {
|
|
|
67
74
|
* Set the length of the array
|
|
68
75
|
*/
|
|
69
76
|
set length(value: number);
|
|
70
|
-
constructor(value: Item[]);
|
|
77
|
+
constructor(value: Item[], options?: ReactiveOptions<Item>);
|
|
71
78
|
/**
|
|
72
79
|
* Get an indexed item
|
|
73
80
|
*/
|
|
@@ -132,6 +139,6 @@ export declare class ReactiveArray<Item> extends Reactive<Item[]> {
|
|
|
132
139
|
/**
|
|
133
140
|
* Create a reactive array
|
|
134
141
|
*/
|
|
135
|
-
export declare function array<Item>(value: Item[]): ReactiveArray<Item>;
|
|
142
|
+
export declare function array<Item>(value: Item[], options?: ReactiveOptions<Item>): ReactiveArray<Item>;
|
|
136
143
|
|
|
137
144
|
export {};
|
package/types/value/array.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { type Computed } from './computed';
|
|
2
|
-
import { Reactive } from './reactive';
|
|
3
|
-
export declare class ReactiveArray<Item> extends Reactive<Item[]> {
|
|
2
|
+
import { Reactive, type ReactiveOptions } from './reactive';
|
|
3
|
+
export declare class ReactiveArray<Item> extends Reactive<Item[], Item> {
|
|
4
4
|
#private;
|
|
5
5
|
/**
|
|
6
6
|
* The length of the array
|
|
@@ -10,7 +10,7 @@ export declare class ReactiveArray<Item> extends Reactive<Item[]> {
|
|
|
10
10
|
* Set the length of the array
|
|
11
11
|
*/
|
|
12
12
|
set length(value: number);
|
|
13
|
-
constructor(value: Item[]);
|
|
13
|
+
constructor(value: Item[], options?: ReactiveOptions<Item>);
|
|
14
14
|
/**
|
|
15
15
|
* Get an indexed item
|
|
16
16
|
*/
|
|
@@ -75,4 +75,4 @@ export declare class ReactiveArray<Item> extends Reactive<Item[]> {
|
|
|
75
75
|
/**
|
|
76
76
|
* Create a reactive array
|
|
77
77
|
*/
|
|
78
|
-
export declare function array<Item>(value: Item[]): ReactiveArray<Item>;
|
|
78
|
+
export declare function array<Item>(value: Item[], options?: ReactiveOptions<Item>): ReactiveArray<Item>;
|
|
@@ -12,12 +12,12 @@ export type ComputedEffect = {
|
|
|
12
12
|
};
|
|
13
13
|
export type InternalComputed = {
|
|
14
14
|
readonly effect: ComputedEffect;
|
|
15
|
-
readonly state: ReactiveState<unknown>;
|
|
15
|
+
readonly state: ReactiveState<unknown, unknown>;
|
|
16
16
|
};
|
|
17
17
|
export declare let activeComputed: Computed<unknown> | undefined;
|
|
18
18
|
export declare class Computed<Value> extends Reactive<Value> {
|
|
19
19
|
private readonly effect;
|
|
20
|
-
constructor(callback: () => Value);
|
|
20
|
+
constructor(callback: () => Value, options?: ReactiveOptions<Value>);
|
|
21
21
|
/**
|
|
22
22
|
* @inheritdoc
|
|
23
23
|
*/
|
|
@@ -26,10 +26,10 @@ export declare class Computed<Value> extends Reactive<Value> {
|
|
|
26
26
|
/**
|
|
27
27
|
* Create a computed value
|
|
28
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);
|
|
29
|
+
export declare function computed<Value>(callback: () => Value, options?: ReactiveOptions<Value>): Computed<Value>;
|
|
30
|
+
declare abstract class Reactive<Value, Equal = Value> {
|
|
31
|
+
protected readonly state: ReactiveState<Value, Equal>;
|
|
32
|
+
constructor(name: string, value: Value, options?: ReactiveOptions<Equal>);
|
|
33
33
|
/**
|
|
34
34
|
* Get the value
|
|
35
35
|
*/
|
|
@@ -55,16 +55,23 @@ declare abstract class Reactive<Value> {
|
|
|
55
55
|
*/
|
|
56
56
|
unsubscribe(callback: (value: Value) => void): void;
|
|
57
57
|
}
|
|
58
|
-
export type
|
|
58
|
+
export type ReactiveOptions<Value> = {
|
|
59
|
+
/**
|
|
60
|
+
* Method to compare values for equality
|
|
61
|
+
*/
|
|
62
|
+
equal?: (first: Value, second: Value) => boolean;
|
|
63
|
+
};
|
|
64
|
+
export type ReactiveState<Value, Equal> = {
|
|
59
65
|
computeds: Set<Computed<unknown>>;
|
|
60
66
|
effects: Set<Effect>;
|
|
67
|
+
equal: (first: Equal, second: Equal) => boolean;
|
|
61
68
|
subscriptions: Map<(value: Value) => void, Subscription<Value>>;
|
|
62
69
|
value: Value;
|
|
63
70
|
};
|
|
64
71
|
declare class Subscription<Value> {
|
|
65
|
-
state: ReactiveState<Value>;
|
|
72
|
+
state: ReactiveState<Value, never>;
|
|
66
73
|
callback: GenericCallback;
|
|
67
|
-
constructor(state: ReactiveState<Value>, callback: GenericCallback);
|
|
74
|
+
constructor(state: ReactiveState<Value, never>, callback: GenericCallback);
|
|
68
75
|
}
|
|
69
76
|
/**
|
|
70
77
|
* Unsubscribe from changes
|
|
@@ -1,17 +1,17 @@
|
|
|
1
1
|
import { type Effect } from '../effect';
|
|
2
|
-
import { Reactive, type ReactiveState } from './reactive';
|
|
2
|
+
import { Reactive, type ReactiveOptions, type ReactiveState } from './reactive';
|
|
3
3
|
export type ComputedEffect = {
|
|
4
4
|
dirty: boolean;
|
|
5
5
|
instance: Effect;
|
|
6
6
|
};
|
|
7
7
|
export type InternalComputed = {
|
|
8
8
|
readonly effect: ComputedEffect;
|
|
9
|
-
readonly state: ReactiveState<unknown>;
|
|
9
|
+
readonly state: ReactiveState<unknown, unknown>;
|
|
10
10
|
};
|
|
11
11
|
export declare let activeComputed: Computed<unknown> | undefined;
|
|
12
12
|
export declare class Computed<Value> extends Reactive<Value> {
|
|
13
13
|
private readonly effect;
|
|
14
|
-
constructor(callback: () => Value);
|
|
14
|
+
constructor(callback: () => Value, options?: ReactiveOptions<Value>);
|
|
15
15
|
/**
|
|
16
16
|
* @inheritdoc
|
|
17
17
|
*/
|
|
@@ -20,4 +20,4 @@ export declare class Computed<Value> extends Reactive<Value> {
|
|
|
20
20
|
/**
|
|
21
21
|
* Create a computed value
|
|
22
22
|
*/
|
|
23
|
-
export declare function computed<Value>(callback: () => Value): Computed<Value>;
|
|
23
|
+
export declare function computed<Value>(callback: () => Value, options?: ReactiveOptions<Value>): Computed<Value>;
|
|
@@ -8,15 +8,15 @@ declare class Effect {
|
|
|
8
8
|
}
|
|
9
9
|
declare class Computed<Value> extends Reactive<Value> {
|
|
10
10
|
private readonly effect;
|
|
11
|
-
constructor(callback: () => Value);
|
|
11
|
+
constructor(callback: () => Value, options?: ReactiveOptions<Value>);
|
|
12
12
|
/**
|
|
13
13
|
* @inheritdoc
|
|
14
14
|
*/
|
|
15
15
|
get(): Value;
|
|
16
16
|
}
|
|
17
|
-
export declare abstract class Reactive<Value> {
|
|
18
|
-
protected readonly state: ReactiveState<Value>;
|
|
19
|
-
constructor(name: string, value: Value);
|
|
17
|
+
export declare abstract class Reactive<Value, Equal = Value> {
|
|
18
|
+
protected readonly state: ReactiveState<Value, Equal>;
|
|
19
|
+
constructor(name: string, value: Value, options?: ReactiveOptions<Equal>);
|
|
20
20
|
/**
|
|
21
21
|
* Get the value
|
|
22
22
|
*/
|
|
@@ -42,16 +42,23 @@ export declare abstract class Reactive<Value> {
|
|
|
42
42
|
*/
|
|
43
43
|
unsubscribe(callback: (value: Value) => void): void;
|
|
44
44
|
}
|
|
45
|
-
export type
|
|
45
|
+
export type ReactiveOptions<Value> = {
|
|
46
|
+
/**
|
|
47
|
+
* Method to compare values for equality
|
|
48
|
+
*/
|
|
49
|
+
equal?: (first: Value, second: Value) => boolean;
|
|
50
|
+
};
|
|
51
|
+
export type ReactiveState<Value, Equal> = {
|
|
46
52
|
computeds: Set<Computed<unknown>>;
|
|
47
53
|
effects: Set<Effect>;
|
|
54
|
+
equal: (first: Equal, second: Equal) => boolean;
|
|
48
55
|
subscriptions: Map<(value: Value) => void, Subscription<Value>>;
|
|
49
56
|
value: Value;
|
|
50
57
|
};
|
|
51
58
|
declare class Subscription<Value> {
|
|
52
|
-
state: ReactiveState<Value>;
|
|
59
|
+
state: ReactiveState<Value, never>;
|
|
53
60
|
callback: GenericCallback;
|
|
54
|
-
constructor(state: ReactiveState<Value>, callback: GenericCallback);
|
|
61
|
+
constructor(state: ReactiveState<Value, never>, callback: GenericCallback);
|
|
55
62
|
}
|
|
56
63
|
/**
|
|
57
64
|
* Unsubscribe from changes
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import type { Effect } from '../effect';
|
|
2
2
|
import { type Subscription, type Unsubscribe } from '../subscription';
|
|
3
3
|
import type { Computed } from './computed';
|
|
4
|
-
export declare abstract class Reactive<Value> {
|
|
5
|
-
protected readonly state: ReactiveState<Value>;
|
|
6
|
-
constructor(name: string, value: Value);
|
|
4
|
+
export declare abstract class Reactive<Value, Equal = Value> {
|
|
5
|
+
protected readonly state: ReactiveState<Value, Equal>;
|
|
6
|
+
constructor(name: string, value: Value, options?: ReactiveOptions<Equal>);
|
|
7
7
|
/**
|
|
8
8
|
* Get the value
|
|
9
9
|
*/
|
|
@@ -29,9 +29,16 @@ export declare abstract class Reactive<Value> {
|
|
|
29
29
|
*/
|
|
30
30
|
unsubscribe(callback: (value: Value) => void): void;
|
|
31
31
|
}
|
|
32
|
-
export type
|
|
32
|
+
export type ReactiveOptions<Value> = {
|
|
33
|
+
/**
|
|
34
|
+
* Method to compare values for equality
|
|
35
|
+
*/
|
|
36
|
+
equal?: (first: Value, second: Value) => boolean;
|
|
37
|
+
};
|
|
38
|
+
export type ReactiveState<Value, Equal> = {
|
|
33
39
|
computeds: Set<Computed<unknown>>;
|
|
34
40
|
effects: Set<Effect>;
|
|
41
|
+
equal: (first: Equal, second: Equal) => boolean;
|
|
35
42
|
subscriptions: Map<(value: Value) => void, Subscription<Value>>;
|
|
36
43
|
value: Value;
|
|
37
44
|
};
|