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