@oscarpalmer/mora 0.15.0 → 0.17.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 +3 -3
- package/dist/batch.js +3 -3
- package/dist/helpers/value.cjs +44 -8
- package/dist/helpers/value.js +45 -9
- package/dist/mora.full.js +75 -64
- package/dist/value/array.cjs +15 -9
- package/dist/value/array.js +14 -8
- package/dist/value/computed.cjs +6 -6
- package/dist/value/computed.js +6 -6
- package/dist/value/reactive.cjs +5 -1
- package/dist/value/reactive.js +5 -1
- package/dist/value/signal.cjs +8 -5
- package/dist/value/signal.js +9 -6
- package/package.json +3 -3
- package/src/batch.ts +2 -2
- package/src/helpers/is.ts +1 -1
- package/src/helpers/value.ts +66 -14
- package/src/subscription.ts +3 -3
- package/src/value/array.ts +22 -12
- package/src/value/computed.ts +12 -9
- package/src/value/reactive.ts +17 -4
- package/src/value/signal.ts +14 -7
- package/types/batch.d.cts +15 -8
- package/types/batch.d.ts +1 -1
- package/types/helpers/is.d.cts +21 -10
- package/types/helpers/is.d.ts +1 -1
- package/types/helpers/value.d.cts +18 -9
- package/types/helpers/value.d.ts +4 -2
- package/types/index.d.cts +24 -13
- package/types/subscription.d.cts +16 -9
- package/types/subscription.d.ts +4 -4
- package/types/value/array.d.cts +21 -10
- package/types/value/array.d.ts +8 -4
- package/types/value/computed.d.cts +16 -9
- package/types/value/computed.d.ts +5 -6
- 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/dist/helpers/emit.cjs +0 -42
- package/dist/helpers/emit.js +0 -42
- package/src/helpers/emit.ts +0 -52
- package/types/helpers/emit.d.cts +0 -63
- package/types/helpers/emit.d.ts +0 -3
|
@@ -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,31 @@ 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
|
|
67
|
+
export declare function differentArrays<Value>(state: ReactiveState<Value[], Value>, first: Value[], second: Value[]): boolean;
|
|
68
|
+
export declare function differentValues<Value>(state: ReactiveState<Value, Value>, first: Value, second: Value): boolean;
|
|
69
|
+
export declare function emitValue<Value>(state: ReactiveState<Value, never>): void;
|
|
70
|
+
export declare function getValue<Value>(state: ReactiveState<Value, never>): Value;
|
|
62
71
|
|
|
63
72
|
export {};
|
package/types/helpers/value.d.ts
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
1
|
import type { ReactiveState } from '../value/reactive';
|
|
2
|
-
export declare function
|
|
3
|
-
export declare function
|
|
2
|
+
export declare function differentArrays<Value>(state: ReactiveState<Value[], Value>, first: Value[], second: Value[]): boolean;
|
|
3
|
+
export declare function differentValues<Value>(state: ReactiveState<Value, Value>, first: Value, second: Value): boolean;
|
|
4
|
+
export declare function emitValue<Value>(state: ReactiveState<Value, never>): void;
|
|
5
|
+
export declare function getValue<Value>(state: ReactiveState<Value, never>): Value;
|
package/types/index.d.cts
CHANGED
|
@@ -12,7 +12,7 @@ export declare class Effect {
|
|
|
12
12
|
export declare function effect(callback: GenericCallback): Effect;
|
|
13
13
|
export declare class Computed<Value> extends Reactive<Value> {
|
|
14
14
|
private readonly effect;
|
|
15
|
-
constructor(callback: () => Value);
|
|
15
|
+
constructor(callback: () => Value, options?: ReactiveOptions<Value>);
|
|
16
16
|
/**
|
|
17
17
|
* @inheritdoc
|
|
18
18
|
*/
|
|
@@ -21,10 +21,10 @@ export declare class Computed<Value> extends Reactive<Value> {
|
|
|
21
21
|
/**
|
|
22
22
|
* Create a computed value
|
|
23
23
|
*/
|
|
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);
|
|
24
|
+
export declare function computed<Value>(callback: () => Value, options?: ReactiveOptions<Value>): Computed<Value>;
|
|
25
|
+
export declare abstract class Reactive<Value, Equal = Value> {
|
|
26
|
+
protected readonly state: ReactiveState<Value, Equal>;
|
|
27
|
+
constructor(name: string, value: Value, options?: ReactiveOptions<Equal>);
|
|
28
28
|
/**
|
|
29
29
|
* Get the value
|
|
30
30
|
*/
|
|
@@ -50,16 +50,23 @@ export declare abstract class Reactive<Value> {
|
|
|
50
50
|
*/
|
|
51
51
|
unsubscribe(callback: (value: Value) => void): void;
|
|
52
52
|
}
|
|
53
|
-
export type
|
|
53
|
+
export type ReactiveOptions<Value> = {
|
|
54
|
+
/**
|
|
55
|
+
* Method to compare values for equality
|
|
56
|
+
*/
|
|
57
|
+
equal?: (first: Value, second: Value) => boolean;
|
|
58
|
+
};
|
|
59
|
+
export type ReactiveState<Value, Equal> = {
|
|
54
60
|
computeds: Set<Computed<unknown>>;
|
|
55
61
|
effects: Set<Effect>;
|
|
62
|
+
equal: (first: Equal, second: Equal) => boolean;
|
|
56
63
|
subscriptions: Map<(value: Value) => void, Subscription<Value>>;
|
|
57
64
|
value: Value;
|
|
58
65
|
};
|
|
59
66
|
declare class Subscription<Value> {
|
|
60
|
-
state: ReactiveState<Value>;
|
|
67
|
+
state: ReactiveState<Value, never>;
|
|
61
68
|
callback: GenericCallback;
|
|
62
|
-
constructor(state: ReactiveState<Value>, callback: GenericCallback);
|
|
69
|
+
constructor(state: ReactiveState<Value, never>, callback: GenericCallback);
|
|
63
70
|
}
|
|
64
71
|
/**
|
|
65
72
|
* Unsubscribe from changes
|
|
@@ -73,7 +80,7 @@ export declare function startBatch(): void;
|
|
|
73
80
|
* Stop batching effects and flush _(run)_ them
|
|
74
81
|
*/
|
|
75
82
|
export declare function stopBatch(): void;
|
|
76
|
-
export declare class ReactiveArray<Item> extends Reactive<Item[]> {
|
|
83
|
+
export declare class ReactiveArray<Item> extends Reactive<Item[], Item> {
|
|
77
84
|
#private;
|
|
78
85
|
/**
|
|
79
86
|
* The length of the array
|
|
@@ -83,11 +90,15 @@ export declare class ReactiveArray<Item> extends Reactive<Item[]> {
|
|
|
83
90
|
* Set the length of the array
|
|
84
91
|
*/
|
|
85
92
|
set length(value: number);
|
|
86
|
-
constructor(value: Item[]);
|
|
93
|
+
constructor(value: Item[], options?: ReactiveOptions<Item>);
|
|
87
94
|
/**
|
|
88
95
|
* Get an indexed item
|
|
89
96
|
*/
|
|
90
97
|
at(index: number): Item | undefined;
|
|
98
|
+
/**
|
|
99
|
+
* Clear the array
|
|
100
|
+
*/
|
|
101
|
+
clear(): void;
|
|
91
102
|
/**
|
|
92
103
|
* @inheritdoc
|
|
93
104
|
*/
|
|
@@ -144,9 +155,9 @@ export declare class ReactiveArray<Item> extends Reactive<Item[]> {
|
|
|
144
155
|
/**
|
|
145
156
|
* Create a reactive array
|
|
146
157
|
*/
|
|
147
|
-
export declare function array<Item>(value: Item[]): ReactiveArray<Item>;
|
|
158
|
+
export declare function array<Item>(value: Item[], options?: ReactiveOptions<Item>): ReactiveArray<Item>;
|
|
148
159
|
export declare class Signal<Value> extends Reactive<Value> {
|
|
149
|
-
constructor(value: Value);
|
|
160
|
+
constructor(value: Value, options?: ReactiveOptions<Value>);
|
|
150
161
|
/**
|
|
151
162
|
* @inheritdoc
|
|
152
163
|
*/
|
|
@@ -163,7 +174,7 @@ export declare class Signal<Value> extends Reactive<Value> {
|
|
|
163
174
|
/**
|
|
164
175
|
* Create a reactive value
|
|
165
176
|
*/
|
|
166
|
-
export declare function signal<Value>(value: Value): Signal<Value>;
|
|
177
|
+
export declare function signal<Value>(value: Value, options?: ReactiveOptions<Value>): Signal<Value>;
|
|
167
178
|
/**
|
|
168
179
|
* Is the value a reactive array?
|
|
169
180
|
*/
|
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,11 +74,15 @@ 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
|
*/
|
|
74
81
|
at(index: number): Item | undefined;
|
|
82
|
+
/**
|
|
83
|
+
* Clear the array
|
|
84
|
+
*/
|
|
85
|
+
clear(): void;
|
|
75
86
|
/**
|
|
76
87
|
* @inheritdoc
|
|
77
88
|
*/
|
|
@@ -128,6 +139,6 @@ export declare class ReactiveArray<Item> extends Reactive<Item[]> {
|
|
|
128
139
|
/**
|
|
129
140
|
* Create a reactive array
|
|
130
141
|
*/
|
|
131
|
-
export declare function array<Item>(value: Item[]): ReactiveArray<Item>;
|
|
142
|
+
export declare function array<Item>(value: Item[], options?: ReactiveOptions<Item>): ReactiveArray<Item>;
|
|
132
143
|
|
|
133
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,11 +10,15 @@ 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
|
*/
|
|
17
17
|
at(index: number): Item | undefined;
|
|
18
|
+
/**
|
|
19
|
+
* Clear the array
|
|
20
|
+
*/
|
|
21
|
+
clear(): void;
|
|
18
22
|
/**
|
|
19
23
|
* @inheritdoc
|
|
20
24
|
*/
|
|
@@ -71,4 +75,4 @@ export declare class ReactiveArray<Item> extends Reactive<Item[]> {
|
|
|
71
75
|
/**
|
|
72
76
|
* Create a reactive array
|
|
73
77
|
*/
|
|
74
|
-
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';
|
|
3
|
-
type ComputedEffect = {
|
|
2
|
+
import { Reactive, type ReactiveOptions, type ReactiveState } from './reactive';
|
|
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,5 +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>;
|
|
24
|
-
export {};
|
|
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
|
};
|
package/types/value/signal.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
|
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 class Signal<Value> extends Reactive<Value> {
|
|
61
|
-
constructor(value: Value);
|
|
68
|
+
constructor(value: Value, options?: ReactiveOptions<Value>);
|
|
62
69
|
/**
|
|
63
70
|
* @inheritdoc
|
|
64
71
|
*/
|
|
@@ -75,6 +82,6 @@ export declare class Signal<Value> extends Reactive<Value> {
|
|
|
75
82
|
/**
|
|
76
83
|
* Create a reactive value
|
|
77
84
|
*/
|
|
78
|
-
export declare function signal<Value>(value: Value): Signal<Value>;
|
|
85
|
+
export declare function signal<Value>(value: Value, options?: ReactiveOptions<Value>): Signal<Value>;
|
|
79
86
|
|
|
80
87
|
export {};
|
package/types/value/signal.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { Reactive } from './reactive';
|
|
1
|
+
import { Reactive, type ReactiveOptions } from './reactive';
|
|
2
2
|
export declare class Signal<Value> extends Reactive<Value> {
|
|
3
|
-
constructor(value: Value);
|
|
3
|
+
constructor(value: Value, options?: ReactiveOptions<Value>);
|
|
4
4
|
/**
|
|
5
5
|
* @inheritdoc
|
|
6
6
|
*/
|
|
@@ -17,4 +17,4 @@ export declare class Signal<Value> extends Reactive<Value> {
|
|
|
17
17
|
/**
|
|
18
18
|
* Create a reactive value
|
|
19
19
|
*/
|
|
20
|
-
export declare function signal<Value>(value: Value): Signal<Value>;
|
|
20
|
+
export declare function signal<Value>(value: Value, options?: ReactiveOptions<Value>): Signal<Value>;
|
package/dist/helpers/emit.cjs
DELETED
|
@@ -1,42 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
|
-
const batch = require("../batch.cjs");
|
|
4
|
-
function emitArrayChanges(first, second) {
|
|
5
|
-
let { length } = first;
|
|
6
|
-
if (length !== second.length) {
|
|
7
|
-
return true;
|
|
8
|
-
}
|
|
9
|
-
let offset = 0;
|
|
10
|
-
if (length >= 100) {
|
|
11
|
-
offset = Math.round(length / 10);
|
|
12
|
-
offset = offset > 25 ? 25 : offset;
|
|
13
|
-
for (let index = 0; index < offset; index += 1) {
|
|
14
|
-
if (!Object.is(first[index], second[index])) {
|
|
15
|
-
return true;
|
|
16
|
-
}
|
|
17
|
-
}
|
|
18
|
-
}
|
|
19
|
-
length -= offset;
|
|
20
|
-
for (let index = offset; index < length; index += 1) {
|
|
21
|
-
if (!Object.is(first[index], second[index])) {
|
|
22
|
-
return true;
|
|
23
|
-
}
|
|
24
|
-
}
|
|
25
|
-
return false;
|
|
26
|
-
}
|
|
27
|
-
function emitValue(state) {
|
|
28
|
-
for (const computed of state.computeds) {
|
|
29
|
-
computed.effect.dirty = true;
|
|
30
|
-
}
|
|
31
|
-
for (const effect of state.effects) {
|
|
32
|
-
batch.batchedHandlers.add(effect);
|
|
33
|
-
}
|
|
34
|
-
for (const [, subscription] of state.subscriptions) {
|
|
35
|
-
batch.batchedHandlers.add(subscription);
|
|
36
|
-
}
|
|
37
|
-
if (batch.batchDepth === 0) {
|
|
38
|
-
batch.flushEffects();
|
|
39
|
-
}
|
|
40
|
-
}
|
|
41
|
-
exports.emitArrayChanges = emitArrayChanges;
|
|
42
|
-
exports.emitValue = emitValue;
|