@oscarpalmer/mora 0.31.0 → 0.33.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.d.mts +4 -5
- package/dist/batch.mjs +4 -2
- package/dist/constants.d.mts +31 -19
- package/dist/constants.mjs +19 -2
- package/dist/effect.d.mts +5 -5
- package/dist/effect.mjs +8 -5
- package/dist/helpers/is.d.mts +14 -9
- package/dist/helpers/is.mjs +6 -0
- package/dist/helpers/misc.d.mts +4 -0
- package/dist/helpers/misc.mjs +9 -0
- package/dist/helpers/proxy.d.mts +10 -10
- package/dist/helpers/proxy.mjs +83 -27
- package/dist/helpers/subscription.d.mts +8 -0
- package/dist/helpers/subscription.mjs +30 -0
- package/dist/helpers/value.d.mts +10 -7
- package/dist/helpers/value.mjs +56 -17
- package/dist/index.d.mts +3 -2
- package/dist/models.d.mts +82 -101
- package/dist/models.mjs +1 -0
- package/dist/mora.full.mjs +659 -412
- package/dist/value/array.d.mts +5 -5
- package/dist/value/array.mjs +70 -109
- package/dist/value/computed.d.mts +5 -4
- package/dist/value/computed.mjs +45 -31
- package/dist/value/readonly.d.mts +4 -6
- package/dist/value/readonly.mjs +34 -31
- package/dist/value/signal.d.mts +5 -5
- package/dist/value/signal.mjs +28 -34
- package/dist/value/store.d.mts +5 -5
- package/dist/value/store.mjs +25 -83
- package/package.json +6 -6
- package/src/batch.ts +15 -5
- package/src/constants.ts +36 -2
- package/src/effect.ts +20 -11
- package/src/helpers/is.ts +16 -6
- package/src/helpers/misc.ts +15 -0
- package/src/helpers/proxy.ts +151 -74
- package/src/helpers/subscription.ts +89 -0
- package/src/helpers/value.ts +121 -30
- package/src/index.ts +1 -1
- package/src/models.ts +81 -98
- package/src/value/array.ts +116 -226
- package/src/value/computed.ts +96 -43
- package/src/value/readonly.ts +68 -54
- package/src/value/signal.ts +54 -46
- package/src/value/store.ts +42 -168
- package/types/constants.d.ts +1 -1
- package/types/index.d.ts +1 -1
- package/types/value/array.d.ts +1 -1
- package/types/value/computed.d.ts +0 -3
- package/types/value/signal.d.ts +1 -1
- package/types/value/store.d.ts +1 -1
- package/dist/subscription.d.mts +0 -7
- package/dist/subscription.mjs +0 -27
- package/dist/value/reactive.d.mts +0 -5
- package/dist/value/reactive.mjs +0 -16
- package/src/subscription.ts +0 -45
- package/src/value/reactive.ts +0 -24
package/dist/models.d.mts
CHANGED
|
@@ -1,39 +1,53 @@
|
|
|
1
|
-
import { PROPERTY_LENGTH } from "./constants.mjs";
|
|
1
|
+
import { PROPERTY_LENGTH, SYMBOL_EFFECT, SYMBOL_STATE } from "./constants.mjs";
|
|
2
|
+
import { Subscription, Subscriptions } from "@oscarpalmer/atoms/subscription";
|
|
2
3
|
import { GenericCallback, Key, PlainObject } from "@oscarpalmer/atoms/models";
|
|
3
4
|
//#region src/models.d.ts
|
|
4
|
-
type Active = {
|
|
5
|
+
export type Active = {
|
|
5
6
|
computed?: ComputedEffect;
|
|
6
7
|
effect?: EffectState;
|
|
7
8
|
};
|
|
8
|
-
type Batch = {
|
|
9
|
+
export type Batch = {
|
|
9
10
|
depth: number;
|
|
10
11
|
flushing: boolean;
|
|
11
|
-
handlers:
|
|
12
|
+
handlers: Map<EffectState | Subscription, EffectState | StoredSubscription>;
|
|
12
13
|
};
|
|
13
|
-
type Computed<Value> = Reactive<Value> & SimpleReactive<Value>;
|
|
14
|
-
type ComputedEffect = {
|
|
14
|
+
export type Computed<Value> = Reactive<Value> & SimpleReactive<Value>;
|
|
15
|
+
export type ComputedEffect = {
|
|
15
16
|
dirty: boolean;
|
|
16
17
|
instance: EffectState;
|
|
17
18
|
};
|
|
18
|
-
type Effect = {};
|
|
19
|
-
type EffectState = {
|
|
19
|
+
export type Effect = {};
|
|
20
|
+
export type EffectState = {
|
|
20
21
|
callback: GenericCallback;
|
|
21
22
|
};
|
|
22
|
-
type
|
|
23
|
+
export type InternalComputed = {
|
|
24
|
+
[SYMBOL_EFFECT]: ComputedEffect;
|
|
25
|
+
} & InternalSignal;
|
|
26
|
+
export type InternalProxy = {
|
|
27
|
+
[SYMBOL_STATE]: ReactiveProxyState;
|
|
28
|
+
};
|
|
29
|
+
export type InternalReadonly = {
|
|
30
|
+
frozen: boolean;
|
|
31
|
+
} & InternalSignal;
|
|
32
|
+
export type InternalSignal = {
|
|
33
|
+
[SYMBOL_STATE]: SignalState;
|
|
34
|
+
};
|
|
35
|
+
export type Reactive<Value> = {
|
|
23
36
|
/**
|
|
24
|
-
*
|
|
37
|
+
* _JSON_ representation of the value
|
|
25
38
|
*
|
|
26
|
-
* @returns
|
|
39
|
+
* @returns _JSON_ value
|
|
27
40
|
*/
|
|
28
41
|
toJSON(): Value;
|
|
29
42
|
/**
|
|
30
43
|
* String representation of the value
|
|
31
44
|
*
|
|
45
|
+
* @param json When `true`, returns the _JSON_ string representation of the value _(defaults to `false`)_
|
|
32
46
|
* @returns Value as string
|
|
33
47
|
*/
|
|
34
|
-
toString(): string;
|
|
48
|
+
toString(json?: boolean): string;
|
|
35
49
|
};
|
|
36
|
-
type ReactiveArray<Item> = {
|
|
50
|
+
export type ReactiveArray<Item> = {
|
|
37
51
|
/**
|
|
38
52
|
* The length of the array
|
|
39
53
|
*/
|
|
@@ -186,37 +200,26 @@ type ReactiveArray<Item> = {
|
|
|
186
200
|
/**
|
|
187
201
|
* Subscribe to changes
|
|
188
202
|
*
|
|
189
|
-
* @param
|
|
190
|
-
* @
|
|
203
|
+
* @param subscriber Callback for changes
|
|
204
|
+
* @param copy Copy the array? _(defaults to `false`)_
|
|
205
|
+
* @returns Subscription
|
|
191
206
|
*/
|
|
192
|
-
subscribe(
|
|
207
|
+
subscribe(subscriber: Subscriber<Item[]>, copy?: boolean): Subscription;
|
|
193
208
|
/**
|
|
194
209
|
* Subscribe to changes at a specific index
|
|
195
210
|
*
|
|
196
211
|
* @param index Index of item to subscribe to
|
|
197
|
-
* @param
|
|
198
|
-
* @
|
|
212
|
+
* @param subscriber Callback for changes
|
|
213
|
+
* @param copy If the item is an array or record, should it be copied? _(defaults to `false`)_
|
|
214
|
+
* @returns Subscription
|
|
199
215
|
*/
|
|
200
|
-
subscribe(index: number,
|
|
216
|
+
subscribe(index: number, subscriber: Subscriber<Item | undefined>, copy?: boolean): Subscription;
|
|
201
217
|
/**
|
|
202
218
|
* Add items to the beginning of the array
|
|
203
219
|
* @param items Items to add
|
|
204
220
|
* @returns New array length
|
|
205
221
|
*/
|
|
206
222
|
unshift(...items: Item[]): number;
|
|
207
|
-
/**
|
|
208
|
-
* Unsubscribe from changes for a specific index
|
|
209
|
-
*
|
|
210
|
-
* @param index Index of the value to unsubscribe from
|
|
211
|
-
* @param callback Callback to unsubscribe
|
|
212
|
-
*/
|
|
213
|
-
unsubscribe(index: number, callback: (item: Item | undefined) => void): void;
|
|
214
|
-
/**
|
|
215
|
-
* Unsubscribe from changes
|
|
216
|
-
*
|
|
217
|
-
* @param callback Callback to unsubscribe
|
|
218
|
-
*/
|
|
219
|
-
unsubscribe(callback: (array: Item[]) => void): void;
|
|
220
223
|
/**
|
|
221
224
|
* Update the value _(based on the current value)_
|
|
222
225
|
*
|
|
@@ -224,7 +227,7 @@ type ReactiveArray<Item> = {
|
|
|
224
227
|
*/
|
|
225
228
|
update(callback: (value: Item[]) => Item[]): void;
|
|
226
229
|
} & Reactive<Item[]>;
|
|
227
|
-
type ReactiveOptions<Value> = {
|
|
230
|
+
export type ReactiveOptions<Value> = {
|
|
228
231
|
/**
|
|
229
232
|
* Method for comparing values for equality
|
|
230
233
|
* @param first First value
|
|
@@ -234,16 +237,21 @@ type ReactiveOptions<Value> = {
|
|
|
234
237
|
*/
|
|
235
238
|
equal?: (first: Value, second: Value) => boolean;
|
|
236
239
|
};
|
|
237
|
-
type
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
240
|
+
export type ReactiveProxyState = {
|
|
241
|
+
isArray: boolean;
|
|
242
|
+
length?: Signal<number>;
|
|
243
|
+
mapped?: Map<string, [Computed<unknown>, ComputedEffect]>;
|
|
244
|
+
} & SignalState;
|
|
245
|
+
export type ReactiveState = {
|
|
246
|
+
computeds?: Set<ComputedEffect>;
|
|
247
|
+
effects?: Set<EffectState>;
|
|
248
|
+
equal?: (first: unknown, second: unknown) => boolean;
|
|
249
|
+
promise?: Promise<unknown>;
|
|
242
250
|
promises?: Map<Key, Promise<never>>;
|
|
243
|
-
subscriptions
|
|
244
|
-
value:
|
|
251
|
+
subscriptions?: Subscriptions<GenericCallback>;
|
|
252
|
+
value: unknown;
|
|
245
253
|
};
|
|
246
|
-
type ReactiveStore<Store> = {
|
|
254
|
+
export type ReactiveStore<Store> = {
|
|
247
255
|
/**
|
|
248
256
|
* Get a readonly version of the reactive store
|
|
249
257
|
*
|
|
@@ -331,46 +339,29 @@ type ReactiveStore<Store> = {
|
|
|
331
339
|
/**
|
|
332
340
|
* Subscribe to changes
|
|
333
341
|
*
|
|
334
|
-
* @param
|
|
335
|
-
* @
|
|
342
|
+
* @param subscriber Callback for changes
|
|
343
|
+
* @param copy Copy the store? _(defaults to `false`)_
|
|
344
|
+
* @returns Subscription
|
|
336
345
|
*/
|
|
337
|
-
subscribe(
|
|
346
|
+
subscribe(subscriber: Subscriber<Store>, copy?: boolean): Subscription;
|
|
338
347
|
/**
|
|
339
348
|
* Subscribe to changes for a specific key
|
|
340
349
|
*
|
|
341
350
|
* @param key Key of the value to subscribe to
|
|
342
|
-
* @param
|
|
343
|
-
* @
|
|
351
|
+
* @param subscriber Callback for changes
|
|
352
|
+
* @param copy If the value is an array or record, should it be copied? _(defaults to `false`)_
|
|
353
|
+
* @returns Subscription
|
|
344
354
|
*/
|
|
345
|
-
subscribe<Key extends keyof Store>(key: Key,
|
|
355
|
+
subscribe<Key extends keyof Store>(key: Key, subscriber: Subscriber<Store[Key] | undefined>, copy?: boolean): Subscription;
|
|
346
356
|
/**
|
|
347
357
|
* Subscribe to changes for a specific key
|
|
348
358
|
*
|
|
349
359
|
* @param key Key of the value to subscribe to
|
|
350
|
-
* @param
|
|
351
|
-
* @
|
|
352
|
-
|
|
353
|
-
subscribe(key: Key, callback: (value: unknown) => void): Unsubscribe;
|
|
354
|
-
/**
|
|
355
|
-
* Unsubscribe from changes for a specific key
|
|
356
|
-
*
|
|
357
|
-
* @param key Key of the value to unsubscribe from
|
|
358
|
-
* @param callback Callback to unsubscribe
|
|
359
|
-
*/
|
|
360
|
-
unsubscribe<Key extends keyof Store>(key: Key, callback: (value: Store[Key] | undefined) => void): void;
|
|
361
|
-
/**
|
|
362
|
-
* Unsubscribe from changes for a specific key
|
|
363
|
-
*
|
|
364
|
-
* @param key Key of the value to unsubscribe from
|
|
365
|
-
* @param callback Callback to unsubscribe
|
|
366
|
-
*/
|
|
367
|
-
unsubscribe(key: Key, callback: (value: unknown | undefined) => void): void;
|
|
368
|
-
/**
|
|
369
|
-
* Unsubscribe from changes
|
|
370
|
-
*
|
|
371
|
-
* @param callback Callback to unsubscribe
|
|
360
|
+
* @param subscriber Callback for changes
|
|
361
|
+
* @param copy If the value is an array or record, should it be copied? _(defaults to `false`)_
|
|
362
|
+
* @returns Subscription
|
|
372
363
|
*/
|
|
373
|
-
|
|
364
|
+
subscribe(key: Key, subscriber: Subscriber<unknown>, copy?: boolean): Subscription;
|
|
374
365
|
/**
|
|
375
366
|
* Update the value _(based on the current value)_
|
|
376
367
|
*
|
|
@@ -382,23 +373,15 @@ type ReadonlyInstances<Value> = {
|
|
|
382
373
|
frozen?: ReadonlyFrozenSignal<Value>;
|
|
383
374
|
original?: ReadonlySignal<Value>;
|
|
384
375
|
};
|
|
385
|
-
type ReadonlyFrozenSignal<Value> = ReadonlySignal<ReadonlySignalValue<Value>>;
|
|
386
|
-
type ReadonlySignal<Value> = {
|
|
376
|
+
export type ReadonlyFrozenSignal<Value> = ReadonlySignal<ReadonlySignalValue<Value>>;
|
|
377
|
+
export type ReadonlySignal<Value> = {
|
|
387
378
|
/**
|
|
388
379
|
* Is the signal frozen?
|
|
389
380
|
*/
|
|
390
381
|
get frozen(): boolean;
|
|
391
382
|
} & Reactive<Value> & SimpleReactive<Value>;
|
|
392
|
-
type ReadonlySignalValue<Value> = Value extends unknown[] ? Readonly<Value> : Value extends PlainObject ? Readonly<Value> : Value;
|
|
393
|
-
type
|
|
394
|
-
target: Value;
|
|
395
|
-
property: PropertyKey;
|
|
396
|
-
value: unknown;
|
|
397
|
-
state: ReactiveState<Value, Equal>;
|
|
398
|
-
isArray: boolean;
|
|
399
|
-
length?: Signal<number>;
|
|
400
|
-
};
|
|
401
|
-
type Signal<Value> = {
|
|
383
|
+
export type ReadonlySignalValue<Value> = Value extends unknown[] ? Readonly<Value> : Value extends PlainObject ? Readonly<Value> : Value;
|
|
384
|
+
export type Signal<Value> = {
|
|
402
385
|
/**
|
|
403
386
|
* Get a readonly version of the signal
|
|
404
387
|
*
|
|
@@ -426,6 +409,9 @@ type Signal<Value> = {
|
|
|
426
409
|
*/
|
|
427
410
|
update(callback: (value: Value) => Value): void;
|
|
428
411
|
} & Reactive<Value> & SimpleReactive<Value>;
|
|
412
|
+
export type SignalState = {
|
|
413
|
+
readonlies?: ReadonlyInstances<unknown>;
|
|
414
|
+
} & ReactiveState;
|
|
429
415
|
type SimpleReactive<Value> = {
|
|
430
416
|
/**
|
|
431
417
|
* Get the value
|
|
@@ -436,31 +422,26 @@ type SimpleReactive<Value> = {
|
|
|
436
422
|
/**
|
|
437
423
|
* Get the value _(without reactivity)_
|
|
438
424
|
*
|
|
425
|
+
* @param copy If the value is an array or record, should it be copied? _(defaults to `false`)_
|
|
439
426
|
* @returns Current value
|
|
440
427
|
*/
|
|
441
|
-
peek(): Value;
|
|
428
|
+
peek(copy?: boolean): Value;
|
|
442
429
|
/**
|
|
443
430
|
* Subscribe to changes
|
|
444
431
|
*
|
|
445
|
-
* @param
|
|
446
|
-
* @
|
|
447
|
-
|
|
448
|
-
subscribe(callback: (value: Value) => void): Unsubscribe;
|
|
449
|
-
/**
|
|
450
|
-
* Unsubscribe from changes
|
|
451
|
-
*
|
|
452
|
-
* @param callback Callback to unsubscribe
|
|
432
|
+
* @param subscriber Callback for changes
|
|
433
|
+
* @param copy If the value is an array or record, should it be copied? _(defaults to `false`)_
|
|
434
|
+
* @returns Subscription
|
|
453
435
|
*/
|
|
454
|
-
|
|
436
|
+
subscribe(subscriber: Subscriber<Value>, copy?: boolean): Subscription;
|
|
455
437
|
};
|
|
456
|
-
type
|
|
438
|
+
export type StoredSubscription = {
|
|
457
439
|
callback: GenericCallback;
|
|
458
|
-
|
|
459
|
-
|
|
440
|
+
copy: boolean;
|
|
441
|
+
frozen: boolean;
|
|
442
|
+
instance: InternalSignal;
|
|
443
|
+
state: SignalState;
|
|
460
444
|
};
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
type Unsubscribe = () => void;
|
|
465
|
-
//#endregion
|
|
466
|
-
export { Active, Batch, Computed, ComputedEffect, Effect, EffectState, Reactive, ReactiveArray, ReactiveOptions, ReactiveState, ReactiveStore, ReadonlyFrozenSignal, ReadonlyInstances, ReadonlySignal, ReadonlySignalValue, SetValueInProxyParameters, Signal, Subscription, Unsubscribe };
|
|
445
|
+
export type Subscriber<Value> = (value: Value, subscription: Subscription) => void;
|
|
446
|
+
export type SubscriptionType = 'copy' | 'frozen' | 'original' | 'readonly';
|
|
447
|
+
//#endregion
|
package/dist/models.mjs
CHANGED