@oscarpalmer/mora 0.38.0 → 0.39.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 +1 -3
- package/dist/batch.mjs +3 -4
- package/dist/constants.d.mts +16 -10
- package/dist/constants.mjs +12 -6
- package/dist/effect.d.mts +2 -3
- package/dist/effect.mjs +27 -8
- package/dist/helpers/is.d.mts +1 -3
- package/dist/helpers/is.mjs +8 -5
- package/dist/helpers/misc.d.mts +8 -4
- package/dist/helpers/misc.mjs +66 -4
- package/dist/helpers/proxy.d.mts +3 -4
- package/dist/helpers/proxy.mjs +26 -11
- package/dist/helpers/subscription.d.mts +1 -3
- package/dist/helpers/subscription.mjs +15 -7
- package/dist/helpers/value.d.mts +4 -5
- package/dist/helpers/value.mjs +18 -13
- package/dist/models.d.mts +38 -5
- package/dist/mora.full.mjs +555 -276
- package/dist/value/array.d.mts +1 -3
- package/dist/value/array.mjs +46 -22
- package/dist/value/computed.d.mts +1 -3
- package/dist/value/computed.mjs +17 -11
- package/dist/value/readonly.d.mts +2 -5
- package/dist/value/readonly.mjs +24 -16
- package/dist/value/signal.d.mts +1 -3
- package/dist/value/signal.mjs +9 -6
- package/dist/value/store.d.mts +1 -3
- package/dist/value/store.mjs +9 -6
- package/package.json +5 -12
- package/src/batch.ts +8 -4
- package/src/constants.ts +26 -16
- package/src/effect.ts +37 -7
- package/src/helpers/is.ts +18 -8
- package/src/helpers/misc.ts +121 -2
- package/src/helpers/proxy.ts +59 -9
- package/src/helpers/subscription.ts +34 -4
- package/src/helpers/value.ts +48 -15
- package/src/models.ts +42 -3
- package/src/value/array.ts +100 -21
- package/src/value/computed.ts +29 -10
- package/src/value/readonly.ts +38 -33
- package/src/value/signal.ts +11 -5
- package/src/value/store.ts +11 -5
- package/types/batch.d.ts +0 -11
- package/types/constants.d.ts +0 -16
- package/types/effect.d.ts +0 -13
- package/types/helpers/is.d.ts +0 -43
- package/types/helpers/proxy.d.ts +0 -11
- package/types/helpers/value.d.ts +0 -4
- package/types/index.d.ts +0 -9
- package/types/models.d.ts +0 -56
- package/types/subscription.d.ts +0 -11
- package/types/value/array.d.ts +0 -137
- package/types/value/computed.d.ts +0 -14
- package/types/value/reactive.d.ts +0 -36
- package/types/value/signal.d.ts +0 -26
- package/types/value/store.d.ts +0 -94
package/types/models.d.ts
DELETED
|
@@ -1,56 +0,0 @@
|
|
|
1
|
-
import type { GenericCallback } from '@oscarpalmer/atoms/models';
|
|
2
|
-
import type { Effect } from './effect';
|
|
3
|
-
import type { Subscription } from './subscription';
|
|
4
|
-
import type { Computed } from './value/computed';
|
|
5
|
-
import type { Signal } from './value/signal';
|
|
6
|
-
export type Active = {
|
|
7
|
-
computed?: Computed<unknown>;
|
|
8
|
-
effect?: Effect;
|
|
9
|
-
};
|
|
10
|
-
export type Batch = {
|
|
11
|
-
depth: number;
|
|
12
|
-
handlers: Set<Effect | Subscription>;
|
|
13
|
-
};
|
|
14
|
-
export type ComputedEffect = {
|
|
15
|
-
dirty: boolean;
|
|
16
|
-
instance: Effect;
|
|
17
|
-
};
|
|
18
|
-
export type EffectState = {
|
|
19
|
-
callback: GenericCallback;
|
|
20
|
-
};
|
|
21
|
-
export type InternalComputed = {
|
|
22
|
-
readonly effect: ComputedEffect;
|
|
23
|
-
readonly state: ReactiveState<unknown, unknown>;
|
|
24
|
-
};
|
|
25
|
-
export type InternalEffect = {
|
|
26
|
-
state: EffectState;
|
|
27
|
-
};
|
|
28
|
-
export type ReactiveOptions<Value> = {
|
|
29
|
-
/**
|
|
30
|
-
* Method for comparing values for equality
|
|
31
|
-
* @param first First value
|
|
32
|
-
* @param second Second value
|
|
33
|
-
* @returns Are the values equal?
|
|
34
|
-
* @default Object.is
|
|
35
|
-
*/
|
|
36
|
-
equal?: (first: Value, second: Value) => boolean;
|
|
37
|
-
};
|
|
38
|
-
export type ReactiveState<Value, Equal> = {
|
|
39
|
-
computeds: Set<Computed<unknown>>;
|
|
40
|
-
effects: Set<Effect>;
|
|
41
|
-
equal: (first: Equal, second: Equal) => boolean;
|
|
42
|
-
subscriptions: Map<GenericCallback, Subscription>;
|
|
43
|
-
value: Value;
|
|
44
|
-
};
|
|
45
|
-
export type SetValueInProxyParameters<Value, Equal> = {
|
|
46
|
-
target: Value;
|
|
47
|
-
property: PropertyKey;
|
|
48
|
-
value: unknown;
|
|
49
|
-
state: ReactiveState<Value, Equal>;
|
|
50
|
-
isArray: boolean;
|
|
51
|
-
length?: Signal<number>;
|
|
52
|
-
};
|
|
53
|
-
/**
|
|
54
|
-
* Unsubscribe from changes
|
|
55
|
-
*/
|
|
56
|
-
export type Unsubscribe = () => void;
|
package/types/subscription.d.ts
DELETED
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import type { GenericCallback } from '@oscarpalmer/atoms/models';
|
|
2
|
-
import type { ReactiveState, Unsubscribe } from './models';
|
|
3
|
-
export declare class Subscription {
|
|
4
|
-
callback: GenericCallback;
|
|
5
|
-
state: ReactiveState<unknown, never>;
|
|
6
|
-
constructor(state: ReactiveState<unknown, never>, callback: GenericCallback);
|
|
7
|
-
destroy(): void;
|
|
8
|
-
}
|
|
9
|
-
export declare function noop(): void;
|
|
10
|
-
export declare function subscribe<Value>(state: ReactiveState<Value, never>, callback: (value: Value) => void): Unsubscribe;
|
|
11
|
-
export declare function unsubscribe<Value>(state: ReactiveState<Value, never>, callback: (value: Value) => void): void;
|
package/types/value/array.d.ts
DELETED
|
@@ -1,137 +0,0 @@
|
|
|
1
|
-
import type { ReactiveOptions, Unsubscribe } from '../models';
|
|
2
|
-
import { type Computed } from './computed';
|
|
3
|
-
import { Reactive } from './reactive';
|
|
4
|
-
export declare class ReactiveArray<Item> extends Reactive<Item[], Item> {
|
|
5
|
-
#private;
|
|
6
|
-
/**
|
|
7
|
-
* The length of the array
|
|
8
|
-
*/
|
|
9
|
-
get length(): number;
|
|
10
|
-
/**
|
|
11
|
-
* Set the length of the array
|
|
12
|
-
*/
|
|
13
|
-
set length(value: number);
|
|
14
|
-
constructor(value: Item[], options?: ReactiveOptions<Item>);
|
|
15
|
-
/**
|
|
16
|
-
* Clear the array
|
|
17
|
-
*/
|
|
18
|
-
clear(): void;
|
|
19
|
-
/**
|
|
20
|
-
* Create a computed, filtered array
|
|
21
|
-
* @param callback Callback to evaluate each item
|
|
22
|
-
* @return Computed array of filtered items
|
|
23
|
-
*/
|
|
24
|
-
filter(callback: (item: Item, index: number, array: Item[]) => boolean): Computed<Item[]>;
|
|
25
|
-
/**
|
|
26
|
-
* @inheritdoc
|
|
27
|
-
*/
|
|
28
|
-
get(): Item[];
|
|
29
|
-
/**
|
|
30
|
-
* Get the value at an index
|
|
31
|
-
* @param index Index of item to get _(if negative, starts from the end)_
|
|
32
|
-
* @returns Item at index, or `undefined` if it doesn't exist
|
|
33
|
-
*/
|
|
34
|
-
get(index: number): Item | undefined;
|
|
35
|
-
/**
|
|
36
|
-
* Get the length of the array
|
|
37
|
-
* @returns Length of the array
|
|
38
|
-
*/
|
|
39
|
-
get(property: 'length'): number;
|
|
40
|
-
/**
|
|
41
|
-
* Create a computed, mapped array
|
|
42
|
-
* @param callback Callback to transform each item
|
|
43
|
-
* @return Computed array of mapped items
|
|
44
|
-
*/
|
|
45
|
-
map<Mapped>(callback: (item: Item, index: number, array: Item[]) => Mapped): Computed<Mapped[]>;
|
|
46
|
-
/**
|
|
47
|
-
* Notify dependents of changes
|
|
48
|
-
*
|
|
49
|
-
* _This bypasses equality checks and will immediately notify dependents.
|
|
50
|
-
* Use this only if you're modifying nested data that would be ignored by equality checks._
|
|
51
|
-
*/
|
|
52
|
-
notify(): void;
|
|
53
|
-
/**
|
|
54
|
-
* @inheritdoc
|
|
55
|
-
*/
|
|
56
|
-
peek(): Item[];
|
|
57
|
-
/**
|
|
58
|
-
* Get the value at an index _(without reactivity)_
|
|
59
|
-
* @param index Index of item to get _(if negative, starts from the end)_
|
|
60
|
-
* @returns Item at index, or `undefined` if it doesn't exist
|
|
61
|
-
*/
|
|
62
|
-
peek(index: number): Item | undefined;
|
|
63
|
-
/**
|
|
64
|
-
* Get the length of the array _(without reactivity)_
|
|
65
|
-
* @returns Length of the array
|
|
66
|
-
*/
|
|
67
|
-
peek(property: 'length'): number;
|
|
68
|
-
/**
|
|
69
|
-
* Remove and return the last item of the array
|
|
70
|
-
* @returns Removed item, or `undefined` if the array is empty
|
|
71
|
-
*/
|
|
72
|
-
pop(): Item | undefined;
|
|
73
|
-
/**
|
|
74
|
-
* Add items to the end of the array
|
|
75
|
-
* @param items Items to add
|
|
76
|
-
* @returns New array length
|
|
77
|
-
*/
|
|
78
|
-
push(...items: Item[]): number;
|
|
79
|
-
/**
|
|
80
|
-
* Set the value
|
|
81
|
-
* @param value New array of items _(defaults to an empty array)_
|
|
82
|
-
*/
|
|
83
|
-
set(value?: Item[]): void;
|
|
84
|
-
/**
|
|
85
|
-
* Set the value at an index
|
|
86
|
-
* @param index Index of item to set __(if negative, starts from the end)_
|
|
87
|
-
* @param value New item
|
|
88
|
-
*/
|
|
89
|
-
set(index: number, value: Item): void;
|
|
90
|
-
/**
|
|
91
|
-
* Set the length of the array
|
|
92
|
-
* @param value New array length
|
|
93
|
-
*/
|
|
94
|
-
set(property: 'length', value: number): void;
|
|
95
|
-
/**
|
|
96
|
-
* Remove and return the first item of the array
|
|
97
|
-
* @returns Removed item, or `undefined` if the array is empty
|
|
98
|
-
*/
|
|
99
|
-
shift(): Item | undefined;
|
|
100
|
-
/**
|
|
101
|
-
* Remove and return items from the array _(and optionally add new items)_
|
|
102
|
-
* @param from Index to start removing items from
|
|
103
|
-
* @param to Index to stop removing items at _(defaults to the end of the array)_
|
|
104
|
-
* @param items Optional items to add
|
|
105
|
-
* @returns Removed items
|
|
106
|
-
*/
|
|
107
|
-
splice(from: number, to?: number, ...items: Item[]): Item[];
|
|
108
|
-
/**
|
|
109
|
-
* @inheritdoc
|
|
110
|
-
*/
|
|
111
|
-
subscribe(callback: (value: Item[]) => void): Unsubscribe;
|
|
112
|
-
/**
|
|
113
|
-
* Subscribe to changes at a specific index
|
|
114
|
-
* @param index Index of item to subscribe to
|
|
115
|
-
* @param callback Callback for changes
|
|
116
|
-
* @returns Unsubscribe callback
|
|
117
|
-
*/
|
|
118
|
-
subscribe(index: number, callback: (value: Item | undefined) => void): Unsubscribe;
|
|
119
|
-
/**
|
|
120
|
-
* Add items to the beginning of the array
|
|
121
|
-
* @param items Items to add
|
|
122
|
-
* @returns New array length
|
|
123
|
-
*/
|
|
124
|
-
unshift(...items: Item[]): number;
|
|
125
|
-
/**
|
|
126
|
-
* Update the value _(based on the current value)_
|
|
127
|
-
* @param callback Callback to update the value
|
|
128
|
-
*/
|
|
129
|
-
update(callback: (value: Item[]) => Item[]): void;
|
|
130
|
-
}
|
|
131
|
-
/**
|
|
132
|
-
* Create a reactive array
|
|
133
|
-
* @param value Initial array of items
|
|
134
|
-
* @param options Optional reactivity options
|
|
135
|
-
* @returns Reactive array
|
|
136
|
-
*/
|
|
137
|
-
export declare function array<Item>(value: Item[], options?: ReactiveOptions<Item>): ReactiveArray<Item>;
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
import type { ReactiveOptions } from '../models';
|
|
2
|
-
import { Reactive } from './reactive';
|
|
3
|
-
export declare class Computed<Value> extends Reactive<Value> {
|
|
4
|
-
private readonly effect;
|
|
5
|
-
constructor(callback: () => Value, options?: ReactiveOptions<Value>);
|
|
6
|
-
/**
|
|
7
|
-
* @inheritdoc
|
|
8
|
-
*/
|
|
9
|
-
get(): Value;
|
|
10
|
-
}
|
|
11
|
-
/**
|
|
12
|
-
* Create a computed value
|
|
13
|
-
*/
|
|
14
|
-
export declare function computed<Value>(callback: () => Value, options?: ReactiveOptions<Value>): Computed<Value>;
|
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
import type { ReactiveOptions, ReactiveState, Unsubscribe } from '../models';
|
|
2
|
-
export declare abstract class Reactive<Value, Equal = Value> {
|
|
3
|
-
protected readonly state: ReactiveState<Value, Equal>;
|
|
4
|
-
constructor(name: string, value: Value, options?: ReactiveOptions<Equal>);
|
|
5
|
-
/**
|
|
6
|
-
* Get the value
|
|
7
|
-
* @return Current value
|
|
8
|
-
*/
|
|
9
|
-
abstract get(): Value;
|
|
10
|
-
/**
|
|
11
|
-
* Get the value _(without reactivity)_
|
|
12
|
-
* @return Current value
|
|
13
|
-
*/
|
|
14
|
-
peek(): Value;
|
|
15
|
-
/**
|
|
16
|
-
* Subscribe to changes
|
|
17
|
-
* @param callback Callback for changes
|
|
18
|
-
* @return Unsubscribe callback
|
|
19
|
-
*/
|
|
20
|
-
subscribe(callback: (value: Value) => void): Unsubscribe;
|
|
21
|
-
/**
|
|
22
|
-
* JSON representation of the value
|
|
23
|
-
* @return JSON value
|
|
24
|
-
*/
|
|
25
|
-
toJSON(): Value;
|
|
26
|
-
/**
|
|
27
|
-
* String representation of the value
|
|
28
|
-
* @return Value as string
|
|
29
|
-
*/
|
|
30
|
-
toString(): string;
|
|
31
|
-
/**
|
|
32
|
-
* Unsubscribe from changes
|
|
33
|
-
* @param callback Callback to unsubscribe
|
|
34
|
-
*/
|
|
35
|
-
unsubscribe(callback: (value: Value) => void): void;
|
|
36
|
-
}
|
package/types/value/signal.d.ts
DELETED
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
import type { ReactiveOptions } from '../models';
|
|
2
|
-
import { Reactive } from './reactive';
|
|
3
|
-
export declare class Signal<Value> extends Reactive<Value> {
|
|
4
|
-
constructor(value: Value, options?: ReactiveOptions<Value>);
|
|
5
|
-
/**
|
|
6
|
-
* @inheritdoc
|
|
7
|
-
*/
|
|
8
|
-
get(): Value;
|
|
9
|
-
/**
|
|
10
|
-
* Set the value
|
|
11
|
-
* @param value New value
|
|
12
|
-
*/
|
|
13
|
-
set(value: Value): void;
|
|
14
|
-
/**
|
|
15
|
-
* Update the value _(based on the current value)_
|
|
16
|
-
* @param callback Callback to update the value
|
|
17
|
-
*/
|
|
18
|
-
update(callback: (value: Value) => Value): void;
|
|
19
|
-
}
|
|
20
|
-
/**
|
|
21
|
-
* Create a reactive value
|
|
22
|
-
* @param value Initial value
|
|
23
|
-
* @param options Optional reactivity options
|
|
24
|
-
* @returns Reactive value
|
|
25
|
-
*/
|
|
26
|
-
export declare function signal<Value>(value: Value, options?: ReactiveOptions<Value>): Signal<Value>;
|
package/types/value/store.d.ts
DELETED
|
@@ -1,94 +0,0 @@
|
|
|
1
|
-
import type { Key, PlainObject } from '@oscarpalmer/atoms/models';
|
|
2
|
-
import type { ReactiveOptions, Unsubscribe } from '../models';
|
|
3
|
-
import { Reactive } from './reactive';
|
|
4
|
-
export declare class Store<Value extends PlainObject> extends Reactive<Value, Value> {
|
|
5
|
-
#private;
|
|
6
|
-
constructor(value: Value, options?: ReactiveOptions<Value>);
|
|
7
|
-
/**
|
|
8
|
-
* @inheritdoc
|
|
9
|
-
*/
|
|
10
|
-
get(): Value;
|
|
11
|
-
/**
|
|
12
|
-
* Get a value by key
|
|
13
|
-
* @param key Key of the value to get
|
|
14
|
-
* @returns Value for the specified key, or `undefined` if it doesn't exist
|
|
15
|
-
*/
|
|
16
|
-
get<Key extends keyof Value>(key: Key): Value[Key];
|
|
17
|
-
/**
|
|
18
|
-
* Get a value by key
|
|
19
|
-
* @param key Key of the value to get
|
|
20
|
-
* @returns Value for the specified key, or `undefined` if it doesn't exist
|
|
21
|
-
*/
|
|
22
|
-
get(key: Key): unknown;
|
|
23
|
-
/**
|
|
24
|
-
* Notify dependents of changes
|
|
25
|
-
*
|
|
26
|
-
* _This bypasses equality checks and will immediately notify dependents.
|
|
27
|
-
* Use this only if you're modifying nested data that would be ignored by equality checks._
|
|
28
|
-
*/
|
|
29
|
-
notify(): void;
|
|
30
|
-
/**
|
|
31
|
-
* Get the value _(without reactivity)_
|
|
32
|
-
* @returns The current value
|
|
33
|
-
*/
|
|
34
|
-
peek(): Value;
|
|
35
|
-
/**
|
|
36
|
-
* Get a value by key _(without reactivity)_
|
|
37
|
-
* @param key Key of the value to get
|
|
38
|
-
* @returns Value for the specified key, or `undefined` if it doesn't exist
|
|
39
|
-
*/
|
|
40
|
-
peek<Key extends keyof Value>(key: Key): Value[Key];
|
|
41
|
-
/**
|
|
42
|
-
* Get a value by key _(without reactivity)_
|
|
43
|
-
* @param key Key of the value to get
|
|
44
|
-
* @returns Value for the specified key, or `undefined` if it doesn't exist
|
|
45
|
-
*/
|
|
46
|
-
peek(key: Key): unknown;
|
|
47
|
-
/**
|
|
48
|
-
* Set the value
|
|
49
|
-
* @param value New value _(defaults to an empty object)_
|
|
50
|
-
*/
|
|
51
|
-
set(value?: Value): void;
|
|
52
|
-
/**
|
|
53
|
-
* Set a value by key
|
|
54
|
-
* @param key Key of the value to set
|
|
55
|
-
* @param value New value
|
|
56
|
-
*/
|
|
57
|
-
set<Key extends keyof Value>(key: Key, value: Value[Key]): void;
|
|
58
|
-
/**
|
|
59
|
-
* Set a value by key
|
|
60
|
-
* @param key Key of the value to set
|
|
61
|
-
* @param value New value
|
|
62
|
-
*/
|
|
63
|
-
set(key: Key, value: unknown): void;
|
|
64
|
-
/**
|
|
65
|
-
* @inheritdoc
|
|
66
|
-
*/
|
|
67
|
-
subscribe(callback: (value: Value) => void): Unsubscribe;
|
|
68
|
-
/**
|
|
69
|
-
* Subscribe to changes for a specific key
|
|
70
|
-
* @param key Key of the value to subscribe to
|
|
71
|
-
* @param callback Callback for changes
|
|
72
|
-
* @returns Unsubscribe callback
|
|
73
|
-
*/
|
|
74
|
-
subscribe<Key extends keyof Value>(key: Key, callback: (value: Value[Key] | undefined) => void): Unsubscribe;
|
|
75
|
-
/**
|
|
76
|
-
* Subscribe to changes for a specific key
|
|
77
|
-
* @param key Key of the value to subscribe to
|
|
78
|
-
* @param callback Callback for changes
|
|
79
|
-
* @returns Unsubscribe callback
|
|
80
|
-
*/
|
|
81
|
-
subscribe(key: Key, callback: (value: unknown) => void): Unsubscribe;
|
|
82
|
-
/**
|
|
83
|
-
* Update the value _(based on the current value)_
|
|
84
|
-
* @param callback Callback to update the value
|
|
85
|
-
*/
|
|
86
|
-
update(callback: (value: Value) => Value): void;
|
|
87
|
-
}
|
|
88
|
-
/**
|
|
89
|
-
* Create a reactive store
|
|
90
|
-
* @param value Initial object value
|
|
91
|
-
* @param options Optional reactivity options
|
|
92
|
-
* @returns Reactive store
|
|
93
|
-
*/
|
|
94
|
-
export declare function store<Value extends PlainObject>(value: Value, options?: ReactiveOptions<Value>): Store<Value>;
|