@oscarpalmer/mora 0.17.0 → 0.18.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/helpers/value.cjs +5 -5
- package/dist/helpers/value.js +5 -5
- package/dist/mora.full.js +23 -27
- package/dist/value/array.cjs +6 -7
- package/dist/value/array.js +6 -7
- package/dist/value/computed.cjs +5 -5
- package/dist/value/computed.js +5 -5
- package/dist/value/reactive.cjs +1 -5
- package/dist/value/reactive.js +1 -5
- package/dist/value/signal.cjs +5 -5
- package/dist/value/signal.js +5 -5
- package/package.json +1 -1
- package/src/helpers/is.ts +7 -1
- package/src/helpers/proxy.ts +72 -0
- package/src/helpers/value.ts +23 -33
- package/src/index.ts +1 -0
- package/src/value/array.ts +11 -30
- package/src/value/signal.ts +2 -2
- package/src/value/store.ts +90 -0
- package/types/batch.d.cts +7 -14
- package/types/helpers/is.d.cts +10 -17
- package/types/helpers/value.d.cts +11 -18
- package/types/helpers/value.d.ts +4 -4
- package/types/index.d.cts +13 -20
- package/types/subscription.d.cts +9 -16
- package/types/subscription.d.ts +4 -4
- package/types/value/array.d.cts +10 -17
- package/types/value/array.d.ts +4 -4
- package/types/value/computed.d.cts +9 -16
- package/types/value/computed.d.ts +4 -4
- package/types/value/reactive.d.cts +7 -14
- package/types/value/reactive.d.ts +4 -11
- package/types/value/signal.d.cts +9 -16
- package/types/value/signal.d.ts +3 -3
package/src/value/array.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import {arrayName} from '../helpers/is';
|
|
2
|
-
import {
|
|
2
|
+
import {setValueInProxy} from '../helpers/proxy';
|
|
3
|
+
import {emitValue, equalArrays, getValue} from '../helpers/value';
|
|
3
4
|
import {type Computed, computed} from './computed';
|
|
4
5
|
import {Reactive, type ReactiveOptions, type ReactiveState} from './reactive';
|
|
5
6
|
import {type Signal, signal} from './signal';
|
|
@@ -36,7 +37,14 @@ export class ReactiveArray<Item> extends Reactive<Item[], Item> {
|
|
|
36
37
|
? updateArray(property as string, target, this.state, this.#size)
|
|
37
38
|
: Reflect.get(target, property),
|
|
38
39
|
set: (target, property, value) =>
|
|
39
|
-
|
|
40
|
+
setValueInProxy(
|
|
41
|
+
target,
|
|
42
|
+
property,
|
|
43
|
+
value,
|
|
44
|
+
this.state,
|
|
45
|
+
true,
|
|
46
|
+
this.#size,
|
|
47
|
+
),
|
|
40
48
|
}),
|
|
41
49
|
options,
|
|
42
50
|
);
|
|
@@ -172,33 +180,6 @@ export function array<Item>(
|
|
|
172
180
|
return new ReactiveArray(Array.isArray(value) ? value : [], options);
|
|
173
181
|
}
|
|
174
182
|
|
|
175
|
-
function setValue<Item>(
|
|
176
|
-
target: Item[],
|
|
177
|
-
property: PropertyKey,
|
|
178
|
-
value: Item,
|
|
179
|
-
state: ReactiveState<Item[], Item>,
|
|
180
|
-
length: Signal<number>,
|
|
181
|
-
): boolean {
|
|
182
|
-
const isIndex = !Number.isNaN(Number(property));
|
|
183
|
-
const isLength = property === 'length';
|
|
184
|
-
|
|
185
|
-
if (!isIndex && !isLength) {
|
|
186
|
-
return Reflect.set(target, property, value);
|
|
187
|
-
}
|
|
188
|
-
|
|
189
|
-
const previous = Reflect.get(target, property);
|
|
190
|
-
|
|
191
|
-
if (!state.equal(previous, value)) {
|
|
192
|
-
Reflect.set(target, property, value);
|
|
193
|
-
|
|
194
|
-
emitValue(state);
|
|
195
|
-
|
|
196
|
-
length.set(target.length);
|
|
197
|
-
}
|
|
198
|
-
|
|
199
|
-
return true;
|
|
200
|
-
}
|
|
201
|
-
|
|
202
183
|
function updateArray<Item>(
|
|
203
184
|
type: string,
|
|
204
185
|
array: Item[],
|
|
@@ -217,7 +198,7 @@ function updateArray<Item>(
|
|
|
217
198
|
if (
|
|
218
199
|
affectsLength
|
|
219
200
|
? array.length !== previousLength
|
|
220
|
-
:
|
|
201
|
+
: !equalArrays(state, previousArray, array)
|
|
221
202
|
) {
|
|
222
203
|
emitValue(state);
|
|
223
204
|
|
package/src/value/signal.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import {signalName} from '../helpers/is';
|
|
2
|
-
import {
|
|
2
|
+
import {emitValue, getValue} from '../helpers/value';
|
|
3
3
|
import {Reactive, type ReactiveOptions} from './reactive';
|
|
4
4
|
|
|
5
5
|
export class Signal<Value> extends Reactive<Value> {
|
|
@@ -18,7 +18,7 @@ export class Signal<Value> extends Reactive<Value> {
|
|
|
18
18
|
* Set the value
|
|
19
19
|
*/
|
|
20
20
|
set(value: Value): void {
|
|
21
|
-
if (
|
|
21
|
+
if (!this.state.equal(this.state.value, value)) {
|
|
22
22
|
this.state.value = value;
|
|
23
23
|
|
|
24
24
|
emitValue(this.state);
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
import {isKey, isPlainObject} from '@oscarpalmer/atoms/is';
|
|
2
|
+
import type {Key, PlainObject} from '@oscarpalmer/atoms/models';
|
|
3
|
+
import {storeName} from '../helpers/is';
|
|
4
|
+
import {setProxyValue, setValueInProxy} from '../helpers/proxy';
|
|
5
|
+
import {getValue} from '../helpers/value';
|
|
6
|
+
import {Reactive, type ReactiveOptions} from './reactive';
|
|
7
|
+
|
|
8
|
+
export class Store<Value extends PlainObject> extends Reactive<Value, Value> {
|
|
9
|
+
constructor(value: Value, options?: ReactiveOptions<Value>) {
|
|
10
|
+
super(
|
|
11
|
+
storeName,
|
|
12
|
+
new Proxy(value, {
|
|
13
|
+
set: (target, property, value) =>
|
|
14
|
+
setValueInProxy(target, property, value, this.state, false),
|
|
15
|
+
}),
|
|
16
|
+
options,
|
|
17
|
+
);
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* @inheritdoc
|
|
22
|
+
*/
|
|
23
|
+
get(): Value;
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* Get a value by key _(without reactivity)_
|
|
27
|
+
*/
|
|
28
|
+
get(key: keyof Value): Value[keyof Value];
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* Get a value by key _(without reactivity)_
|
|
32
|
+
*/
|
|
33
|
+
get(key: Key): unknown;
|
|
34
|
+
|
|
35
|
+
get(key?: unknown): unknown {
|
|
36
|
+
return isKey(key) ? this.state.value[key] : getValue(this.state);
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* Get the value _(without reactivity)_
|
|
41
|
+
*/
|
|
42
|
+
peek(): Value;
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* Get a value by key _(without reactivity)_
|
|
46
|
+
*/
|
|
47
|
+
peek(key: keyof Value): Value[keyof Value];
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* Get a value by key _(without reactivity)_
|
|
51
|
+
*/
|
|
52
|
+
peek(key: Key): unknown;
|
|
53
|
+
|
|
54
|
+
peek(key?: unknown): unknown {
|
|
55
|
+
return isKey(key) ? this.state.value[key] : {...this.state.value};
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
/**
|
|
59
|
+
* Set the value
|
|
60
|
+
*/
|
|
61
|
+
set(value?: Value): void;
|
|
62
|
+
|
|
63
|
+
/**
|
|
64
|
+
* Set a value by key
|
|
65
|
+
*/
|
|
66
|
+
set(key: keyof Value, value: Value[keyof Value]): void;
|
|
67
|
+
|
|
68
|
+
/**
|
|
69
|
+
* Set a value by key
|
|
70
|
+
*/
|
|
71
|
+
set(key: Key, value: unknown): void;
|
|
72
|
+
|
|
73
|
+
set(first?: unknown, second?: unknown): void {
|
|
74
|
+
if (isKey(first)) {
|
|
75
|
+
(this.state.value as PlainObject)[first] = second;
|
|
76
|
+
} else if (first == null || isPlainObject(first)) {
|
|
77
|
+
setProxyValue(this.state.value, first ?? {});
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
/**
|
|
83
|
+
* Create a reactive store
|
|
84
|
+
*/
|
|
85
|
+
export function store<Value extends PlainObject>(
|
|
86
|
+
value: Value,
|
|
87
|
+
options?: ReactiveOptions<Value>,
|
|
88
|
+
): Store<Value> {
|
|
89
|
+
return new Store((isPlainObject(value) ? value : {}) as Value, options);
|
|
90
|
+
}
|
package/types/batch.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);
|
|
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> {
|
|
18
|
+
protected readonly state: ReactiveState<Value>;
|
|
19
|
+
constructor(name: string, value: Value);
|
|
20
20
|
/**
|
|
21
21
|
* Get the value
|
|
22
22
|
*/
|
|
@@ -42,23 +42,16 @@ declare abstract class Reactive<Value, Equal = Value> {
|
|
|
42
42
|
*/
|
|
43
43
|
unsubscribe(callback: (value: Value) => void): void;
|
|
44
44
|
}
|
|
45
|
-
export type
|
|
46
|
-
/**
|
|
47
|
-
* Method to compare values for equality
|
|
48
|
-
*/
|
|
49
|
-
equal?: (first: Value, second: Value) => boolean;
|
|
50
|
-
};
|
|
51
|
-
export type ReactiveState<Value, Equal> = {
|
|
45
|
+
export type ReactiveState<Value> = {
|
|
52
46
|
computeds: Set<Computed<unknown>>;
|
|
53
47
|
effects: Set<Effect>;
|
|
54
|
-
equal: (first: Equal, second: Equal) => boolean;
|
|
55
48
|
subscriptions: Map<(value: Value) => void, Subscription<Value>>;
|
|
56
49
|
value: Value;
|
|
57
50
|
};
|
|
58
51
|
declare class Subscription<Value> {
|
|
59
|
-
state: ReactiveState<Value
|
|
52
|
+
state: ReactiveState<Value>;
|
|
60
53
|
callback: GenericCallback;
|
|
61
|
-
constructor(state: ReactiveState<Value
|
|
54
|
+
constructor(state: ReactiveState<Value>, callback: GenericCallback);
|
|
62
55
|
}
|
|
63
56
|
/**
|
|
64
57
|
* Unsubscribe from changes
|
package/types/helpers/is.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);
|
|
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> {
|
|
18
|
+
protected readonly state: ReactiveState<Value>;
|
|
19
|
+
constructor(name: string, value: Value);
|
|
20
20
|
/**
|
|
21
21
|
* Get the value
|
|
22
22
|
*/
|
|
@@ -42,29 +42,22 @@ declare abstract class Reactive<Value, Equal = Value> {
|
|
|
42
42
|
*/
|
|
43
43
|
unsubscribe(callback: (value: Value) => void): void;
|
|
44
44
|
}
|
|
45
|
-
export type
|
|
46
|
-
/**
|
|
47
|
-
* Method to compare values for equality
|
|
48
|
-
*/
|
|
49
|
-
equal?: (first: Value, second: Value) => boolean;
|
|
50
|
-
};
|
|
51
|
-
export type ReactiveState<Value, Equal> = {
|
|
45
|
+
export type ReactiveState<Value> = {
|
|
52
46
|
computeds: Set<Computed<unknown>>;
|
|
53
47
|
effects: Set<Effect>;
|
|
54
|
-
equal: (first: Equal, second: Equal) => boolean;
|
|
55
48
|
subscriptions: Map<(value: Value) => void, Subscription<Value>>;
|
|
56
49
|
value: Value;
|
|
57
50
|
};
|
|
58
51
|
declare class Subscription<Value> {
|
|
59
|
-
state: ReactiveState<Value
|
|
52
|
+
state: ReactiveState<Value>;
|
|
60
53
|
callback: GenericCallback;
|
|
61
|
-
constructor(state: ReactiveState<Value
|
|
54
|
+
constructor(state: ReactiveState<Value>, callback: GenericCallback);
|
|
62
55
|
}
|
|
63
56
|
/**
|
|
64
57
|
* Unsubscribe from changes
|
|
65
58
|
*/
|
|
66
59
|
export type Unsubscribe = () => void;
|
|
67
|
-
declare class ReactiveArray<Item> extends Reactive<Item[]
|
|
60
|
+
declare class ReactiveArray<Item> extends Reactive<Item[]> {
|
|
68
61
|
#private;
|
|
69
62
|
/**
|
|
70
63
|
* The length of the array
|
|
@@ -74,7 +67,7 @@ declare class ReactiveArray<Item> extends Reactive<Item[], Item> {
|
|
|
74
67
|
* Set the length of the array
|
|
75
68
|
*/
|
|
76
69
|
set length(value: number);
|
|
77
|
-
constructor(value: Item[]
|
|
70
|
+
constructor(value: Item[]);
|
|
78
71
|
/**
|
|
79
72
|
* Get an indexed item
|
|
80
73
|
*/
|
|
@@ -137,7 +130,7 @@ declare class ReactiveArray<Item> extends Reactive<Item[], Item> {
|
|
|
137
130
|
unshift(...items: Item[]): number;
|
|
138
131
|
}
|
|
139
132
|
declare class Signal<Value> extends Reactive<Value> {
|
|
140
|
-
constructor(value: Value
|
|
133
|
+
constructor(value: Value);
|
|
141
134
|
/**
|
|
142
135
|
* @inheritdoc
|
|
143
136
|
*/
|
|
@@ -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);
|
|
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> {
|
|
18
|
+
protected readonly state: ReactiveState<Value>;
|
|
19
|
+
constructor(name: string, value: Value);
|
|
20
20
|
/**
|
|
21
21
|
* Get the value
|
|
22
22
|
*/
|
|
@@ -42,31 +42,24 @@ declare abstract class Reactive<Value, Equal = Value> {
|
|
|
42
42
|
*/
|
|
43
43
|
unsubscribe(callback: (value: Value) => void): void;
|
|
44
44
|
}
|
|
45
|
-
export type
|
|
46
|
-
/**
|
|
47
|
-
* Method to compare values for equality
|
|
48
|
-
*/
|
|
49
|
-
equal?: (first: Value, second: Value) => boolean;
|
|
50
|
-
};
|
|
51
|
-
export type ReactiveState<Value, Equal> = {
|
|
45
|
+
export type ReactiveState<Value> = {
|
|
52
46
|
computeds: Set<Computed<unknown>>;
|
|
53
47
|
effects: Set<Effect>;
|
|
54
|
-
equal: (first: Equal, second: Equal) => boolean;
|
|
55
48
|
subscriptions: Map<(value: Value) => void, Subscription<Value>>;
|
|
56
49
|
value: Value;
|
|
57
50
|
};
|
|
58
51
|
declare class Subscription<Value> {
|
|
59
|
-
state: ReactiveState<Value
|
|
52
|
+
state: ReactiveState<Value>;
|
|
60
53
|
callback: GenericCallback;
|
|
61
|
-
constructor(state: ReactiveState<Value
|
|
54
|
+
constructor(state: ReactiveState<Value>, callback: GenericCallback);
|
|
62
55
|
}
|
|
63
56
|
/**
|
|
64
57
|
* Unsubscribe from changes
|
|
65
58
|
*/
|
|
66
59
|
export type Unsubscribe = () => void;
|
|
67
|
-
export declare function differentArrays
|
|
68
|
-
export declare function differentValues
|
|
69
|
-
export declare function emitValue<Value>(state: ReactiveState<Value
|
|
70
|
-
export declare function getValue<Value>(state: ReactiveState<Value
|
|
60
|
+
export declare function differentArrays(first: unknown[], second: unknown[]): boolean;
|
|
61
|
+
export declare function differentValues(first: unknown, second: unknown): boolean;
|
|
62
|
+
export declare function emitValue<Value>(state: ReactiveState<Value>): void;
|
|
63
|
+
export declare function getValue<Value>(state: ReactiveState<Value>): Value;
|
|
71
64
|
|
|
72
65
|
export {};
|
package/types/helpers/value.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { ReactiveState } from '../value/reactive';
|
|
2
|
-
export declare function differentArrays
|
|
3
|
-
export declare function differentValues
|
|
4
|
-
export declare function emitValue<Value>(state: ReactiveState<Value
|
|
5
|
-
export declare function getValue<Value>(state: ReactiveState<Value
|
|
2
|
+
export declare function differentArrays(first: unknown[], second: unknown[]): boolean;
|
|
3
|
+
export declare function differentValues(first: unknown, second: unknown): boolean;
|
|
4
|
+
export declare function emitValue<Value>(state: ReactiveState<Value>): void;
|
|
5
|
+
export declare function getValue<Value>(state: ReactiveState<Value>): 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);
|
|
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
|
|
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): Computed<Value>;
|
|
25
|
+
export declare abstract class Reactive<Value> {
|
|
26
|
+
protected readonly state: ReactiveState<Value>;
|
|
27
|
+
constructor(name: string, value: Value);
|
|
28
28
|
/**
|
|
29
29
|
* Get the value
|
|
30
30
|
*/
|
|
@@ -50,23 +50,16 @@ export declare abstract class Reactive<Value, Equal = Value> {
|
|
|
50
50
|
*/
|
|
51
51
|
unsubscribe(callback: (value: Value) => void): void;
|
|
52
52
|
}
|
|
53
|
-
export type
|
|
54
|
-
/**
|
|
55
|
-
* Method to compare values for equality
|
|
56
|
-
*/
|
|
57
|
-
equal?: (first: Value, second: Value) => boolean;
|
|
58
|
-
};
|
|
59
|
-
export type ReactiveState<Value, Equal> = {
|
|
53
|
+
export type ReactiveState<Value> = {
|
|
60
54
|
computeds: Set<Computed<unknown>>;
|
|
61
55
|
effects: Set<Effect>;
|
|
62
|
-
equal: (first: Equal, second: Equal) => boolean;
|
|
63
56
|
subscriptions: Map<(value: Value) => void, Subscription<Value>>;
|
|
64
57
|
value: Value;
|
|
65
58
|
};
|
|
66
59
|
declare class Subscription<Value> {
|
|
67
|
-
state: ReactiveState<Value
|
|
60
|
+
state: ReactiveState<Value>;
|
|
68
61
|
callback: GenericCallback;
|
|
69
|
-
constructor(state: ReactiveState<Value
|
|
62
|
+
constructor(state: ReactiveState<Value>, callback: GenericCallback);
|
|
70
63
|
}
|
|
71
64
|
/**
|
|
72
65
|
* Unsubscribe from changes
|
|
@@ -80,7 +73,7 @@ export declare function startBatch(): void;
|
|
|
80
73
|
* Stop batching effects and flush _(run)_ them
|
|
81
74
|
*/
|
|
82
75
|
export declare function stopBatch(): void;
|
|
83
|
-
export declare class ReactiveArray<Item> extends Reactive<Item[]
|
|
76
|
+
export declare class ReactiveArray<Item> extends Reactive<Item[]> {
|
|
84
77
|
#private;
|
|
85
78
|
/**
|
|
86
79
|
* The length of the array
|
|
@@ -90,7 +83,7 @@ export declare class ReactiveArray<Item> extends Reactive<Item[], Item> {
|
|
|
90
83
|
* Set the length of the array
|
|
91
84
|
*/
|
|
92
85
|
set length(value: number);
|
|
93
|
-
constructor(value: Item[]
|
|
86
|
+
constructor(value: Item[]);
|
|
94
87
|
/**
|
|
95
88
|
* Get an indexed item
|
|
96
89
|
*/
|
|
@@ -155,9 +148,9 @@ export declare class ReactiveArray<Item> extends Reactive<Item[], Item> {
|
|
|
155
148
|
/**
|
|
156
149
|
* Create a reactive array
|
|
157
150
|
*/
|
|
158
|
-
export declare function array<Item>(value: Item[]
|
|
151
|
+
export declare function array<Item>(value: Item[]): ReactiveArray<Item>;
|
|
159
152
|
export declare class Signal<Value> extends Reactive<Value> {
|
|
160
|
-
constructor(value: Value
|
|
153
|
+
constructor(value: Value);
|
|
161
154
|
/**
|
|
162
155
|
* @inheritdoc
|
|
163
156
|
*/
|
|
@@ -174,7 +167,7 @@ export declare class Signal<Value> extends Reactive<Value> {
|
|
|
174
167
|
/**
|
|
175
168
|
* Create a reactive value
|
|
176
169
|
*/
|
|
177
|
-
export declare function signal<Value>(value: Value
|
|
170
|
+
export declare function signal<Value>(value: Value): Signal<Value>;
|
|
178
171
|
/**
|
|
179
172
|
* Is the value a reactive array?
|
|
180
173
|
*/
|
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);
|
|
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> {
|
|
18
|
+
protected readonly state: ReactiveState<Value>;
|
|
19
|
+
constructor(name: string, value: Value);
|
|
20
20
|
/**
|
|
21
21
|
* Get the value
|
|
22
22
|
*/
|
|
@@ -42,30 +42,23 @@ declare abstract class Reactive<Value, Equal = Value> {
|
|
|
42
42
|
*/
|
|
43
43
|
unsubscribe(callback: (value: Value) => void): void;
|
|
44
44
|
}
|
|
45
|
-
export type
|
|
46
|
-
/**
|
|
47
|
-
* Method to compare values for equality
|
|
48
|
-
*/
|
|
49
|
-
equal?: (first: Value, second: Value) => boolean;
|
|
50
|
-
};
|
|
51
|
-
export type ReactiveState<Value, Equal> = {
|
|
45
|
+
export type ReactiveState<Value> = {
|
|
52
46
|
computeds: Set<Computed<unknown>>;
|
|
53
47
|
effects: Set<Effect>;
|
|
54
|
-
equal: (first: Equal, second: Equal) => boolean;
|
|
55
48
|
subscriptions: Map<(value: Value) => void, Subscription<Value>>;
|
|
56
49
|
value: Value;
|
|
57
50
|
};
|
|
58
51
|
export declare class Subscription<Value> {
|
|
59
|
-
state: ReactiveState<Value
|
|
52
|
+
state: ReactiveState<Value>;
|
|
60
53
|
callback: GenericCallback;
|
|
61
|
-
constructor(state: ReactiveState<Value
|
|
54
|
+
constructor(state: ReactiveState<Value>, callback: GenericCallback);
|
|
62
55
|
}
|
|
63
56
|
/**
|
|
64
57
|
* Unsubscribe from changes
|
|
65
58
|
*/
|
|
66
59
|
export type Unsubscribe = () => void;
|
|
67
60
|
export declare function noop(): void;
|
|
68
|
-
export declare function subscribe<Value>(state: ReactiveState<Value
|
|
69
|
-
export declare function unsubscribe<Value>(state: ReactiveState<Value
|
|
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;
|
|
70
63
|
|
|
71
64
|
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>;
|
|
5
5
|
callback: GenericCallback;
|
|
6
|
-
constructor(state: ReactiveState<Value
|
|
6
|
+
constructor(state: ReactiveState<Value>, 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
|
|
14
|
-
export declare function unsubscribe<Value>(state: ReactiveState<Value
|
|
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;
|
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);
|
|
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> {
|
|
18
|
+
protected readonly state: ReactiveState<Value>;
|
|
19
|
+
constructor(name: string, value: Value);
|
|
20
20
|
/**
|
|
21
21
|
* Get the value
|
|
22
22
|
*/
|
|
@@ -42,29 +42,22 @@ declare abstract class Reactive<Value, Equal = Value> {
|
|
|
42
42
|
*/
|
|
43
43
|
unsubscribe(callback: (value: Value) => void): void;
|
|
44
44
|
}
|
|
45
|
-
export type
|
|
46
|
-
/**
|
|
47
|
-
* Method to compare values for equality
|
|
48
|
-
*/
|
|
49
|
-
equal?: (first: Value, second: Value) => boolean;
|
|
50
|
-
};
|
|
51
|
-
export type ReactiveState<Value, Equal> = {
|
|
45
|
+
export type ReactiveState<Value> = {
|
|
52
46
|
computeds: Set<Computed<unknown>>;
|
|
53
47
|
effects: Set<Effect>;
|
|
54
|
-
equal: (first: Equal, second: Equal) => boolean;
|
|
55
48
|
subscriptions: Map<(value: Value) => void, Subscription<Value>>;
|
|
56
49
|
value: Value;
|
|
57
50
|
};
|
|
58
51
|
declare class Subscription<Value> {
|
|
59
|
-
state: ReactiveState<Value
|
|
52
|
+
state: ReactiveState<Value>;
|
|
60
53
|
callback: GenericCallback;
|
|
61
|
-
constructor(state: ReactiveState<Value
|
|
54
|
+
constructor(state: ReactiveState<Value>, callback: GenericCallback);
|
|
62
55
|
}
|
|
63
56
|
/**
|
|
64
57
|
* Unsubscribe from changes
|
|
65
58
|
*/
|
|
66
59
|
export type Unsubscribe = () => void;
|
|
67
|
-
export declare class ReactiveArray<Item> extends Reactive<Item[]
|
|
60
|
+
export declare class ReactiveArray<Item> extends Reactive<Item[]> {
|
|
68
61
|
#private;
|
|
69
62
|
/**
|
|
70
63
|
* The length of the array
|
|
@@ -74,7 +67,7 @@ export declare class ReactiveArray<Item> extends Reactive<Item[], Item> {
|
|
|
74
67
|
* Set the length of the array
|
|
75
68
|
*/
|
|
76
69
|
set length(value: number);
|
|
77
|
-
constructor(value: Item[]
|
|
70
|
+
constructor(value: Item[]);
|
|
78
71
|
/**
|
|
79
72
|
* Get an indexed item
|
|
80
73
|
*/
|
|
@@ -139,6 +132,6 @@ export declare class ReactiveArray<Item> extends Reactive<Item[], Item> {
|
|
|
139
132
|
/**
|
|
140
133
|
* Create a reactive array
|
|
141
134
|
*/
|
|
142
|
-
export declare function array<Item>(value: Item[]
|
|
135
|
+
export declare function array<Item>(value: Item[]): ReactiveArray<Item>;
|
|
143
136
|
|
|
144
137
|
export {};
|
package/types/value/array.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { type Computed } from './computed';
|
|
2
|
-
import { Reactive
|
|
3
|
-
export declare class ReactiveArray<Item> extends Reactive<Item[]
|
|
2
|
+
import { Reactive } from './reactive';
|
|
3
|
+
export declare class ReactiveArray<Item> extends Reactive<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[], 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[]);
|
|
14
14
|
/**
|
|
15
15
|
* Get an indexed item
|
|
16
16
|
*/
|
|
@@ -75,4 +75,4 @@ export declare class ReactiveArray<Item> extends Reactive<Item[], Item> {
|
|
|
75
75
|
/**
|
|
76
76
|
* Create a reactive array
|
|
77
77
|
*/
|
|
78
|
-
export declare function array<Item>(value: Item[]
|
|
78
|
+
export declare function array<Item>(value: 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>;
|
|
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);
|
|
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
|
|
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): Computed<Value>;
|
|
30
|
+
declare abstract class Reactive<Value> {
|
|
31
|
+
protected readonly state: ReactiveState<Value>;
|
|
32
|
+
constructor(name: string, value: Value);
|
|
33
33
|
/**
|
|
34
34
|
* Get the value
|
|
35
35
|
*/
|
|
@@ -55,23 +55,16 @@ declare abstract class Reactive<Value, Equal = Value> {
|
|
|
55
55
|
*/
|
|
56
56
|
unsubscribe(callback: (value: Value) => void): void;
|
|
57
57
|
}
|
|
58
|
-
export type
|
|
59
|
-
/**
|
|
60
|
-
* Method to compare values for equality
|
|
61
|
-
*/
|
|
62
|
-
equal?: (first: Value, second: Value) => boolean;
|
|
63
|
-
};
|
|
64
|
-
export type ReactiveState<Value, Equal> = {
|
|
58
|
+
export type ReactiveState<Value> = {
|
|
65
59
|
computeds: Set<Computed<unknown>>;
|
|
66
60
|
effects: Set<Effect>;
|
|
67
|
-
equal: (first: Equal, second: Equal) => boolean;
|
|
68
61
|
subscriptions: Map<(value: Value) => void, Subscription<Value>>;
|
|
69
62
|
value: Value;
|
|
70
63
|
};
|
|
71
64
|
declare class Subscription<Value> {
|
|
72
|
-
state: ReactiveState<Value
|
|
65
|
+
state: ReactiveState<Value>;
|
|
73
66
|
callback: GenericCallback;
|
|
74
|
-
constructor(state: ReactiveState<Value
|
|
67
|
+
constructor(state: ReactiveState<Value>, callback: GenericCallback);
|
|
75
68
|
}
|
|
76
69
|
/**
|
|
77
70
|
* Unsubscribe from changes
|