@oscarpalmer/mora 0.18.1 → 0.19.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/proxy.cjs +13 -0
- package/dist/helpers/proxy.js +13 -0
- package/dist/mora.full.js +25 -11
- package/dist/value/array.cjs +10 -11
- package/dist/value/array.js +11 -12
- package/dist/value/store.cjs +10 -1
- package/dist/value/store.js +11 -2
- package/package.json +1 -1
- package/src/helpers/proxy.ts +45 -1
- package/src/index.ts +1 -0
- package/src/value/array.ts +17 -9
- package/src/value/store.ts +11 -2
- package/types/batch.d.cts +79 -0
- package/types/effect.d.cts +16 -0
- package/types/helpers/is.d.cts +224 -0
- package/types/helpers/is.d.ts +2 -1
- package/types/helpers/proxy.d.cts +209 -0
- package/types/helpers/proxy.d.ts +6 -1
- package/types/helpers/value.d.cts +71 -0
- package/types/index.d.cts +246 -0
- package/types/subscription.d.cts +71 -0
- package/types/value/array.d.cts +142 -0
- package/types/value/array.d.ts +2 -4
- package/types/value/computed.d.cts +81 -0
- package/types/value/reactive.d.cts +68 -0
- package/types/value/signal.d.cts +87 -0
- package/types/value/store.d.cts +120 -0
- package/types/value/store.d.ts +1 -0
|
@@ -0,0 +1,224 @@
|
|
|
1
|
+
// Generated by dts-bundle-generator v9.5.1
|
|
2
|
+
|
|
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>;
|
|
12
|
+
declare class Effect {
|
|
13
|
+
private readonly $mora;
|
|
14
|
+
private readonly state;
|
|
15
|
+
constructor(callback: GenericCallback);
|
|
16
|
+
}
|
|
17
|
+
declare class Computed<Value> extends Reactive<Value> {
|
|
18
|
+
private readonly effect;
|
|
19
|
+
constructor(callback: () => Value, options?: ReactiveOptions<Value>);
|
|
20
|
+
/**
|
|
21
|
+
* @inheritdoc
|
|
22
|
+
*/
|
|
23
|
+
get(): Value;
|
|
24
|
+
}
|
|
25
|
+
declare abstract class Reactive<Value, Equal = Value> {
|
|
26
|
+
protected readonly state: ReactiveState<Value, Equal>;
|
|
27
|
+
constructor(name: string, value: Value, options?: ReactiveOptions<Equal>);
|
|
28
|
+
/**
|
|
29
|
+
* Get the value
|
|
30
|
+
*/
|
|
31
|
+
abstract get(): Value;
|
|
32
|
+
/**
|
|
33
|
+
* Get the value _(without reactivity)_
|
|
34
|
+
*/
|
|
35
|
+
peek(): Value;
|
|
36
|
+
/**
|
|
37
|
+
* Subscribe to changes
|
|
38
|
+
*/
|
|
39
|
+
subscribe(callback: (value: Value) => void): Unsubscribe;
|
|
40
|
+
/**
|
|
41
|
+
* JSON representation of the value
|
|
42
|
+
*/
|
|
43
|
+
toJSON(): Value;
|
|
44
|
+
/**
|
|
45
|
+
* String representation of the value
|
|
46
|
+
*/
|
|
47
|
+
toString(): string;
|
|
48
|
+
/**
|
|
49
|
+
* Unsubscribe from changes
|
|
50
|
+
*/
|
|
51
|
+
unsubscribe(callback: (value: Value) => void): void;
|
|
52
|
+
}
|
|
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> = {
|
|
60
|
+
computeds: Set<Computed<unknown>>;
|
|
61
|
+
effects: Set<Effect>;
|
|
62
|
+
equal: (first: Equal, second: Equal) => boolean;
|
|
63
|
+
subscriptions: Map<(value: Value) => void, Subscription<Value>>;
|
|
64
|
+
value: Value;
|
|
65
|
+
};
|
|
66
|
+
declare class Subscription<Value> {
|
|
67
|
+
state: ReactiveState<Value, never>;
|
|
68
|
+
callback: GenericCallback;
|
|
69
|
+
constructor(state: ReactiveState<Value, never>, callback: GenericCallback);
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* Unsubscribe from changes
|
|
73
|
+
*/
|
|
74
|
+
export type Unsubscribe = () => void;
|
|
75
|
+
declare class ReactiveArray<Item> extends Reactive<Item[], Item> {
|
|
76
|
+
#private;
|
|
77
|
+
/**
|
|
78
|
+
* The length of the array
|
|
79
|
+
*/
|
|
80
|
+
get length(): number;
|
|
81
|
+
/**
|
|
82
|
+
* Set the length of the array
|
|
83
|
+
*/
|
|
84
|
+
set length(value: number);
|
|
85
|
+
constructor(value: Item[], options?: ReactiveOptions<Item>);
|
|
86
|
+
/**
|
|
87
|
+
* Clear the array
|
|
88
|
+
*/
|
|
89
|
+
clear(): void;
|
|
90
|
+
/**
|
|
91
|
+
* @inheritdoc
|
|
92
|
+
*/
|
|
93
|
+
get(): Item[];
|
|
94
|
+
get(index: number): Item | undefined;
|
|
95
|
+
get(property: "length"): number;
|
|
96
|
+
/**
|
|
97
|
+
* Create a computed, filtered array
|
|
98
|
+
*/
|
|
99
|
+
filter(callback: (item: Item, index: number, array: Item[]) => boolean): Computed<Item[]>;
|
|
100
|
+
/**
|
|
101
|
+
* Create a computed, mapped array
|
|
102
|
+
*/
|
|
103
|
+
map<Mapped>(callback: (item: Item, index: number, array: Item[]) => Mapped): Computed<Mapped[]>;
|
|
104
|
+
/**
|
|
105
|
+
* @inheritdoc
|
|
106
|
+
*/
|
|
107
|
+
peek(): Item[];
|
|
108
|
+
/**
|
|
109
|
+
* Get the length of the array _(without reactivity)_
|
|
110
|
+
*/
|
|
111
|
+
peek(length: true): number;
|
|
112
|
+
/**
|
|
113
|
+
* Remove and return the last item of the array
|
|
114
|
+
*/
|
|
115
|
+
pop(): Item | undefined;
|
|
116
|
+
/**
|
|
117
|
+
* Add items to the end of the array
|
|
118
|
+
*/
|
|
119
|
+
push(...items: Item[]): number;
|
|
120
|
+
/**
|
|
121
|
+
* Set the value
|
|
122
|
+
*/
|
|
123
|
+
set(value: Item[]): void;
|
|
124
|
+
/**
|
|
125
|
+
* Set the value at an index
|
|
126
|
+
*/
|
|
127
|
+
set(index: number, value: Item): void;
|
|
128
|
+
/**
|
|
129
|
+
* Set the length of the array
|
|
130
|
+
*/
|
|
131
|
+
set(property: "length", value: number): void;
|
|
132
|
+
/**
|
|
133
|
+
* Remove and return the first item of the array
|
|
134
|
+
*/
|
|
135
|
+
shift(): Item | undefined;
|
|
136
|
+
/**
|
|
137
|
+
* Remove and return items from the array _(and optionally add new items)_
|
|
138
|
+
*/
|
|
139
|
+
splice(from: number, to?: number, ...items: Item[]): Item[];
|
|
140
|
+
/**
|
|
141
|
+
* Add items to the beginning of the array
|
|
142
|
+
*/
|
|
143
|
+
unshift(...items: Item[]): number;
|
|
144
|
+
}
|
|
145
|
+
declare class Signal<Value> extends Reactive<Value> {
|
|
146
|
+
constructor(value: Value, options?: ReactiveOptions<Value>);
|
|
147
|
+
/**
|
|
148
|
+
* @inheritdoc
|
|
149
|
+
*/
|
|
150
|
+
get(): Value;
|
|
151
|
+
/**
|
|
152
|
+
* Set the value
|
|
153
|
+
*/
|
|
154
|
+
set(value: Value): void;
|
|
155
|
+
/**
|
|
156
|
+
* Update the value
|
|
157
|
+
*/
|
|
158
|
+
update(callback: (value: Value) => Value): void;
|
|
159
|
+
}
|
|
160
|
+
declare class Store<Value extends PlainObject> extends Reactive<Value, Value> {
|
|
161
|
+
#private;
|
|
162
|
+
constructor(value: Value, options?: ReactiveOptions<Value>);
|
|
163
|
+
/**
|
|
164
|
+
* @inheritdoc
|
|
165
|
+
*/
|
|
166
|
+
get(): Value;
|
|
167
|
+
/**
|
|
168
|
+
* Get a value by key _(without reactivity)_
|
|
169
|
+
*/
|
|
170
|
+
get(key: keyof Value): Value[keyof Value];
|
|
171
|
+
/**
|
|
172
|
+
* Get a value by key _(without reactivity)_
|
|
173
|
+
*/
|
|
174
|
+
get(key: Key): unknown;
|
|
175
|
+
/**
|
|
176
|
+
* Get the value _(without reactivity)_
|
|
177
|
+
*/
|
|
178
|
+
peek(): Value;
|
|
179
|
+
/**
|
|
180
|
+
* Get a value by key _(without reactivity)_
|
|
181
|
+
*/
|
|
182
|
+
peek(key: keyof Value): Value[keyof Value];
|
|
183
|
+
/**
|
|
184
|
+
* Get a value by key _(without reactivity)_
|
|
185
|
+
*/
|
|
186
|
+
peek(key: Key): unknown;
|
|
187
|
+
/**
|
|
188
|
+
* Set the value
|
|
189
|
+
*/
|
|
190
|
+
set(value?: Value): void;
|
|
191
|
+
/**
|
|
192
|
+
* Set a value by key
|
|
193
|
+
*/
|
|
194
|
+
set(key: keyof Value, value: Value[keyof Value]): void;
|
|
195
|
+
/**
|
|
196
|
+
* Set a value by key
|
|
197
|
+
*/
|
|
198
|
+
set(key: Key, value: unknown): void;
|
|
199
|
+
}
|
|
200
|
+
/**
|
|
201
|
+
* Is the value a reactive array?
|
|
202
|
+
*/
|
|
203
|
+
export declare function isArray(value: unknown): value is ReactiveArray<unknown>;
|
|
204
|
+
/**
|
|
205
|
+
* Is the value a computed signal?
|
|
206
|
+
*/
|
|
207
|
+
export declare function isComputed(value: unknown): value is Computed<unknown>;
|
|
208
|
+
/**
|
|
209
|
+
* Is the value an effect?
|
|
210
|
+
*/
|
|
211
|
+
export declare function isEffect(value: unknown): value is Effect;
|
|
212
|
+
export declare function isReactive(value: unknown): value is Reactive<unknown>;
|
|
213
|
+
/**
|
|
214
|
+
* Is the value a signal?
|
|
215
|
+
*/
|
|
216
|
+
export declare function isSignal(value: unknown): value is Signal<unknown>;
|
|
217
|
+
export declare function isStore(value: unknown): value is Store<PlainObject>;
|
|
218
|
+
export declare const arrayName = "array";
|
|
219
|
+
export declare const computedName = "computed";
|
|
220
|
+
export declare const effectName = "effect";
|
|
221
|
+
export declare const signalName = "signal";
|
|
222
|
+
export declare const storeName = "store";
|
|
223
|
+
|
|
224
|
+
export {};
|
package/types/helpers/is.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { PlainObject } from '@oscarpalmer/atoms/models';
|
|
1
2
|
import type { Effect } from '../effect';
|
|
2
3
|
import type { ReactiveArray } from '../value/array';
|
|
3
4
|
import type { Computed } from '../value/computed';
|
|
@@ -21,7 +22,7 @@ export declare function isReactive(value: unknown): value is Reactive<unknown>;
|
|
|
21
22
|
* Is the value a signal?
|
|
22
23
|
*/
|
|
23
24
|
export declare function isSignal(value: unknown): value is Signal<unknown>;
|
|
24
|
-
export declare function isStore(value: unknown): value is Store<
|
|
25
|
+
export declare function isStore(value: unknown): value is Store<PlainObject>;
|
|
25
26
|
export declare const arrayName = "array";
|
|
26
27
|
export declare const computedName = "computed";
|
|
27
28
|
export declare const effectName = "effect";
|
|
@@ -0,0 +1,209 @@
|
|
|
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
|
+
/**
|
|
9
|
+
* A useful key type
|
|
10
|
+
*/
|
|
11
|
+
export type Key = number | string;
|
|
12
|
+
/**
|
|
13
|
+
* A generic object
|
|
14
|
+
*/
|
|
15
|
+
export type PlainObject = Record<PropertyKey, unknown>;
|
|
16
|
+
declare class Effect {
|
|
17
|
+
private readonly $mora;
|
|
18
|
+
private readonly state;
|
|
19
|
+
constructor(callback: GenericCallback);
|
|
20
|
+
}
|
|
21
|
+
declare class Computed<Value> extends Reactive<Value> {
|
|
22
|
+
private readonly effect;
|
|
23
|
+
constructor(callback: () => Value, options?: ReactiveOptions<Value>);
|
|
24
|
+
/**
|
|
25
|
+
* @inheritdoc
|
|
26
|
+
*/
|
|
27
|
+
get(): Value;
|
|
28
|
+
}
|
|
29
|
+
declare abstract class Reactive<Value, Equal = Value> {
|
|
30
|
+
protected readonly state: ReactiveState<Value, Equal>;
|
|
31
|
+
constructor(name: string, value: Value, options?: ReactiveOptions<Equal>);
|
|
32
|
+
/**
|
|
33
|
+
* Get the value
|
|
34
|
+
*/
|
|
35
|
+
abstract get(): Value;
|
|
36
|
+
/**
|
|
37
|
+
* Get the value _(without reactivity)_
|
|
38
|
+
*/
|
|
39
|
+
peek(): Value;
|
|
40
|
+
/**
|
|
41
|
+
* Subscribe to changes
|
|
42
|
+
*/
|
|
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;
|
|
52
|
+
/**
|
|
53
|
+
* Unsubscribe from changes
|
|
54
|
+
*/
|
|
55
|
+
unsubscribe(callback: (value: Value) => void): void;
|
|
56
|
+
}
|
|
57
|
+
export type ReactiveOptions<Value> = {
|
|
58
|
+
/**
|
|
59
|
+
* Method to compare values for equality
|
|
60
|
+
*/
|
|
61
|
+
equal?: (first: Value, second: Value) => boolean;
|
|
62
|
+
};
|
|
63
|
+
export type ReactiveState<Value, Equal> = {
|
|
64
|
+
computeds: Set<Computed<unknown>>;
|
|
65
|
+
effects: Set<Effect>;
|
|
66
|
+
equal: (first: Equal, second: Equal) => boolean;
|
|
67
|
+
subscriptions: Map<(value: Value) => void, Subscription<Value>>;
|
|
68
|
+
value: Value;
|
|
69
|
+
};
|
|
70
|
+
declare class Subscription<Value> {
|
|
71
|
+
state: ReactiveState<Value, never>;
|
|
72
|
+
callback: GenericCallback;
|
|
73
|
+
constructor(state: ReactiveState<Value, never>, callback: GenericCallback);
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* Unsubscribe from changes
|
|
77
|
+
*/
|
|
78
|
+
export type Unsubscribe = () => void;
|
|
79
|
+
declare class ReactiveArray<Item> extends Reactive<Item[], Item> {
|
|
80
|
+
#private;
|
|
81
|
+
/**
|
|
82
|
+
* The length of the array
|
|
83
|
+
*/
|
|
84
|
+
get length(): number;
|
|
85
|
+
/**
|
|
86
|
+
* Set the length of the array
|
|
87
|
+
*/
|
|
88
|
+
set length(value: number);
|
|
89
|
+
constructor(value: Item[], options?: ReactiveOptions<Item>);
|
|
90
|
+
/**
|
|
91
|
+
* Clear the array
|
|
92
|
+
*/
|
|
93
|
+
clear(): void;
|
|
94
|
+
/**
|
|
95
|
+
* @inheritdoc
|
|
96
|
+
*/
|
|
97
|
+
get(): Item[];
|
|
98
|
+
get(index: number): Item | undefined;
|
|
99
|
+
get(property: "length"): number;
|
|
100
|
+
/**
|
|
101
|
+
* Create a computed, filtered array
|
|
102
|
+
*/
|
|
103
|
+
filter(callback: (item: Item, index: number, array: Item[]) => boolean): Computed<Item[]>;
|
|
104
|
+
/**
|
|
105
|
+
* Create a computed, mapped array
|
|
106
|
+
*/
|
|
107
|
+
map<Mapped>(callback: (item: Item, index: number, array: Item[]) => Mapped): Computed<Mapped[]>;
|
|
108
|
+
/**
|
|
109
|
+
* @inheritdoc
|
|
110
|
+
*/
|
|
111
|
+
peek(): Item[];
|
|
112
|
+
/**
|
|
113
|
+
* Get the length of the array _(without reactivity)_
|
|
114
|
+
*/
|
|
115
|
+
peek(length: true): number;
|
|
116
|
+
/**
|
|
117
|
+
* Remove and return the last item of the array
|
|
118
|
+
*/
|
|
119
|
+
pop(): Item | undefined;
|
|
120
|
+
/**
|
|
121
|
+
* Add items to the end of the array
|
|
122
|
+
*/
|
|
123
|
+
push(...items: Item[]): number;
|
|
124
|
+
/**
|
|
125
|
+
* Set the value
|
|
126
|
+
*/
|
|
127
|
+
set(value: Item[]): void;
|
|
128
|
+
/**
|
|
129
|
+
* Set the value at an index
|
|
130
|
+
*/
|
|
131
|
+
set(index: number, value: Item): void;
|
|
132
|
+
/**
|
|
133
|
+
* Set the length of the array
|
|
134
|
+
*/
|
|
135
|
+
set(property: "length", value: number): void;
|
|
136
|
+
/**
|
|
137
|
+
* Remove and return the first item of the array
|
|
138
|
+
*/
|
|
139
|
+
shift(): Item | undefined;
|
|
140
|
+
/**
|
|
141
|
+
* Remove and return items from the array _(and optionally add new items)_
|
|
142
|
+
*/
|
|
143
|
+
splice(from: number, to?: number, ...items: Item[]): Item[];
|
|
144
|
+
/**
|
|
145
|
+
* Add items to the beginning of the array
|
|
146
|
+
*/
|
|
147
|
+
unshift(...items: Item[]): number;
|
|
148
|
+
}
|
|
149
|
+
declare class Signal<Value> extends Reactive<Value> {
|
|
150
|
+
constructor(value: Value, options?: ReactiveOptions<Value>);
|
|
151
|
+
/**
|
|
152
|
+
* @inheritdoc
|
|
153
|
+
*/
|
|
154
|
+
get(): Value;
|
|
155
|
+
/**
|
|
156
|
+
* Set the value
|
|
157
|
+
*/
|
|
158
|
+
set(value: Value): void;
|
|
159
|
+
/**
|
|
160
|
+
* Update the value
|
|
161
|
+
*/
|
|
162
|
+
update(callback: (value: Value) => Value): void;
|
|
163
|
+
}
|
|
164
|
+
declare class Store<Value extends PlainObject> extends Reactive<Value, Value> {
|
|
165
|
+
#private;
|
|
166
|
+
constructor(value: Value, options?: ReactiveOptions<Value>);
|
|
167
|
+
/**
|
|
168
|
+
* @inheritdoc
|
|
169
|
+
*/
|
|
170
|
+
get(): Value;
|
|
171
|
+
/**
|
|
172
|
+
* Get a value by key _(without reactivity)_
|
|
173
|
+
*/
|
|
174
|
+
get(key: keyof Value): Value[keyof Value];
|
|
175
|
+
/**
|
|
176
|
+
* Get a value by key _(without reactivity)_
|
|
177
|
+
*/
|
|
178
|
+
get(key: Key): unknown;
|
|
179
|
+
/**
|
|
180
|
+
* Get the value _(without reactivity)_
|
|
181
|
+
*/
|
|
182
|
+
peek(): Value;
|
|
183
|
+
/**
|
|
184
|
+
* Get a value by key _(without reactivity)_
|
|
185
|
+
*/
|
|
186
|
+
peek(key: keyof Value): Value[keyof Value];
|
|
187
|
+
/**
|
|
188
|
+
* Get a value by key _(without reactivity)_
|
|
189
|
+
*/
|
|
190
|
+
peek(key: Key): unknown;
|
|
191
|
+
/**
|
|
192
|
+
* Set the value
|
|
193
|
+
*/
|
|
194
|
+
set(value?: Value): void;
|
|
195
|
+
/**
|
|
196
|
+
* Set a value by key
|
|
197
|
+
*/
|
|
198
|
+
set(key: keyof Value, value: Value[keyof Value]): void;
|
|
199
|
+
/**
|
|
200
|
+
* Set a value by key
|
|
201
|
+
*/
|
|
202
|
+
set(key: Key, value: unknown): void;
|
|
203
|
+
}
|
|
204
|
+
export declare function getReactiveValueInProxy<Value>(array: ReactiveArray<Value>, mapped: Map<Key, Computed<unknown>>, index: number, isArray: true): unknown;
|
|
205
|
+
export declare function getReactiveValueInProxy<Value extends PlainObject>(store: Store<Value>, mapped: Map<Key, Computed<unknown>>, key: Key, isArray: false): unknown;
|
|
206
|
+
export declare function setProxyValue(proxy: ArrayOrPlainObject, value: ArrayOrPlainObject): void;
|
|
207
|
+
export declare function setValueInProxy<Value extends ArrayOrPlainObject, Equal>(target: Value, property: PropertyKey, value: unknown, state: ReactiveState<Value, Equal>, isArray: boolean, length?: Signal<number>): boolean;
|
|
208
|
+
|
|
209
|
+
export {};
|
package/types/helpers/proxy.d.ts
CHANGED
|
@@ -1,5 +1,10 @@
|
|
|
1
|
-
import type { ArrayOrPlainObject } from '@oscarpalmer/atoms/models';
|
|
1
|
+
import type { ArrayOrPlainObject, Key, PlainObject } from '@oscarpalmer/atoms/models';
|
|
2
|
+
import type { ReactiveArray } from '../value/array';
|
|
3
|
+
import { type Computed } from '../value/computed';
|
|
2
4
|
import type { ReactiveState } from '../value/reactive';
|
|
3
5
|
import type { Signal } from '../value/signal';
|
|
6
|
+
import type { Store } from '../value/store';
|
|
7
|
+
export declare function getReactiveValueInProxy<Value>(array: ReactiveArray<Value>, mapped: Map<Key, Computed<unknown>>, index: number, isArray: true): unknown;
|
|
8
|
+
export declare function getReactiveValueInProxy<Value extends PlainObject>(store: Store<Value>, mapped: Map<Key, Computed<unknown>>, key: Key, isArray: false): unknown;
|
|
4
9
|
export declare function setProxyValue(proxy: ArrayOrPlainObject, value: ArrayOrPlainObject): void;
|
|
5
10
|
export declare function setValueInProxy<Value extends ArrayOrPlainObject, Equal>(target: Value, property: PropertyKey, value: unknown, state: ReactiveState<Value, Equal>, isArray: boolean, length?: Signal<number>): boolean;
|
|
@@ -0,0 +1,71 @@
|
|
|
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, options?: ReactiveOptions<Value>);
|
|
12
|
+
/**
|
|
13
|
+
* @inheritdoc
|
|
14
|
+
*/
|
|
15
|
+
get(): Value;
|
|
16
|
+
}
|
|
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
|
+
/**
|
|
21
|
+
* Get the value
|
|
22
|
+
*/
|
|
23
|
+
abstract get(): Value;
|
|
24
|
+
/**
|
|
25
|
+
* Get the value _(without reactivity)_
|
|
26
|
+
*/
|
|
27
|
+
peek(): Value;
|
|
28
|
+
/**
|
|
29
|
+
* Subscribe to changes
|
|
30
|
+
*/
|
|
31
|
+
subscribe(callback: (value: Value) => void): Unsubscribe;
|
|
32
|
+
/**
|
|
33
|
+
* JSON representation of the value
|
|
34
|
+
*/
|
|
35
|
+
toJSON(): Value;
|
|
36
|
+
/**
|
|
37
|
+
* String representation of the value
|
|
38
|
+
*/
|
|
39
|
+
toString(): string;
|
|
40
|
+
/**
|
|
41
|
+
* Unsubscribe from changes
|
|
42
|
+
*/
|
|
43
|
+
unsubscribe(callback: (value: Value) => void): void;
|
|
44
|
+
}
|
|
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> = {
|
|
52
|
+
computeds: Set<Computed<unknown>>;
|
|
53
|
+
effects: Set<Effect>;
|
|
54
|
+
equal: (first: Equal, second: Equal) => boolean;
|
|
55
|
+
subscriptions: Map<(value: Value) => void, Subscription<Value>>;
|
|
56
|
+
value: Value;
|
|
57
|
+
};
|
|
58
|
+
declare class Subscription<Value> {
|
|
59
|
+
state: ReactiveState<Value, never>;
|
|
60
|
+
callback: GenericCallback;
|
|
61
|
+
constructor(state: ReactiveState<Value, never>, callback: GenericCallback);
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* Unsubscribe from changes
|
|
65
|
+
*/
|
|
66
|
+
export type Unsubscribe = () => void;
|
|
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;
|
|
70
|
+
|
|
71
|
+
export {};
|