@oscarpalmer/mora 0.20.0 → 0.22.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.
Files changed (44) hide show
  1. package/dist/batch.js +11 -24
  2. package/dist/effect.js +17 -26
  3. package/dist/helpers/is.js +14 -21
  4. package/dist/helpers/proxy.js +34 -47
  5. package/dist/helpers/value.js +20 -46
  6. package/dist/index.js +4 -17
  7. package/dist/mora.full.js +8 -2
  8. package/dist/subscription.js +20 -28
  9. package/dist/value/array.js +94 -173
  10. package/dist/value/computed.js +34 -56
  11. package/dist/value/reactive.js +29 -53
  12. package/dist/value/signal.js +20 -32
  13. package/dist/value/store.js +30 -59
  14. package/package.json +12 -18
  15. package/src/helpers/value.ts +1 -1
  16. package/src/index.ts +0 -1
  17. package/src/value/array.ts +13 -3
  18. package/types/value/array.d.ts +1 -0
  19. package/dist/batch.cjs +0 -32
  20. package/dist/effect.cjs +0 -30
  21. package/dist/helpers/is.cjs +0 -40
  22. package/dist/helpers/proxy.cjs +0 -56
  23. package/dist/helpers/value.cjs +0 -54
  24. package/dist/index.cjs +0 -21
  25. package/dist/node_modules/@oscarpalmer/atoms/dist/internal/is.cjs +0 -17
  26. package/dist/node_modules/@oscarpalmer/atoms/dist/internal/is.js +0 -17
  27. package/dist/subscription.cjs +0 -32
  28. package/dist/value/array.cjs +0 -181
  29. package/dist/value/computed.cjs +0 -60
  30. package/dist/value/reactive.cjs +0 -55
  31. package/dist/value/signal.cjs +0 -36
  32. package/dist/value/store.cjs +0 -63
  33. package/types/batch.d.cts +0 -79
  34. package/types/effect.d.cts +0 -16
  35. package/types/helpers/is.d.cts +0 -258
  36. package/types/helpers/proxy.d.cts +0 -243
  37. package/types/helpers/value.d.cts +0 -71
  38. package/types/index.d.cts +0 -280
  39. package/types/subscription.d.cts +0 -71
  40. package/types/value/array.d.cts +0 -160
  41. package/types/value/computed.d.cts +0 -81
  42. package/types/value/reactive.d.cts +0 -68
  43. package/types/value/signal.d.cts +0 -87
  44. package/types/value/store.d.cts +0 -136
