@oscarpalmer/mora 0.31.0 → 0.32.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 +29 -19
- package/dist/constants.mjs +17 -2
- package/dist/effect.d.mts +4 -5
- package/dist/effect.mjs +2 -2
- package/dist/helpers/is.d.mts +14 -9
- package/dist/helpers/is.mjs +6 -0
- package/dist/helpers/proxy.d.mts +12 -10
- package/dist/helpers/proxy.mjs +32 -14
- package/dist/helpers/subscription.d.mts +8 -0
- package/dist/helpers/subscription.mjs +27 -0
- package/dist/helpers/value.d.mts +8 -6
- package/dist/helpers/value.mjs +30 -4
- package/dist/index.d.mts +3 -2
- package/dist/models.d.mts +45 -87
- package/dist/mora.full.mjs +461 -285
- package/dist/value/array.d.mts +4 -5
- package/dist/value/array.mjs +22 -69
- package/dist/value/computed.d.mts +3 -4
- package/dist/value/computed.mjs +14 -14
- package/dist/value/reactive.d.mts +2 -3
- package/dist/value/reactive.mjs +0 -1
- package/dist/value/readonly.d.mts +3 -5
- package/dist/value/readonly.mjs +15 -19
- package/dist/value/signal.d.mts +4 -5
- package/dist/value/signal.mjs +9 -22
- package/dist/value/store.d.mts +4 -5
- package/dist/value/store.mjs +16 -56
- package/package.json +6 -6
- package/src/batch.ts +15 -5
- package/src/constants.ts +32 -2
- package/src/effect.ts +6 -2
- package/src/helpers/is.ts +10 -0
- package/src/helpers/proxy.ts +99 -49
- package/src/helpers/subscription.ts +78 -0
- package/src/helpers/value.ts +69 -4
- package/src/index.ts +1 -1
- package/src/models.ts +38 -81
- package/src/value/array.ts +61 -150
- package/src/value/computed.ts +36 -13
- package/src/value/reactive.ts +8 -5
- package/src/value/readonly.ts +26 -25
- package/src/value/signal.ts +19 -22
- package/src/value/store.ts +35 -114
- 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/src/subscription.ts +0 -45
package/dist/models.d.mts
CHANGED
|
@@ -1,25 +1,26 @@
|
|
|
1
1
|
import { PROPERTY_LENGTH } 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 Reactive<Value> = {
|
|
23
|
+
export type Reactive<Value> = {
|
|
23
24
|
/**
|
|
24
25
|
* JSON representation of the value
|
|
25
26
|
*
|
|
@@ -33,7 +34,7 @@ type Reactive<Value> = {
|
|
|
33
34
|
*/
|
|
34
35
|
toString(): string;
|
|
35
36
|
};
|
|
36
|
-
type ReactiveArray<Item> = {
|
|
37
|
+
export type ReactiveArray<Item> = {
|
|
37
38
|
/**
|
|
38
39
|
* The length of the array
|
|
39
40
|
*/
|
|
@@ -187,36 +188,25 @@ type ReactiveArray<Item> = {
|
|
|
187
188
|
* Subscribe to changes
|
|
188
189
|
*
|
|
189
190
|
* @param callback Callback for changes
|
|
190
|
-
* @
|
|
191
|
+
* @param copy Copy the array? _(defaults to `false`)_
|
|
192
|
+
* @returns Subscription
|
|
191
193
|
*/
|
|
192
|
-
subscribe(callback: (value: Item[]) => void):
|
|
194
|
+
subscribe(callback: (value: Item[]) => void, copy?: boolean): Subscription;
|
|
193
195
|
/**
|
|
194
196
|
* Subscribe to changes at a specific index
|
|
195
197
|
*
|
|
196
198
|
* @param index Index of item to subscribe to
|
|
197
199
|
* @param callback Callback for changes
|
|
198
|
-
* @
|
|
200
|
+
* @param copy If the item is an array or record, should it be copied? _(defaults to `false`)_
|
|
201
|
+
* @returns Subscription
|
|
199
202
|
*/
|
|
200
|
-
subscribe(index: number, callback: (value: Item | undefined) => void):
|
|
203
|
+
subscribe(index: number, callback: (value: Item | undefined) => void, copy?: boolean): Subscription;
|
|
201
204
|
/**
|
|
202
205
|
* Add items to the beginning of the array
|
|
203
206
|
* @param items Items to add
|
|
204
207
|
* @returns New array length
|
|
205
208
|
*/
|
|
206
209
|
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
210
|
/**
|
|
221
211
|
* Update the value _(based on the current value)_
|
|
222
212
|
*
|
|
@@ -224,7 +214,7 @@ type ReactiveArray<Item> = {
|
|
|
224
214
|
*/
|
|
225
215
|
update(callback: (value: Item[]) => Item[]): void;
|
|
226
216
|
} & Reactive<Item[]>;
|
|
227
|
-
type ReactiveOptions<Value> = {
|
|
217
|
+
export type ReactiveOptions<Value> = {
|
|
228
218
|
/**
|
|
229
219
|
* Method for comparing values for equality
|
|
230
220
|
* @param first First value
|
|
@@ -234,16 +224,16 @@ type ReactiveOptions<Value> = {
|
|
|
234
224
|
*/
|
|
235
225
|
equal?: (first: Value, second: Value) => boolean;
|
|
236
226
|
};
|
|
237
|
-
type ReactiveState<Value,
|
|
227
|
+
export type ReactiveState<Value, Item = Value> = {
|
|
238
228
|
computeds: Set<ComputedEffect>;
|
|
239
229
|
effects: Set<EffectState>;
|
|
240
|
-
equal: (first:
|
|
230
|
+
equal: (first: Item, second: Item) => boolean;
|
|
241
231
|
promise?: Promise<Value>;
|
|
242
232
|
promises?: Map<Key, Promise<never>>;
|
|
243
|
-
subscriptions
|
|
233
|
+
subscriptions?: Subscriptions<GenericCallback>;
|
|
244
234
|
value: Value;
|
|
245
235
|
};
|
|
246
|
-
type ReactiveStore<Store> = {
|
|
236
|
+
export type ReactiveStore<Store> = {
|
|
247
237
|
/**
|
|
248
238
|
* Get a readonly version of the reactive store
|
|
249
239
|
*
|
|
@@ -332,45 +322,28 @@ type ReactiveStore<Store> = {
|
|
|
332
322
|
* Subscribe to changes
|
|
333
323
|
*
|
|
334
324
|
* @param callback Callback for changes
|
|
335
|
-
* @
|
|
325
|
+
* @param copy Copy the store? _(defaults to `false`)_
|
|
326
|
+
* @returns Subscription
|
|
336
327
|
*/
|
|
337
|
-
subscribe(callback: (value: Store) => void):
|
|
328
|
+
subscribe(callback: (value: Store) => void, copy?: boolean): Subscription;
|
|
338
329
|
/**
|
|
339
330
|
* Subscribe to changes for a specific key
|
|
340
331
|
*
|
|
341
332
|
* @param key Key of the value to subscribe to
|
|
342
333
|
* @param callback Callback for changes
|
|
343
|
-
* @
|
|
334
|
+
* @param copy If the value is an array or record, should it be copied? _(defaults to `false`)_
|
|
335
|
+
* @returns Subscription
|
|
344
336
|
*/
|
|
345
|
-
subscribe<Key extends keyof Store>(key: Key, callback: (value: Store[Key] | undefined) => void):
|
|
337
|
+
subscribe<Key extends keyof Store>(key: Key, callback: (value: Store[Key] | undefined) => void, copy?: boolean): Subscription;
|
|
346
338
|
/**
|
|
347
339
|
* Subscribe to changes for a specific key
|
|
348
340
|
*
|
|
349
341
|
* @param key Key of the value to subscribe to
|
|
350
342
|
* @param callback Callback for changes
|
|
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
|
|
343
|
+
* @param copy If the value is an array or record, should it be copied? _(defaults to `false`)_
|
|
344
|
+
* @returns Subscription
|
|
372
345
|
*/
|
|
373
|
-
|
|
346
|
+
subscribe(key: Key, callback: (value: unknown) => void, copy?: boolean): Subscription;
|
|
374
347
|
/**
|
|
375
348
|
* Update the value _(based on the current value)_
|
|
376
349
|
*
|
|
@@ -378,27 +351,19 @@ type ReactiveStore<Store> = {
|
|
|
378
351
|
*/
|
|
379
352
|
update(callback: (value: Store) => Store): void;
|
|
380
353
|
} & Reactive<Store>;
|
|
381
|
-
type ReadonlyInstances<Value> = {
|
|
354
|
+
export type ReadonlyInstances<Value> = {
|
|
382
355
|
frozen?: ReadonlyFrozenSignal<Value>;
|
|
383
356
|
original?: ReadonlySignal<Value>;
|
|
384
357
|
};
|
|
385
|
-
type ReadonlyFrozenSignal<Value> = ReadonlySignal<ReadonlySignalValue<Value>>;
|
|
386
|
-
type ReadonlySignal<Value> = {
|
|
358
|
+
export type ReadonlyFrozenSignal<Value> = ReadonlySignal<ReadonlySignalValue<Value>>;
|
|
359
|
+
export type ReadonlySignal<Value> = {
|
|
387
360
|
/**
|
|
388
361
|
* Is the signal frozen?
|
|
389
362
|
*/
|
|
390
363
|
get frozen(): boolean;
|
|
391
364
|
} & 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> = {
|
|
365
|
+
export type ReadonlySignalValue<Value> = Value extends unknown[] ? Readonly<Value> : Value extends PlainObject ? Readonly<Value> : Value;
|
|
366
|
+
export type Signal<Value> = {
|
|
402
367
|
/**
|
|
403
368
|
* Get a readonly version of the signal
|
|
404
369
|
*
|
|
@@ -436,31 +401,24 @@ type SimpleReactive<Value> = {
|
|
|
436
401
|
/**
|
|
437
402
|
* Get the value _(without reactivity)_
|
|
438
403
|
*
|
|
404
|
+
* @param copy If the value is an array or record, should it be copied? _(defaults to `false`)_
|
|
439
405
|
* @returns Current value
|
|
440
406
|
*/
|
|
441
|
-
peek(): Value;
|
|
407
|
+
peek(copy?: boolean): Value;
|
|
442
408
|
/**
|
|
443
409
|
* Subscribe to changes
|
|
444
410
|
*
|
|
445
411
|
* @param callback Callback for changes
|
|
446
|
-
* @
|
|
447
|
-
|
|
448
|
-
subscribe(callback: (value: Value) => void): Unsubscribe;
|
|
449
|
-
/**
|
|
450
|
-
* Unsubscribe from changes
|
|
451
|
-
*
|
|
452
|
-
* @param callback Callback to unsubscribe
|
|
412
|
+
* @param copy If the value is an array or record, should it be copied? _(defaults to `false`)_
|
|
413
|
+
* @returns Subscription
|
|
453
414
|
*/
|
|
454
|
-
|
|
415
|
+
subscribe(callback: (value: Value) => void, copy?: boolean): Subscription;
|
|
455
416
|
};
|
|
456
|
-
type
|
|
417
|
+
export type StoredSubscription = {
|
|
457
418
|
callback: GenericCallback;
|
|
419
|
+
copy: boolean;
|
|
420
|
+
frozen: boolean;
|
|
458
421
|
state: ReactiveState<unknown, never>;
|
|
459
|
-
destroy(): void;
|
|
460
422
|
};
|
|
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 };
|
|
423
|
+
export type SubscriptionType = 'copy' | 'frozen' | 'original' | 'readonly';
|
|
424
|
+
//#endregion
|