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