@@ -1,243 +0,0 @@
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<GenericCallback, Subscription>;
68
- value: Value;
69
- };
70
- declare class Subscription {
71
- state: ReactiveState<unknown, never>;
72
- callback: GenericCallback;
73
- constructor(state: ReactiveState<unknown, 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
- /**
99
- * Get the value at an index
100
- */
101
- get(index: number): Item | undefined;
102
- /**
103
- * Get the length of the array
104
- */
105
- get(property: "length"): number;
106
- /**
107
- * Create a computed, filtered array
108
- */
109
- filter(callback: (item: Item, index: number, array: Item[]) => boolean): Computed<Item[]>;
110
- /**
111
- * Create a computed, mapped array
112
- */
113
- map<Mapped>(callback: (item: Item, index: number, array: Item[]) => Mapped): Computed<Mapped[]>;
114
- /**
115
- * @inheritdoc
116
- */
117
- peek(): Item[];
118
- /**
119
- * Get the length of the array _(without reactivity)_
120
- */
121
- peek(length: true): number;
122
- /**
123
- * Remove and return the last item of the array
124
- */
125
- pop(): Item | undefined;
126
- /**
127
- * Add items to the end of the array
128
- */
129
- push(...items: Item[]): number;
130
- /**
131
- * Set the value
132
- */
133
- set(value?: Item[]): void;
134
- /**
135
- * Set the value at an index
136
- */
137
- set(index: number, value: Item): void;
138
- /**
139
- * Set the length of the array
140
- */
141
- set(property: "length", value: number): void;
142
- /**
143
- * Remove and return the first item of the array
144
- */
145
- shift(): Item | undefined;
146
- /**
147
- * Remove and return items from the array _(and optionally add new items)_
148
- */
149
- splice(from: number, to?: number, ...items: Item[]): Item[];
150
- /**
151
- * @inheritdoc
152
- */
153
- subscribe(callback: (value: Item[]) => void): Unsubscribe;
154
- /**
155
- * Subscribe to changes at a specific index
156
- */
157
- subscribe(index: number, callback: (value: Item | undefined) => void): Unsubscribe;
158
- /**
159
- * Add items to the beginning of the array
160
- */
161
- unshift(...items: Item[]): number;
162
- /**
163
- * Update the value _(based on the current value)_
164
- */
165
- update(callback: (value: Item[]) => Item[]): void;
166
- }
167
- declare class Signal<Value> extends Reactive<Value> {
168
- constructor(value: Value, options?: ReactiveOptions<Value>);
169
- /**
170
- * @inheritdoc
171
- */
172
- get(): Value;
173
- /**
174
- * Set the value
175
- */
176
- set(value: Value): void;
177
- /**
178
- * Update the value _(based on the current value)_
179
- */
180
- update(callback: (value: Value) => Value): void;
181
- }
182
- declare class Store<Value extends PlainObject> extends Reactive<Value, Value> {
183
- #private;
184
- constructor(value: Value, options?: ReactiveOptions<Value>);
185
- /**
186
- * @inheritdoc
187
- */
188
- get(): Value;
189
- /**
190
- * Get a value by key _(without reactivity)_
191
- */
192
- get(key: keyof Value): Value[keyof Value];
193
- /**
194
- * Get a value by key _(without reactivity)_
195
- */
196
- get(key: Key): unknown;
197
- /**
198
- * Get the value _(without reactivity)_
199
- */
200
- peek(): Value;
201
- /**
202
- * Get a value by key _(without reactivity)_
203
- */
204
- peek(key: keyof Value): Value[keyof Value];
205
- /**
206
- * Get a value by key _(without reactivity)_
207
- */
208
- peek(key: Key): unknown;
209
- /**
210
- * Set the value
211
- */
212
- set(value?: Value): void;
213
- /**
214
- * Set a value by key
215
- */
216
- set(key: keyof Value, value: Value[keyof Value]): void;
217
- /**
218
- * Set a value by key
219
- */
220
- set(key: Key, value: unknown): void;
221
- /**
222
- * @inheritdoc
223
- */
224
- subscribe(callback: (value: Value) => void): Unsubscribe;
225
- /**
226
- * Subscribe to changes for a specific key
227
- */
228
- subscribe<Key extends keyof Value>(key: Key, callback: (value: Value[Key] | undefined) => void): Unsubscribe;
229
- /**
230
- * Subscribe to changes for a specific key
231
- */
232
- subscribe(key: Key, callback: (value: unknown) => void): Unsubscribe;
233
- /**
234
- * Update the value _(based on the current value)_
235
- */
236
- update(callback: (value: Value) => Value): void;
237
- }
238
- export declare function getReactiveValueInProxy<Value>(array: ReactiveArray<Value>, mapped: Map<Key, Computed<unknown>>, index: number, isArray: true): Computed<unknown>;
239
- export declare function getReactiveValueInProxy<Value extends PlainObject>(store: Store<Value>, mapped: Map<Key, Computed<unknown>>, key: Key, isArray: false): Computed<unknown>;
240
- export declare function setProxyValue(proxy: ArrayOrPlainObject, value: ArrayOrPlainObject): void;
241
- export declare function setValueInProxy<Value extends ArrayOrPlainObject, Equal>(target: Value, property: PropertyKey, value: unknown, state: ReactiveState<Value, Equal>, isArray: boolean, length?: Signal<number>): boolean;
242
-
243
- export {};
@@ -1,71 +0,0 @@
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<GenericCallback, Subscription>;
56
- value: Value;
57
- };
58
- declare class Subscription {
59
- state: ReactiveState<unknown, never>;
60
- callback: GenericCallback;
61
- constructor(state: ReactiveState<unknown, 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 {};
package/types/index.d.cts DELETED
@@ -1,280 +0,0 @@
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
- export declare class Effect {
13
- private readonly $mora;
14
- private readonly state;
15
- constructor(callback: GenericCallback);
16
- }
17
- /**
18
- * Create an effect
19
- */
20
- export declare function effect(callback: GenericCallback): Effect;
21
- export 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
- /**
30
- * Create a computed value
31
- */
32
- export declare function computed<Value>(callback: () => Value, options?: ReactiveOptions<Value>): Computed<Value>;
33
- export declare abstract class Reactive<Value, Equal = Value> {
34
- protected readonly state: ReactiveState<Value, Equal>;
35
- constructor(name: string, value: Value, options?: ReactiveOptions<Equal>);
36
- /**
37
- * Get the value
38
- */
39
- abstract get(): Value;
40
- /**
41
- * Get the value _(without reactivity)_
42
- */
43
- peek(): Value;
44
- /**
45
- * Subscribe to changes
46
- */
47
- subscribe(callback: (value: Value) => void): Unsubscribe;
48
- /**
49
- * JSON representation of the value
50
- */
51
- toJSON(): Value;
52
- /**
53
- * String representation of the value
54
- */
55
- toString(): string;
56
- /**
57
- * Unsubscribe from changes
58
- */
59
- unsubscribe(callback: (value: Value) => void): void;
60
- }
61
- export type ReactiveOptions<Value> = {
62
- /**
63
- * Method to compare values for equality
64
- */
65
- equal?: (first: Value, second: Value) => boolean;
66
- };
67
- export type ReactiveState<Value, Equal> = {
68
- computeds: Set<Computed<unknown>>;
69
- effects: Set<Effect>;
70
- equal: (first: Equal, second: Equal) => boolean;
71
- subscriptions: Map<GenericCallback, Subscription>;
72
- value: Value;
73
- };
74
- declare class Subscription {
75
- state: ReactiveState<unknown, never>;
76
- callback: GenericCallback;
77
- constructor(state: ReactiveState<unknown, never>, callback: GenericCallback);
78
- }
79
- /**
80
- * Unsubscribe from changes
81
- */
82
- export type Unsubscribe = () => void;
83
- /**
84
- * Start batching effects _(use `stopBatch` to flush and run batched effects)_
85
- */
86
- export declare function startBatch(): void;
87
- /**
88
- * Stop batching effects and flush _(run)_ them
89
- */
90
- export declare function stopBatch(): void;
91
- export declare class ReactiveArray<Item> extends Reactive<Item[], Item> {
92
- #private;
93
- /**
94
- * The length of the array
95
- */
96
- get length(): number;
97
- /**
98
- * Set the length of the array
99
- */
100
- set length(value: number);
101
- constructor(value: Item[], options?: ReactiveOptions<Item>);
102
- /**
103
- * Clear the array
104
- */
105
- clear(): void;
106
- /**
107
- * @inheritdoc
108
- */
109
- get(): Item[];
110
- /**
111
- * Get the value at an index
112
- */
113
- get(index: number): Item | undefined;
114
- /**
115
- * Get the length of the array
116
- */
117
- get(property: "length"): number;
118
- /**
119
- * Create a computed, filtered array
120
- */
121
- filter(callback: (item: Item, index: number, array: Item[]) => boolean): Computed<Item[]>;
122
- /**
123
- * Create a computed, mapped array
124
- */
125
- map<Mapped>(callback: (item: Item, index: number, array: Item[]) => Mapped): Computed<Mapped[]>;
126
- /**
127
- * @inheritdoc
128
- */
129
- peek(): Item[];
130
- /**
131
- * Get the length of the array _(without reactivity)_
132
- */
133
- peek(length: true): number;
134
- /**
135
- * Remove and return the last item of the array
136
- */
137
- pop(): Item | undefined;
138
- /**
139
- * Add items to the end of the array
140
- */
141
- push(...items: Item[]): number;
142
- /**
143
- * Set the value
144
- */
145
- set(value?: Item[]): void;
146
- /**
147
- * Set the value at an index
148
- */
149
- set(index: number, value: Item): void;
150
- /**
151
- * Set the length of the array
152
- */
153
- set(property: "length", value: number): void;
154
- /**
155
- * Remove and return the first item of the array
156
- */
157
- shift(): Item | undefined;
158
- /**
159
- * Remove and return items from the array _(and optionally add new items)_
160
- */
161
- splice(from: number, to?: number, ...items: Item[]): Item[];
162
- /**
163
- * @inheritdoc
164
- */
165
- subscribe(callback: (value: Item[]) => void): Unsubscribe;
166
- /**
167
- * Subscribe to changes at a specific index
168
- */
169
- subscribe(index: number, callback: (value: Item | undefined) => void): Unsubscribe;
170
- /**
171
- * Add items to the beginning of the array
172
- */
173
- unshift(...items: Item[]): number;
174
- /**
175
- * Update the value _(based on the current value)_
176
- */
177
- update(callback: (value: Item[]) => Item[]): void;
178
- }
179
- /**
180
- * Create a reactive array
181
- */
182
- export declare function array<Item>(value: Item[], options?: ReactiveOptions<Item>): ReactiveArray<Item>;
183
- export declare class Signal<Value> extends Reactive<Value> {
184
- constructor(value: Value, options?: ReactiveOptions<Value>);
185
- /**
186
- * @inheritdoc
187
- */
188
- get(): Value;
189
- /**
190
- * Set the value
191
- */
192
- set(value: Value): void;
193
- /**
194
- * Update the value _(based on the current value)_
195
- */
196
- update(callback: (value: Value) => Value): void;
197
- }
198
- /**
199
- * Create a reactive value
200
- */
201
- export declare function signal<Value>(value: Value, options?: ReactiveOptions<Value>): Signal<Value>;
202
- export declare class Store<Value extends PlainObject> extends Reactive<Value, Value> {
203
- #private;
204
- constructor(value: Value, options?: ReactiveOptions<Value>);
205
- /**
206
- * @inheritdoc
207
- */
208
- get(): Value;
209
- /**
210
- * Get a value by key _(without reactivity)_
211
- */
212
- get(key: keyof Value): Value[keyof Value];
213
- /**
214
- * Get a value by key _(without reactivity)_
215
- */
216
- get(key: Key): unknown;
217
- /**
218
- * Get the value _(without reactivity)_
219
- */
220
- peek(): Value;
221
- /**
222
- * Get a value by key _(without reactivity)_
223
- */
224
- peek(key: keyof Value): Value[keyof Value];
225
- /**
226
- * Get a value by key _(without reactivity)_
227
- */
228
- peek(key: Key): unknown;
229
- /**
230
- * Set the value
231
- */
232
- set(value?: Value): void;
233
- /**
234
- * Set a value by key
235
- */
236
- set(key: keyof Value, value: Value[keyof Value]): void;
237
- /**
238
- * Set a value by key
239
- */
240
- set(key: Key, value: unknown): void;
241
- /**
242
- * @inheritdoc
243
- */
244
- subscribe(callback: (value: Value) => void): Unsubscribe;
245
- /**
246
- * Subscribe to changes for a specific key
247
- */
248
- subscribe<Key extends keyof Value>(key: Key, callback: (value: Value[Key] | undefined) => void): Unsubscribe;
249
- /**
250
- * Subscribe to changes for a specific key
251
- */
252
- subscribe(key: Key, callback: (value: unknown) => void): Unsubscribe;
253
- /**
254
- * Update the value _(based on the current value)_
255
- */
256
- update(callback: (value: Value) => Value): void;
257
- }
258
- /**
259
- * Create a reactive store
260
- */
261
- export declare function store<Value extends PlainObject>(value: Value, options?: ReactiveOptions<Value>): Store<Value>;
262
- /**
263
- * Is the value a reactive array?
264
- */
265
- export declare function isArray(value: unknown): value is ReactiveArray<unknown>;
266
- /**
267
- * Is the value a computed signal?
268
- */
269
- export declare function isComputed(value: unknown): value is Computed<unknown>;
270
- /**
271
- * Is the value an effect?
272
- */
273
- export declare function isEffect(value: unknown): value is Effect;
274
- export declare function isReactive(value: unknown): value is Reactive<unknown>;
275
- /**
276
- * Is the value a signal?
277
- */
278
- export declare function isSignal(value: unknown): value is Signal<unknown>;
279
-
280
- export {};
@@ -1,71 +0,0 @@
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<GenericCallback, Subscription>;
56
- value: Value;
57
- };
58
- export declare class Subscription {
59
- state: ReactiveState<unknown, never>;
60
- callback: GenericCallback;
61
- constructor(state: ReactiveState<unknown, never>, callback: GenericCallback);
62
- }
63
- /**
64
- * Unsubscribe from changes
65
- */
66
- export type Unsubscribe = () => void;
67
- export declare function noop(): void;
68
- export declare function subscribe<Value>(state: ReactiveState<Value, never>, callback: (value: Value) => void): Unsubscribe;
69
- export declare function unsubscribe<Value>(state: ReactiveState<Value, never>, callback: (value: Value) => void): void;
70
-
71
- export {};