aberdeen 0.4.0 → 0.5.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/LICENSE.txt +1 -1
- package/README.md +134 -96
- package/dist/aberdeen.d.ts +637 -528
- package/dist/aberdeen.js +1144 -1957
- package/dist/aberdeen.js.map +11 -1
- package/dist/helpers/reverseSortedSet.d.ts +91 -0
- package/dist/prediction.d.ts +7 -3
- package/dist/prediction.js +77 -93
- package/dist/prediction.js.map +10 -1
- package/dist/route.d.ts +36 -19
- package/dist/route.js +131 -158
- package/dist/route.js.map +10 -1
- package/dist/transitions.js +30 -70
- package/dist/transitions.js.map +10 -1
- package/dist-min/aberdeen.js +7 -2
- package/dist-min/aberdeen.js.map +11 -1
- package/dist-min/prediction.js +4 -2
- package/dist-min/prediction.js.map +10 -1
- package/dist-min/route.js +4 -2
- package/dist-min/route.js.map +10 -1
- package/dist-min/transitions.js +4 -2
- package/dist-min/transitions.js.map +10 -1
- package/package.json +20 -23
- package/src/aberdeen.ts +1918 -1814
- package/src/helpers/reverseSortedSet.ts +188 -0
- package/src/prediction.ts +14 -9
- package/src/route.ts +81 -64
- package/src/transitions.ts +1 -14
- package/dist-min/aberdeen.d.ts +0 -601
- package/dist-min/prediction.d.ts +0 -29
- package/dist-min/route.d.ts +0 -30
- package/dist-min/transitions.d.ts +0 -18
package/dist/aberdeen.d.ts
CHANGED
|
@@ -1,599 +1,708 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
3
|
-
* batch, after a timeout of 0s. Calling `runQueue()` will do so immediately
|
|
4
|
-
* and synchronously. Doing so may be helpful in cases where you need some DOM
|
|
5
|
-
* modification to be done synchronously.
|
|
2
|
+
* Forces the immediate and synchronous execution of all pending reactive updates.
|
|
6
3
|
*
|
|
7
|
-
*
|
|
8
|
-
*
|
|
4
|
+
* Normally, changes to observed data sources (like proxied objects or arrays)
|
|
5
|
+
* are processed asynchronously in a batch after a brief timeout (0ms). This function
|
|
6
|
+
* allows you to bypass the timeout and process the update queue immediately.
|
|
7
|
+
*
|
|
8
|
+
* This can be useful in specific scenarios where you need the DOM to be updated
|
|
9
|
+
* synchronously.
|
|
10
|
+
*
|
|
11
|
+
* This function is re-entrant, meaning it is safe to call `runQueue` from within
|
|
12
|
+
* a function that is itself being executed as part of an update cycle triggered
|
|
13
|
+
* by a previous (or the same) `runQueue` call.
|
|
14
|
+
*
|
|
15
|
+
* @example
|
|
16
|
+
* ```typescript
|
|
17
|
+
* const data = proxy("before");
|
|
18
|
+
*
|
|
19
|
+
* $({text: data});
|
|
20
|
+
* console.log(1, document.body.innerHTML); // before
|
|
21
|
+
*
|
|
22
|
+
* // Make an update that should cause the DOM to change.
|
|
23
|
+
* data.value = "after";
|
|
24
|
+
*
|
|
25
|
+
* // Normally, the DOM update would happen after a timeout.
|
|
26
|
+
* // But this causes an immediate update:
|
|
27
|
+
* runQueue();
|
|
28
|
+
*
|
|
29
|
+
* console.log(2, document.body.innerHTML); // after
|
|
30
|
+
* ```
|
|
9
31
|
*/
|
|
10
32
|
export declare function runQueue(): void;
|
|
11
33
|
/**
|
|
12
|
-
* A
|
|
13
|
-
*
|
|
14
|
-
*
|
|
34
|
+
* A sort key, as used by {@link onEach}, is a value that determines the order of items. It can
|
|
35
|
+
* be a number, string, or an array of numbers/strings. The sort key is used to sort items
|
|
36
|
+
* based on their values. The sort key can also be `undefined`, which indicates that the item
|
|
37
|
+
* should be ignored.
|
|
38
|
+
* @private
|
|
39
|
+
*/
|
|
40
|
+
export type SortKeyType = number | string | Array<number | string> | undefined;
|
|
41
|
+
/**
|
|
42
|
+
* Creates a new string that has the opposite sort order compared to the input string.
|
|
43
|
+
*
|
|
44
|
+
* This is achieved by flipping the bits of each character code in the input string.
|
|
45
|
+
* The resulting string is intended for use as a sort key, particularly with the
|
|
46
|
+
* `makeKey` function in {@link onEach}, to achieve a descending sort order.
|
|
15
47
|
*
|
|
16
|
-
*
|
|
17
|
-
*
|
|
18
|
-
* This helps reduce visual glitches and flashes by ensuring the browser doesn't render
|
|
19
|
-
* intermediate DOM states during updates.
|
|
48
|
+
* **Warning:** The output string will likely contain non-printable characters or
|
|
49
|
+
* appear as gibberish and should not be displayed to the user.
|
|
20
50
|
*
|
|
21
|
-
*
|
|
22
|
-
*
|
|
51
|
+
* @example
|
|
52
|
+
* ```typescript
|
|
53
|
+
* const users = proxy([
|
|
54
|
+
* { id: 1, name: 'Charlie', score: 95 },
|
|
55
|
+
* { id: 2, name: 'Alice', score: 100 },
|
|
56
|
+
* { id: 3, name: 'Bob', score: 90 },
|
|
57
|
+
* ]);
|
|
58
|
+
*
|
|
59
|
+
* onEach(users, (user) => {
|
|
60
|
+
* $(`p:${user.name}: ${user.score}`);
|
|
61
|
+
* }, (user) => invertString(user.name)); // Reverse alphabetic order
|
|
62
|
+
* ```
|
|
23
63
|
*
|
|
24
|
-
*
|
|
64
|
+
* @param input The string whose sort order needs to be inverted.
|
|
65
|
+
* @returns A new string that will sort in the reverse order of the input string.
|
|
66
|
+
* @see {@link onEach} for usage with sorting.
|
|
25
67
|
*/
|
|
26
|
-
export declare
|
|
27
|
-
|
|
28
|
-
|
|
68
|
+
export declare function invertString(input: string): string;
|
|
69
|
+
export declare function onEach<T>(target: Array<undefined | T>, render: (value: T, index: number) => void, makeKey?: (value: T, key: any) => SortKeyType): void;
|
|
70
|
+
export declare function onEach<K extends string | number | symbol, T>(target: Record<K, undefined | T>, render: (value: T, index: K) => void, makeKey?: (value: T, key: K) => SortKeyType): void;
|
|
29
71
|
/**
|
|
30
|
-
*
|
|
31
|
-
* DOM_READ_PHASE has completed (if any) and after any DOM triggered by Aberdeen
|
|
32
|
-
* have completed. This is a good time to do little manual DOM tweaks that depend
|
|
33
|
-
* on a *read phase* first, like triggering transitions.
|
|
72
|
+
* Reactively checks if an observable array or object is empty.
|
|
34
73
|
*
|
|
35
|
-
*
|
|
36
|
-
*
|
|
37
|
-
*
|
|
38
|
-
*
|
|
74
|
+
* This function not only returns the current emptiness state but also establishes
|
|
75
|
+
* a reactive dependency. If the emptiness state of the `proxied` object or array
|
|
76
|
+
* changes later (e.g., an item is added to an empty array, or the last property
|
|
77
|
+
* is deleted from an object), the scope that called `isEmpty` will be automatically
|
|
78
|
+
* scheduled for re-evaluation.
|
|
39
79
|
*
|
|
40
|
-
*
|
|
41
|
-
*
|
|
80
|
+
* @param proxied The observable array or object (obtained via `observe()`) to check.
|
|
81
|
+
* @returns `true` if the array has length 0 or the object has no own enumerable properties, `false` otherwise.
|
|
82
|
+
*
|
|
83
|
+
* @example
|
|
84
|
+
* ```typescript
|
|
85
|
+
* const items = proxy([]);
|
|
42
86
|
*
|
|
43
|
-
*
|
|
87
|
+
* // Reactively display a message if the items array is empty
|
|
88
|
+
* $('div', () => {
|
|
89
|
+
* if (isEmpty(items)) {
|
|
90
|
+
* $('p', 'i:No items yet!');
|
|
91
|
+
* } else {
|
|
92
|
+
* onEach(items, item=>$('p:'+item));
|
|
93
|
+
* }
|
|
94
|
+
* });
|
|
95
|
+
*
|
|
96
|
+
* // Adding an item will automatically remove the "No items yet!" message
|
|
97
|
+
* setInterval(() => {
|
|
98
|
+
* if (!items.length || Math.random()>0.5) items.push('Item');
|
|
99
|
+
* else items.length = 0;
|
|
100
|
+
* }, 1000)
|
|
101
|
+
* ```
|
|
44
102
|
*/
|
|
45
|
-
export declare
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
/**
|
|
50
|
-
* Return a `Store` deeper within the tree by resolving the given `path`,
|
|
51
|
-
* subscribing to every level.
|
|
52
|
-
* In case `undefined` is encountered while resolving the path, a newly
|
|
53
|
-
* created `Store` containing `undefined` is returned. In that case, the
|
|
54
|
-
* `Store`'s [[`isDetached`]] method will return `true`.
|
|
55
|
-
* In case something other than a collection is encountered, an error is thrown.
|
|
56
|
-
*/
|
|
57
|
-
(...path: any[]): Store;
|
|
58
|
-
}
|
|
59
|
-
export declare class Store {
|
|
60
|
-
/**
|
|
61
|
-
* Create a new `Store` with `undefined` as its initial value.
|
|
62
|
-
*/
|
|
63
|
-
constructor();
|
|
64
|
-
/**
|
|
65
|
-
* Create a new `Store`.
|
|
66
|
-
* @param value The initial value. Plain objects, arrays and `Map`s, are converted
|
|
67
|
-
* into a tree of nested `Store`s. When another `Store` is included somewhere in that
|
|
68
|
-
* input tree, a reference is made.
|
|
69
|
-
*/
|
|
70
|
-
constructor(value: any);
|
|
71
|
-
/**
|
|
72
|
-
* @returns The index for this Store within its parent collection. This will be a `number`
|
|
73
|
-
* when the parent collection is an array, a `string` when it's an object, or any data type
|
|
74
|
-
* when it's a `Map`.
|
|
75
|
-
*
|
|
76
|
-
* @example
|
|
77
|
-
* ```
|
|
78
|
-
* let store = new Store({x: 123})
|
|
79
|
-
* let subStore = store.ref('x')
|
|
80
|
-
* subStore.get() // 123
|
|
81
|
-
* subStore.index() // 'x'
|
|
82
|
-
* ```
|
|
83
|
-
*/
|
|
84
|
-
index(): any;
|
|
85
|
-
/**
|
|
86
|
-
* Retrieve the value for store, subscribing the observe scope to changes.
|
|
87
|
-
*
|
|
88
|
-
* @param depth Limit the depth of the retrieved data structure to this positive integer.
|
|
89
|
-
* When `depth` is `1`, only a single level of the value at `path` is unpacked. This
|
|
90
|
-
* makes no difference for primitive values (like strings), but for objects, maps and
|
|
91
|
-
* arrays, it means that each *value* in the resulting data structure will be a
|
|
92
|
-
* reference to the `Store` for that value.
|
|
93
|
-
*
|
|
94
|
-
* @returns The resulting value (or `undefined` if the `Store` does not exist).
|
|
95
|
-
*/
|
|
96
|
-
get(depth?: number): any;
|
|
97
|
-
/**
|
|
98
|
-
* Exactly like {@link Store.get}, except that when executed from an observe scope,
|
|
99
|
-
* we will not subscribe to changes in the data retrieved data.
|
|
100
|
-
*/
|
|
101
|
-
peek(depth?: number): any;
|
|
102
|
-
/**
|
|
103
|
-
* Like {@link Store.get}, but with return type checking.
|
|
104
|
-
*
|
|
105
|
-
* @param expectType A string specifying what type the.get is expected to return. Options are:
|
|
106
|
-
* "undefined", "null", "boolean", "number", "string", "function", "array", "map"
|
|
107
|
-
* and "object". If the store holds a different type of value, a `TypeError`
|
|
108
|
-
* exception is thrown.
|
|
109
|
-
* @returns
|
|
110
|
-
*/
|
|
111
|
-
getTyped(expectType: String, depth?: number): any;
|
|
112
|
-
/**
|
|
113
|
-
* @returns Like {@link Store.get}, but throws a `TypeError` if the resulting value is not of type `number`.
|
|
114
|
-
* Using this instead of just {@link Store.get} is especially useful from within TypeScript.
|
|
115
|
-
*/
|
|
116
|
-
getNumber(): number;
|
|
117
|
-
/**
|
|
118
|
-
* @returns Like {@link Store.get}, but throws a `TypeError` if the resulting value is not of type `string`.
|
|
119
|
-
* Using this instead of just {@link Store.get} is especially useful from within TypeScript.
|
|
120
|
-
*/
|
|
121
|
-
getString(): string;
|
|
122
|
-
/**
|
|
123
|
-
* @returns Like {@link Store.get}, but throws a `TypeError` if the resulting value is not of type `boolean`.
|
|
124
|
-
* Using this instead of just {@link Store.get} is especially useful from within TypeScript.
|
|
125
|
-
*/
|
|
126
|
-
getBoolean(): boolean;
|
|
127
|
-
/**
|
|
128
|
-
* @returns Like {@link Store.get}, but throws a `TypeError` if the resulting value is not of type `function`.
|
|
129
|
-
* Using this instead of just {@link Store.get} is especially useful from within TypeScript.
|
|
130
|
-
*/
|
|
131
|
-
getFunction(): (Function);
|
|
132
|
-
/**
|
|
133
|
-
* @returns Like {@link Store.get}, but throws a `TypeError` if the resulting value is not of type `array`.
|
|
134
|
-
* Using this instead of just {@link Store.get} is especially useful from within TypeScript.
|
|
135
|
-
*/
|
|
136
|
-
getArray(depth?: number): any[];
|
|
137
|
-
/**
|
|
138
|
-
* @returns Like {@link Store.get}, but throws a `TypeError` if the resulting value is not of type `object`.
|
|
139
|
-
* Using this instead of just {@link Store.get} is especially useful from within TypeScript.
|
|
140
|
-
*/
|
|
141
|
-
getObject(depth?: number): object;
|
|
142
|
-
/**
|
|
143
|
-
* @returns Like {@link Store.get}, but throws a `TypeError` if the resulting value is not of type `map`.
|
|
144
|
-
* Using this instead of just {@link Store.get} is especially useful from within TypeScript.
|
|
145
|
-
*/
|
|
146
|
-
getMap(depth?: number): Map<any, any>;
|
|
147
|
-
/**
|
|
148
|
-
* Like {@link Store.get}, but with a default value (returned when the Store
|
|
149
|
-
* contains `undefined`). This default value is also used to determine the expected type,
|
|
150
|
-
* and to throw otherwise.
|
|
151
|
-
*
|
|
152
|
-
* @example
|
|
153
|
-
* ```
|
|
154
|
-
* let store = new Store({x: 42})
|
|
155
|
-
* store('x').getOr(99) // 42
|
|
156
|
-
* store('y').getOr(99) // 99
|
|
157
|
-
* store('x').getOr('hello') // throws TypeError (because 42 is not a string)
|
|
158
|
-
* ```
|
|
159
|
-
*/
|
|
160
|
-
getOr<T>(defaultValue: T): T;
|
|
161
|
-
/**
|
|
162
|
-
* Checks if the collection held in `Store` is empty, and subscribes the current scope to changes of the emptiness of this collection.
|
|
163
|
-
*
|
|
164
|
-
* @returns When the collection is not empty `true` is returned. If it is empty or if the value is undefined, `false` is returned.
|
|
165
|
-
* @throws When the value is not a collection and not undefined, an Error will be thrown.
|
|
166
|
-
*/
|
|
167
|
-
isEmpty(): boolean;
|
|
168
|
-
/**
|
|
169
|
-
* Returns the number of items in the collection held in Store, and subscribes the current scope to changes in this count.
|
|
170
|
-
*
|
|
171
|
-
* @returns The number of items contained in the collection, or 0 if the value is undefined.
|
|
172
|
-
* @throws When the value is not a collection and not undefined, an Error will be thrown.
|
|
173
|
-
*/
|
|
174
|
-
count(): number;
|
|
175
|
-
/**
|
|
176
|
-
* Returns a strings describing the type of the `Store` value, subscribing to changes of this type.
|
|
177
|
-
* Note: this currently also subscribes to changes of primitive values, so changing a value from 3 to 4
|
|
178
|
-
* would cause the scope to be rerun. This is not great, and may change in the future. This caveat does
|
|
179
|
-
* not apply to changes made *inside* an object, `Array` or `Map`.
|
|
180
|
-
*
|
|
181
|
-
* @returns Possible options: "undefined", "null", "boolean", "number", "string", "function", "array", "map" or "object".
|
|
182
|
-
*/
|
|
183
|
-
getType(): string;
|
|
184
|
-
/**
|
|
185
|
-
* Returns a new `Store` that will always hold either the value of `whenTrue` or the value
|
|
186
|
-
* of `whenFalse` depending on whether the original `Store` is truthy or not.
|
|
187
|
-
*
|
|
188
|
-
* @param whenTrue The value set to the return-`Store` while `this` is truthy. This can be
|
|
189
|
-
* any type of value. If it's a `Store`, the return-`Store` will reference the same
|
|
190
|
-
* data (so *no* deep copy will be made).
|
|
191
|
-
* @param whenFalse Like `whenTrue`, but for falsy values (false, undefined, null, 0, "").
|
|
192
|
-
* @returns A store holding the result value. The value will keep getting updated while
|
|
193
|
-
* the observe context from which `if()` was called remains active.
|
|
194
|
-
*/
|
|
195
|
-
if(whenTrue: any[], whenFalse?: any[]): Store;
|
|
196
|
-
/**
|
|
197
|
-
* Sets the `Store` value to the given argument.
|
|
198
|
-
*
|
|
199
|
-
* When a `Store` is passed in as the value, its value will be copied (subscribing to changes). In
|
|
200
|
-
* case the value is an object, an `Array` or a `Map`, a *reference* to that data structure will
|
|
201
|
-
* be created, so that changes made through one `Store` will be reflected through the other. Be
|
|
202
|
-
* carefull not to create loops in your `Store` tree that way, as that would cause any future
|
|
203
|
-
* call to {@link Store.get} to throw a `RangeError` (Maximum call stack size exceeded.)
|
|
204
|
-
*
|
|
205
|
-
* If you intent to make a copy instead of a reference, call {@link Store.get} on the origin `Store`.
|
|
206
|
-
*
|
|
207
|
-
* @returns The `Store` itself, for chaining other methods.
|
|
208
|
-
*
|
|
209
|
-
* @example
|
|
210
|
-
* ```
|
|
211
|
-
* let store = new Store() // Value is `undefined`
|
|
212
|
-
*
|
|
213
|
-
* store.set(6)
|
|
214
|
-
* store.get() // 6
|
|
215
|
-
*
|
|
216
|
-
* store.set({}) // Change value to an empty object
|
|
217
|
-
* store('a', 'b', 'c').set('d') // Create parent path as objects
|
|
218
|
-
* store.get() // {x: 6, a: {b: {c: 'd'}}}
|
|
219
|
-
*
|
|
220
|
-
* store.set(42) // Overwrites all of the above
|
|
221
|
-
* store.get() // 42
|
|
222
|
-
*
|
|
223
|
-
* store('x').set(6) // Throw Error (42 is not a collection)
|
|
224
|
-
* ```
|
|
225
|
-
*/
|
|
226
|
-
set(newValue: any): Store;
|
|
227
|
-
/**
|
|
228
|
-
* Sets the `Store` to the given `mergeValue`, but without deleting any pre-existing
|
|
229
|
-
* items when a collection overwrites a similarly typed collection. This results in
|
|
230
|
-
* a deep merge.
|
|
231
|
-
*
|
|
232
|
-
* @returns The `Store` itself, for chaining other methods.
|
|
233
|
-
*
|
|
234
|
-
* @example
|
|
235
|
-
* ```
|
|
236
|
-
* let store = new Store({a: {x: 1}})
|
|
237
|
-
* store.merge({a: {y: 2}, b: 3})
|
|
238
|
-
* store.get() // {a: {x: 1, y: 2}, b: 3}
|
|
239
|
-
* ```
|
|
240
|
-
*/
|
|
241
|
-
merge(mergeValue: any): Store;
|
|
242
|
-
/**
|
|
243
|
-
* Sets the value for the store to `undefined`, which causes it to be omitted from the map (or array, if it's at the end)
|
|
244
|
-
*
|
|
245
|
-
* @returns The `Store` itself, for chaining other methods.
|
|
246
|
-
*
|
|
247
|
-
* @example
|
|
248
|
-
* ```
|
|
249
|
-
* let store = new Store({a: 1, b: 2})
|
|
250
|
-
* store('a').delete()
|
|
251
|
-
* store.get() // {b: 2}
|
|
252
|
-
*
|
|
253
|
-
* store = new Store(['a','b','c'])
|
|
254
|
-
* store(1).delete()
|
|
255
|
-
* store.get() // ['a', undefined, 'c']
|
|
256
|
-
* store(2).delete()
|
|
257
|
-
* store.get() // ['a']
|
|
258
|
-
* store.delete()
|
|
259
|
-
* store.get() // undefined
|
|
260
|
-
* ```
|
|
261
|
-
*/
|
|
262
|
-
delete(): Store;
|
|
263
|
-
/**
|
|
264
|
-
* Pushes a value to the end of the Array that is at the specified path in the store.
|
|
265
|
-
* If that store path is `undefined`, an Array is created first.
|
|
266
|
-
* The last argument is the value to be added, any earlier arguments indicate the path.
|
|
267
|
-
*
|
|
268
|
-
* @returns The index at which the item was appended.
|
|
269
|
-
* @throws TypeError when the store contains a primitive data type.
|
|
270
|
-
*
|
|
271
|
-
* @example
|
|
272
|
-
* ```
|
|
273
|
-
* let store = new Store()
|
|
274
|
-
* store.push(3) // Creates the array
|
|
275
|
-
* store.push(6)
|
|
276
|
-
* store.get() // [3,6]
|
|
277
|
-
*
|
|
278
|
-
* store = new Store({myArray: [1,2]})
|
|
279
|
-
* store('myArray').push(3)
|
|
280
|
-
* store.get() // {myArray: [1,2,3]}
|
|
281
|
-
* ```
|
|
282
|
-
*/
|
|
283
|
-
push(newValue: any): number;
|
|
284
|
-
/**
|
|
285
|
-
* {@link Store.peek} the current value, pass it through `func`, and {@link Store.set} the resulting
|
|
286
|
-
* value.
|
|
287
|
-
* @param func The function transforming the value.
|
|
288
|
-
* @returns The `Store` itself, for chaining other methods.
|
|
289
|
-
*/
|
|
290
|
-
modify(func: (value: any) => any): Store;
|
|
291
|
-
/**
|
|
292
|
-
* Iterate the specified collection (Array, Map or object), running the given code block for each item.
|
|
293
|
-
* When items are added to the collection at some later point, the code block will be ran for them as well.
|
|
294
|
-
* When an item is removed, the {@link Store.clean} handlers left by its code block are executed.
|
|
295
|
-
*
|
|
296
|
-
* @param renderer The function to be called for each item. It receives the item's `Store` object as its only argument.
|
|
297
|
-
* @param makeSortKey An optional function that, given an items `Store` object, returns a value to be sorted on.
|
|
298
|
-
* This value can be a number, a string, or an array containing a combination of both. When undefined is returned,
|
|
299
|
-
* the item is *not* rendered. If `makeSortKey` is not specified, the output will be sorted by `index()`.
|
|
300
|
-
*/
|
|
301
|
-
onEach(renderer: (store: Store) => void, makeSortKey?: (store: Store) => any): void;
|
|
302
|
-
/**
|
|
303
|
-
* Derive a new `Store` from this `Store`, by reactively passing its value
|
|
304
|
-
* through the specified function.
|
|
305
|
-
* @param func Your function. It should accept a the input store's value, and return
|
|
306
|
-
* a result to be reactively set to the output store.
|
|
307
|
-
* @returns The output `Store`.
|
|
308
|
-
* @example
|
|
309
|
-
* ```javascript
|
|
310
|
-
* const store = new Store(21)
|
|
311
|
-
* const double = store.derive(v => v*2)
|
|
312
|
-
* double.get() // 42
|
|
313
|
-
*
|
|
314
|
-
* store.set(100)
|
|
315
|
-
* runQueue() // Or after a setTimeout 0, due to batching
|
|
316
|
-
* double.get() // 200
|
|
317
|
-
* ```
|
|
318
|
-
*/
|
|
319
|
-
derive(func: (value: any) => any): Store;
|
|
320
|
-
/**
|
|
321
|
-
* Applies a filter/map function on each item within the `Store`'s collection,
|
|
322
|
-
* and reactively manages the returned `Map` `Store` to hold any results.
|
|
323
|
-
*
|
|
324
|
-
* @param func - Function that transform the given store into an output value or
|
|
325
|
-
* `undefined` in case this value should be skipped:
|
|
326
|
-
*
|
|
327
|
-
* @returns - A array/map/object `Store` with the values returned by `func` and the
|
|
328
|
-
* corresponding keys from the original map, array or object `Store`.
|
|
329
|
-
*
|
|
330
|
-
* When items disappear from the `Store` or are changed in a way that `func` depends
|
|
331
|
-
* upon, the resulting items are removed from the output `Store` as well. When multiple
|
|
332
|
-
* input items produce the same output keys, this may lead to unexpected results.
|
|
333
|
-
*/
|
|
334
|
-
map(func: (store: Store) => any): Store;
|
|
335
|
-
/**
|
|
336
|
-
* Applies a filter/map function on each item within the `Store`'s collection,
|
|
337
|
-
* each of which can deliver any number of key/value pairs, and reactively manages the
|
|
338
|
-
* returned map `Store` to hold any results.
|
|
339
|
-
*
|
|
340
|
-
* @param func - Function that transform the given store into output values
|
|
341
|
-
* that can take one of the following forms:
|
|
342
|
-
* - an `Object` or a `Map`: Each key/value pair will be added to the output `Store`.
|
|
343
|
-
* - anything else: No key/value pairs are added to the output `Store`.
|
|
344
|
-
*
|
|
345
|
-
* @returns - A map `Store` with the key/value pairs returned by all `func` invocations.
|
|
346
|
-
*
|
|
347
|
-
* When items disappear from the `Store` or are changed in a way that `func` depends
|
|
348
|
-
* upon, the resulting items are removed from the output `Store` as well. When multiple
|
|
349
|
-
* input items produce the same output keys, this may lead to unexpected results.
|
|
350
|
-
*/
|
|
351
|
-
multiMap(func: (store: Store) => any): Store;
|
|
352
|
-
/**
|
|
353
|
-
* Dump a live view of the `Store` tree as HTML text, `ul` and `li` nodes at
|
|
354
|
-
* the current mount position. Meant for debugging purposes.
|
|
355
|
-
* @returns The `Store` itself, for chaining other methods.
|
|
356
|
-
*/
|
|
357
|
-
dump(): Store;
|
|
103
|
+
export declare function isEmpty(proxied: TargetType): boolean;
|
|
104
|
+
/** @private */
|
|
105
|
+
export interface ValueRef<T> {
|
|
106
|
+
value: T;
|
|
358
107
|
}
|
|
359
108
|
/**
|
|
360
|
-
*
|
|
361
|
-
*
|
|
362
|
-
*
|
|
363
|
-
* @
|
|
364
|
-
*
|
|
365
|
-
*
|
|
366
|
-
*
|
|
367
|
-
*
|
|
368
|
-
*
|
|
369
|
-
*
|
|
370
|
-
*
|
|
371
|
-
* $('
|
|
372
|
-
*
|
|
373
|
-
|
|
109
|
+
* Reactively counts the number of properties in an objects.
|
|
110
|
+
*
|
|
111
|
+
* @param proxied The observable object to count. In case an `array` is passed in, a {@link ref} to its `.length` will be returned.
|
|
112
|
+
* @returns an observable object for which the `value` property reflects the number of properties in `proxied` with a value other than `undefined`.
|
|
113
|
+
*
|
|
114
|
+
* @example
|
|
115
|
+
* ```typescript
|
|
116
|
+
* const items = proxy({x: 3, y: 7} as any);
|
|
117
|
+
* const cnt = count(items);
|
|
118
|
+
*
|
|
119
|
+
* // Create a DOM text node for the count:
|
|
120
|
+
* $('div', {text: cnt});
|
|
121
|
+
* // <div>2</div>
|
|
122
|
+
|
|
123
|
+
* // Or we can use it in an {@link observe} function:
|
|
124
|
+
* observe(() => console.log("The count is now", cnt.value));
|
|
125
|
+
* // The count is now 2
|
|
126
|
+
*
|
|
127
|
+
* // Adding/removing items will update the count
|
|
128
|
+
* items.z = 12;
|
|
129
|
+
* // Asynchronously, after 0ms:
|
|
130
|
+
* // <div>3</div>
|
|
131
|
+
* // The count is now 3
|
|
374
132
|
* ```
|
|
133
|
+
*/
|
|
134
|
+
export declare function count(proxied: TargetType): ValueRef<number>;
|
|
135
|
+
export declare function proxy<T extends DatumType>(target: Array<T>): Array<T extends number ? number : T extends string ? string : T extends boolean ? boolean : T>;
|
|
136
|
+
export declare function proxy<T extends object>(target: T): T;
|
|
137
|
+
export declare function proxy<T extends DatumType>(target: T): ValueRef<T extends number ? number : T extends string ? string : T extends boolean ? boolean : T>;
|
|
138
|
+
/**
|
|
139
|
+
* Returns the original, underlying data target from a reactive proxy created by {@link proxy}.
|
|
140
|
+
* If the input `target` is not a proxy, it is returned directly.
|
|
141
|
+
*
|
|
142
|
+
* This is useful when you want to avoid triggering subscriptions during read operations or
|
|
143
|
+
* re-executes during write operations. Using {@link peek} is an alternative way to achieve this.
|
|
144
|
+
*
|
|
145
|
+
* @param target - A proxied object, array, or any other value.
|
|
146
|
+
* @returns The underlying (unproxied) data, or the input value if it wasn't a proxy.
|
|
147
|
+
* @template T - The type of the target.
|
|
148
|
+
*
|
|
149
|
+
* @example
|
|
150
|
+
* ```typescript
|
|
151
|
+
* const userProxy = proxy({ name: 'Frank' });
|
|
152
|
+
* const rawUser = unproxy(userProxy);
|
|
153
|
+
*
|
|
154
|
+
* // Log reactively
|
|
155
|
+
* $(() => console.log('proxied', userProxy.name));
|
|
156
|
+
* // The following will only ever log once, as we're not subscribing to any observable
|
|
157
|
+
* $(() => console.log('unproxied', rawUser.name));
|
|
375
158
|
*
|
|
376
|
-
*
|
|
377
|
-
*
|
|
378
|
-
*
|
|
379
|
-
* //
|
|
380
|
-
*
|
|
381
|
-
*
|
|
382
|
-
*
|
|
383
|
-
*
|
|
384
|
-
*
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
*
|
|
389
|
-
*
|
|
390
|
-
*
|
|
391
|
-
*
|
|
392
|
-
*
|
|
393
|
-
*
|
|
394
|
-
*
|
|
395
|
-
*
|
|
396
|
-
*
|
|
397
|
-
*
|
|
398
|
-
*
|
|
399
|
-
*
|
|
400
|
-
*
|
|
401
|
-
*
|
|
402
|
-
*
|
|
403
|
-
*
|
|
404
|
-
*
|
|
405
|
-
*
|
|
406
|
-
*
|
|
407
|
-
*
|
|
408
|
-
*
|
|
409
|
-
*
|
|
410
|
-
*
|
|
159
|
+
* // This cause the first log to run again:
|
|
160
|
+
* setTimeout(() => userProxy.name += '!', 1000);
|
|
161
|
+
*
|
|
162
|
+
* // This doesn't cause any new logs:
|
|
163
|
+
* setTimeout(() => rawUser.name += '?', 2000);
|
|
164
|
+
*
|
|
165
|
+
* // Both userProxy and rawUser end up as `{name: 'Frank!?'}`
|
|
166
|
+
* setTimeout(() => console.log('final values', userProxy, rawUser), 3000);
|
|
167
|
+
* ```
|
|
168
|
+
*/
|
|
169
|
+
export declare function unproxy<T>(target: T): T;
|
|
170
|
+
/**
|
|
171
|
+
* Recursively copies properties or array items from `src` to `dst`.
|
|
172
|
+
* It's designed to work efficiently with reactive proxies created by {@link proxy}.
|
|
173
|
+
*
|
|
174
|
+
* - **Minimizes Updates:** When copying between objects/arrays (proxied or not), if a nested object
|
|
175
|
+
* exists in `dst` with the same constructor as the corresponding object in `src`, `copy`
|
|
176
|
+
* will recursively copy properties into the existing `dst` object instead of replacing it.
|
|
177
|
+
* This minimizes change notifications for reactive updates.
|
|
178
|
+
* - **Handles Proxies:** Can accept proxied or unproxied objects/arrays for both `dst` and `src`.
|
|
179
|
+
*
|
|
180
|
+
* @param dst - The destination object/array (proxied or unproxied).
|
|
181
|
+
* @param src - The source object/array (proxied or unproxied). It won't be modified.
|
|
182
|
+
* @param flags - Bitmask controlling copy behavior:
|
|
183
|
+
* - {@link MERGE}: Performs a partial update. Properties in `dst` not present in `src` are kept.
|
|
184
|
+
* `null`/`undefined` in `src` delete properties in `dst`. Handles partial array updates via object keys.
|
|
185
|
+
* - {@link SHALLOW}: Performs a shallow copy; when an array/object of the right type doesn't exist in `dst` yet, a reference to the array/object in `src` will be made, instead of creating a copy. If the array/object already exists, it won't be replaced (by a reference), but all items will be individually checked and copied like normal, keeping changes (and therefore UI updates) to a minimum.
|
|
186
|
+
* @template T - The type of the objects being copied.
|
|
187
|
+
* @throws Error if attempting to copy an array into a non-array or vice versa (unless {@link MERGE} is set, allowing for sparse array updates).
|
|
188
|
+
*
|
|
189
|
+
* @example Basic Copy
|
|
190
|
+
* ```typescript
|
|
191
|
+
* const source = proxy({ a: 1, b: { c: 2 } });
|
|
192
|
+
* const dest = proxy({ b: { d: 3 } });
|
|
193
|
+
* copy(dest, source);
|
|
194
|
+
* console.log(dest); // proxy({ a: 1, b: { c: 2 } })
|
|
411
195
|
* ```
|
|
412
196
|
*
|
|
413
|
-
*
|
|
414
|
-
*
|
|
415
|
-
*
|
|
416
|
-
*
|
|
417
|
-
*
|
|
418
|
-
*
|
|
419
|
-
* $('div', {
|
|
420
|
-
* '.active': activeStore, // Reactive class
|
|
421
|
-
* $color: colorStore, // Reactive style
|
|
422
|
-
* text: textStore // Reactive text
|
|
423
|
-
* })
|
|
197
|
+
* @example MERGE
|
|
198
|
+
* ```typescript
|
|
199
|
+
* const source = { b: { c: 99 }, d: undefined }; // d: undefined will delete
|
|
200
|
+
* const dest = proxy({ a: 1, b: { x: 5 }, d: 4 });
|
|
201
|
+
* copy(dest, source, MERGE);
|
|
202
|
+
* console.log(dest); // proxy({ a: 1, b: { c: 99, x: 5 } })
|
|
424
203
|
* ```
|
|
425
204
|
*
|
|
426
|
-
*
|
|
427
|
-
*
|
|
428
|
-
*
|
|
429
|
-
*
|
|
430
|
-
*
|
|
431
|
-
*
|
|
205
|
+
* @example Partial Array Update with MERGE
|
|
206
|
+
* ```typescript
|
|
207
|
+
* const messages = proxy(['msg1', 'msg2', 'msg3']);
|
|
208
|
+
* const update = { 1: 'updated msg2' }; // Update using object key as index
|
|
209
|
+
* copy(messages, update, MERGE);
|
|
210
|
+
* console.log(messages); // proxy(['msg1', 'updated msg2', 'msg3'])
|
|
432
211
|
* ```
|
|
433
|
-
* This is a special case, as changes to the `Store` will *not* be
|
|
434
|
-
* reflected in the UI.
|
|
435
212
|
*
|
|
436
|
-
*
|
|
437
|
-
*
|
|
438
|
-
*
|
|
439
|
-
*
|
|
440
|
-
*
|
|
441
|
-
*
|
|
213
|
+
* @example SHALLOW
|
|
214
|
+
* ```typescript
|
|
215
|
+
* const source = { nested: [1, 2] };
|
|
216
|
+
* const dest = {};
|
|
217
|
+
* copy(dest, source, SHALLOW);
|
|
218
|
+
* dest.nested.push(3);
|
|
219
|
+
* console.log(source.nested); // [1, 2, 3] (source was modified)
|
|
442
220
|
* ```
|
|
443
|
-
|
|
444
|
-
|
|
221
|
+
*/
|
|
222
|
+
export declare function copy<T extends object>(dst: T, src: T, flags?: number): void;
|
|
223
|
+
/** Flag to {@link copy} causing it to use merge semantics. See {@link copy} for details. */
|
|
224
|
+
export declare const MERGE = 1;
|
|
225
|
+
/** Flag to {@link copy} and {@link clone} causing them to create a shallow copy (instead of the deep copy done by default).*/
|
|
226
|
+
export declare const SHALLOW = 2;
|
|
227
|
+
/**
|
|
228
|
+
* Clone an (optionally proxied) object or array.
|
|
445
229
|
*
|
|
446
|
-
* @
|
|
447
|
-
* @
|
|
230
|
+
* @param src The object or array to clone. If it is proxied, `clone` will subscribe to any changes to the (nested) data structure.
|
|
231
|
+
* @param flags
|
|
232
|
+
* - {@link SHALLOW}: Performs a shallow clone, meaning that only the top-level array or object will be copied, while object/array values will just be references to the original data in `src`.
|
|
233
|
+
* @template T - The type of the objects being copied.
|
|
234
|
+
* @returns A new unproxied array or object (of the same type as `src`), containing a deep (by default) copy of `src`.
|
|
448
235
|
*/
|
|
449
|
-
export declare function
|
|
450
|
-
[key: string]: any;
|
|
451
|
-
})[]): void;
|
|
236
|
+
export declare function clone<T extends object>(src: T, flags?: number): T;
|
|
452
237
|
/**
|
|
453
|
-
*
|
|
454
|
-
*
|
|
455
|
-
*
|
|
456
|
-
*
|
|
457
|
-
*
|
|
458
|
-
*
|
|
238
|
+
* Creates a reactive reference (`{ value: T }`-like object) to a specific value
|
|
239
|
+
* within a proxied object or array.
|
|
240
|
+
*
|
|
241
|
+
* This is primarily used for the `bind` property in {@link $} to create two-way data bindings
|
|
242
|
+
* with form elements, and for passing a reactive property to any of the {@link $} key-value pairs.
|
|
243
|
+
*
|
|
244
|
+
* Reading `ref.value` accesses the property from the underlying proxy (and subscribes the current scope).
|
|
245
|
+
* Assigning to `ref.value` updates the property in the underlying proxy (triggering reactive updates).
|
|
459
246
|
*
|
|
460
|
-
* @param
|
|
461
|
-
*
|
|
462
|
-
*
|
|
247
|
+
* @param target - The reactive proxy (created by {@link proxy}) containing the target property.
|
|
248
|
+
* @param index - The key (for objects) or index (for arrays) of the property to reference.
|
|
249
|
+
* @returns A reference object with a `value` property linked to the specified proxy property.
|
|
463
250
|
*
|
|
464
251
|
* @example
|
|
465
252
|
* ```javascript
|
|
466
|
-
*
|
|
253
|
+
* const formData = proxy({ color: 'orange', velocity: 42 });
|
|
254
|
+
*
|
|
255
|
+
* // Usage with `bind`
|
|
256
|
+
* $('input', {
|
|
257
|
+
* type: 'text',
|
|
258
|
+
* // Creates a two-way binding between the input's value and formData.username
|
|
259
|
+
* bind: ref(formData, 'color')
|
|
260
|
+
* });
|
|
261
|
+
*
|
|
262
|
+
* // Usage as a dynamic property, causes a TextNode with just the name to be created and live-updated
|
|
263
|
+
* $('p:Selected color: ', {
|
|
264
|
+
* text: ref(formData, 'color'),
|
|
265
|
+
* $color: ref(formData, 'color')
|
|
266
|
+
* });
|
|
267
|
+
*
|
|
268
|
+
* // Changes are actually stored in formData - this causes logs like `{color: "Blue", velocity 42}`
|
|
269
|
+
* $(() => console.log(formData))
|
|
270
|
+
* ```
|
|
271
|
+
*/
|
|
272
|
+
export declare function ref<T extends TargetType, K extends keyof T>(target: T, index: K): ValueRef<T[K]>;
|
|
273
|
+
/**
|
|
274
|
+
* The core function for building reactive user interfaces in Aberdeen. It creates and inserts new DOM elements
|
|
275
|
+
* and sets attributes/properties/event listeners on DOM elements. It does so in a reactive way, meaning that
|
|
276
|
+
* changes will be (mostly) undone when the current *scope* is destroyed or will be re-execute.
|
|
277
|
+
*
|
|
278
|
+
* @param {...(string | function | object | false | undefined | null)} args - Any number of arguments can be given. How they're interpreted depends on their types:
|
|
279
|
+
*
|
|
280
|
+
* - `string`: Strings can be used to create and insert new elements, set classnames for the *current* element, and add text to the current element.
|
|
281
|
+
* The format of a string is: **tag**? (`.` **class**)* (':' **text**)?
|
|
282
|
+
* meaning it consists of...
|
|
283
|
+
* - An optional HTML **tag**, something like `h1`. If present, a DOM element of that tag is created, and that element will be the *current* element for the rest of this `$` function execution.
|
|
284
|
+
* - Any number of CSS classes prefixed by `.` characters. These classes will be added to the *current* element.
|
|
285
|
+
* - Optional content **text** prefixed by a `:` character, ranging til the end of the string. This will be added as a TextNode to the *current* element.
|
|
286
|
+
* - `function`: When a function (without argument nor a return value) is passed in, it will be reactively executed in its own observe scope, preserving the *current element*. So any `$()` invocations within this function will create DOM elements with our *current* element as parent. If the function reads observable data, and that data is changed later on, the function we re-execute (after side effects, such as DOM modifications through `$`, have been cleaned - see also {@link clean}).
|
|
287
|
+
* - `object`: When an object is passed in, its key-value pairs are used to modify the *current* element in the following ways...
|
|
288
|
+
* - `{<attrName>: any}`: The common case is setting the value as an HTML attribute named key. So `{placeholder: "Your name"}` would add `placeholder="Your name"` to the current HTML element.
|
|
289
|
+
* - `{<propName>: boolean}` or `{value: any}` or `{selectedIndex: number}`: If the value is a boolean, or if the key is `value` or `selectedIndex`, it is set on the `current` element as a DOM property instead of an HTML attribute. For example `{checked: true}` would do `el.checked = true` for the *current* element.
|
|
290
|
+
* - `{".class": boolean}`: If the key starts with a `.` character, its either added to or removed from the *current* element as a CSS class, based on the truthiness of the value. So `{".hidden": hide}` would toggle the `hidden` CSS class.
|
|
291
|
+
* - `{<eventName>: function}`: If the value is a `function` it is set as an event listener for the event with the name given by the key. For example: `{click: myClickHandler}`.
|
|
292
|
+
* - `{$<styleProp>: value}`: If the key starts with a `$` character, set a CSS style property with the name of the rest of the key to the given value. Example: `{$backgroundColor: 'red'}`.
|
|
293
|
+
* - `{create: string}`: Add the value string as a CSS class to the *current* element, *after* the browser has finished doing a layout pass. This behavior only triggers when the scope setting the `create` is the top-level scope being (re-)run. This allows for creation transitions, without triggering the transitions for deeply nested elements being drawn as part of a larger component. The string may also contain multiple dot-separated CSS classes, such as `.fade.grow`.
|
|
294
|
+
* - `{destroy: string}`: When the *current* element is a top-level element to be removed (due to reactivity cleanup), actual removal from the DOM is delayed by 2 seconds, and in the mean time the value string is added as a CSS class to the element, allowing for a deletion transition. The string may also contain multiple dot-separated CSS classes, such as `.fade.shrink`.
|
|
295
|
+
* - `{create: function}` and `{destroy: function}`: The function is invoked when the *current* element is the top-level element being created/destroyed. It can be used for more involved creation/deletion animations. In case of `destroy`, the function is responsible for actually removing the element from the DOM (eventually). See `transitions.ts` in the Aberdeen source code for some examples.
|
|
296
|
+
* - `{bind: <obsValue>}`: Create a two-way binding element between the `value` property of the given observable (proxy) variable, and the *current* input element (`<input>`, `<select>` or `<textarea>`). This is often used together with {@link ref}, in order to use properties other than `.value`.
|
|
297
|
+
* - `{<any>: <obsvalue>}`: Create a new observe scope and read the `value` property of the given observable (proxy) variable from within it, and apply the contained value using any of the other rules in this list. Example:
|
|
298
|
+
* ```typescript
|
|
299
|
+
* const myColor = proxy('red');
|
|
300
|
+
* $('p:Test', {$color: myColor, click: () => myColor.value = 'yellow'})
|
|
301
|
+
* // Clicking the text will cause it to change color without recreating the <p> itself
|
|
302
|
+
* ```
|
|
303
|
+
* This is often used together with {@link ref}, in order to use properties other than `.value`.
|
|
304
|
+
* - `{text: string|number}`: Add the value as a `TextNode` to the *current* element.
|
|
305
|
+
* - `{html: string}`: Add the value as HTML to the *current* element. This should only be used in exceptional situations. And of course, beware of XSS.
|
|
306
|
+
* - `{element: Node}`: Add a pre-existing HTML `Node` to the *current* element.
|
|
307
|
+
*
|
|
308
|
+
*
|
|
309
|
+
* @example Create Element
|
|
310
|
+
* ```typescript
|
|
311
|
+
* $('button.secondary.outline:Submit', {
|
|
312
|
+
* disabled: true,
|
|
313
|
+
* click: () => console.log('Clicked!'),
|
|
314
|
+
* $color: 'red'
|
|
315
|
+
* });
|
|
316
|
+
* ```
|
|
317
|
+
*
|
|
318
|
+
* @example Nested Elements & Reactive Scope
|
|
319
|
+
* ```typescript
|
|
320
|
+
* const state = proxy({ count: 0 });
|
|
321
|
+
* $('div', () => { // Outer element
|
|
322
|
+
* // This scope re-renders when state.count changes
|
|
323
|
+
* $('p:Count is ${state.count}`);
|
|
324
|
+
* $('button:Increment', { click: () => state.count++ });
|
|
325
|
+
* });
|
|
326
|
+
* ```
|
|
327
|
+
*
|
|
328
|
+
* @example Two-way Binding
|
|
329
|
+
* ```typescript
|
|
330
|
+
* const user = proxy({ name: '' });
|
|
331
|
+
* $('input', { placeholder: 'Name', bind: ref(user, 'name') });
|
|
332
|
+
* $('h3', () => { // Reactive scope
|
|
333
|
+
* $(`:Hello ${user.name || 'stranger'}`);
|
|
334
|
+
* });
|
|
335
|
+
* ```
|
|
336
|
+
*
|
|
337
|
+
* @example Conditional Rendering
|
|
338
|
+
* ```typescript
|
|
339
|
+
* const show = proxy(false);
|
|
340
|
+
* $('button', { click: () => show.value = !show.value }, () => $(show.value ? ':Hide' : ':Show'));
|
|
341
|
+
* $(() => { // Reactive scope
|
|
342
|
+
* if (show.value) {
|
|
343
|
+
* $('p:Details are visible!');
|
|
344
|
+
* }
|
|
345
|
+
* });
|
|
346
|
+
* ```
|
|
347
|
+
*/
|
|
348
|
+
export declare function $(...args: (string | null | undefined | false | (() => void) | Record<string, any>)[]): void;
|
|
349
|
+
/**
|
|
350
|
+
* Inserts CSS rules into the document, optionally scoping them with a unique class name.
|
|
351
|
+
*
|
|
352
|
+
* Takes a JavaScript object representation of CSS rules. camelCased property keys are
|
|
353
|
+
* converted to kebab-case (e.g., `fontSize` becomes `font-size`).
|
|
354
|
+
*
|
|
355
|
+
* @param style - An object where keys are CSS selectors (or camelCased properties) and values are
|
|
356
|
+
* CSS properties or nested rule objects.
|
|
357
|
+
* - Selectors are usually combined as a descendant-relationship (meaning just a space character) with their parent selector.
|
|
358
|
+
* - In case a selector contains a `&`, that character will be replaced by the parent selector.
|
|
359
|
+
* - Selectors will be split on `,` characters, each combining with the parent selector with *or* semantics.
|
|
360
|
+
* - Selector starting with `'@'` define at-rules like media queries. They may be nested within regular selectors.
|
|
361
|
+
* @param global - If `true`, styles are inserted globally without prefixing.
|
|
362
|
+
* If `false` (default), all selectors are prefixed with a unique generated
|
|
363
|
+
* class name (e.g., `.AbdStl1`) to scope the styles.
|
|
364
|
+
* @returns The unique class name prefix used for scoping (e.g., `.AbdStl1`), or an empty string
|
|
365
|
+
* if `global` was `true`. Use this prefix with {@link $} to apply the styles.
|
|
366
|
+
*
|
|
367
|
+
* @example Scoped Styles
|
|
368
|
+
* ```typescript
|
|
369
|
+
* const scopeClass = insertCss({
|
|
370
|
+
* color: 'red',
|
|
371
|
+
* padding: '10px',
|
|
372
|
+
* '&:hover': { // Use '&' for the root scoped selector
|
|
373
|
+
* backgroundColor: '#535'
|
|
374
|
+
* },
|
|
375
|
+
* '.child-element': { // Nested selector
|
|
376
|
+
* fontWeight: 'bold'
|
|
377
|
+
* },
|
|
378
|
+
* '@media (max-width: 600px)': {
|
|
379
|
+
* padding: '5px'
|
|
380
|
+
* }
|
|
381
|
+
* });
|
|
382
|
+
* // scopeClass might be ".AbdStl1"
|
|
383
|
+
*
|
|
384
|
+
* // Apply the styles
|
|
385
|
+
* $(scopeClass, () => { // Add class to the div
|
|
386
|
+
* $(`:Scoped content`);
|
|
387
|
+
* $('div.child-element:Child'); // .AbdStl1 .child-element rule applies
|
|
388
|
+
* });
|
|
389
|
+
* ```
|
|
390
|
+
*
|
|
391
|
+
* @example Global Styles
|
|
392
|
+
* ```typescript
|
|
393
|
+
* insertCss({
|
|
394
|
+
* '*': {
|
|
395
|
+
* fontFamily: 'monospace',
|
|
396
|
+
* },
|
|
397
|
+
* 'a': {
|
|
398
|
+
* textDecoration: 'none',
|
|
399
|
+
* color: "#107ab0",
|
|
400
|
+
* }
|
|
401
|
+
* }, true); // Pass true for global
|
|
402
|
+
*
|
|
403
|
+
* $('a:Styled link');
|
|
404
|
+
* ```
|
|
405
|
+
*/
|
|
406
|
+
export declare function insertCss(style: object, global?: boolean): string;
|
|
407
|
+
/**
|
|
408
|
+
* Sets a custom error handler function for errors that occur asynchronously
|
|
409
|
+
* within reactive scopes (e.g., during updates triggered by proxy changes in
|
|
410
|
+
* {@link observe} or {@link $} render functions).
|
|
411
|
+
*
|
|
412
|
+
* The default handler logs the error to `console.error` and adds a simple
|
|
413
|
+
* 'Error' message div to the DOM at the location where the error occurred (if possible).
|
|
414
|
+
*
|
|
415
|
+
* Your handler can provide custom logging, UI feedback, or suppress the default
|
|
416
|
+
* error message.
|
|
417
|
+
*
|
|
418
|
+
* @param handler - A function that accepts the `Error` object.
|
|
419
|
+
* - Return `false` to prevent adding an error message to the DOM.
|
|
420
|
+
* - Return `true` or `undefined` (or throw) to allow the error messages to be added to the DOM.
|
|
421
|
+
*
|
|
422
|
+
* @example Custom Logging and Suppressing Default Message
|
|
423
|
+
* ```typescript
|
|
467
424
|
* setErrorHandler(error => {
|
|
468
|
-
*
|
|
469
|
-
*
|
|
470
|
-
*
|
|
471
|
-
*
|
|
472
|
-
*
|
|
473
|
-
*
|
|
474
|
-
*
|
|
475
|
-
*
|
|
425
|
+
* console.warn('Aberdeen render error:', error.message);
|
|
426
|
+
* // Log to error reporting service
|
|
427
|
+
* // myErrorReporter.log(error);
|
|
428
|
+
*
|
|
429
|
+
* try {
|
|
430
|
+
* // Attempt to show a custom message in the UI
|
|
431
|
+
* $('div.error-display:Oops, something went wrong!');
|
|
432
|
+
* } catch (e) {
|
|
433
|
+
* // Ignore errors during error handling itself
|
|
434
|
+
* }
|
|
435
|
+
*
|
|
436
|
+
* return false; // Suppress default console log and DOM error message
|
|
437
|
+
* });
|
|
438
|
+
*
|
|
439
|
+
* // Cause an error within a render scope.
|
|
440
|
+
* $('div.box', () => {
|
|
441
|
+
* noSuchFunction();
|
|
476
442
|
* })
|
|
477
443
|
* ```
|
|
478
444
|
*/
|
|
479
445
|
export declare function setErrorHandler(handler?: (error: Error) => boolean | undefined): void;
|
|
480
446
|
/**
|
|
481
|
-
*
|
|
482
|
-
*
|
|
483
|
-
*
|
|
484
|
-
*
|
|
485
|
-
*
|
|
447
|
+
* Gets the parent DOM `Element` where nodes created by {@link $} would currently be inserted.
|
|
448
|
+
*
|
|
449
|
+
* This is context-dependent based on the current reactive scope (e.g., inside a {@link mount}
|
|
450
|
+
* call or a {@link $} element's render function).
|
|
451
|
+
*
|
|
452
|
+
* **Note:** While this provides access to the DOM element, directly manipulating it outside
|
|
453
|
+
* of Aberdeen's control is generally discouraged. Prefer declarative updates using {@link $}.
|
|
454
|
+
*
|
|
455
|
+
* @returns The current parent `Element` for DOM insertion.
|
|
456
|
+
*
|
|
457
|
+
* @example Get parent for attaching a third-party library
|
|
458
|
+
* ```typescript
|
|
459
|
+
* function thirdPartyLibInit(parentElement) {
|
|
460
|
+
* parentElement.innerHTML = "This element is managed by a <em>third party</em> lib."
|
|
461
|
+
* }
|
|
462
|
+
*
|
|
463
|
+
* $('div.box', () => {
|
|
464
|
+
* // Get the div.box element just created
|
|
465
|
+
* const containerElement = getParentElement();
|
|
466
|
+
* thirdPartyLibInit(containerElement);
|
|
467
|
+
* });
|
|
468
|
+
* ```
|
|
486
469
|
*/
|
|
487
470
|
export declare function getParentElement(): Element;
|
|
488
471
|
/**
|
|
489
|
-
*
|
|
490
|
-
*
|
|
491
|
-
*
|
|
472
|
+
* Registers a cleanup function to be executed just before the current reactive scope
|
|
473
|
+
* is destroyed or redraws.
|
|
474
|
+
*
|
|
475
|
+
* This is useful for releasing resources, removing manual event listeners, or cleaning up
|
|
476
|
+
* side effects associated with the scope. Cleaners are run in reverse order of registration.
|
|
477
|
+
*
|
|
478
|
+
* Scopes are created by functions like {@link observe}, {@link mount}, {@link $} (when given a render function),
|
|
479
|
+
* and internally by constructs like {@link onEach}.
|
|
480
|
+
*
|
|
481
|
+
* @param cleaner - The function to execute during cleanup.
|
|
482
|
+
*
|
|
483
|
+
* @example Maintaing a sum for a changing array
|
|
484
|
+
* ```typescript
|
|
485
|
+
* const myArray = proxy([3, 5, 10]);
|
|
486
|
+
* let sum = proxy(0);
|
|
487
|
+
*
|
|
488
|
+
* // Show the array items and maintain the sum
|
|
489
|
+
* onEach(myArray, (item, index) => {
|
|
490
|
+
* $(`code:${index}→${item}`);
|
|
491
|
+
* // We'll update sum.value using peek, as += first does a read, but
|
|
492
|
+
* // we don't want to subscribe.
|
|
493
|
+
* peek(() => sum.value += item);
|
|
494
|
+
* // Clean gets called before each rerun for a certain item index
|
|
495
|
+
* // No need for peek here, as the clean code doesn't run in an
|
|
496
|
+
* // observe scope.
|
|
497
|
+
* clean(() => sum.value -= item);
|
|
498
|
+
* })
|
|
499
|
+
*
|
|
500
|
+
* // Show the sum
|
|
501
|
+
* $('h1', {text: sum});
|
|
502
|
+
*
|
|
503
|
+
* // Make random changes to the array
|
|
504
|
+
* const rnd = () => 0|(Math.random()*20);
|
|
505
|
+
* setInterval(() => myArray[rnd()] = rnd(), 1000);
|
|
506
|
+
* ```
|
|
492
507
|
*/
|
|
493
|
-
export declare function clean(
|
|
508
|
+
export declare function clean(cleaner: () => void): void;
|
|
494
509
|
/**
|
|
495
|
-
*
|
|
496
|
-
* during its execution
|
|
497
|
-
*
|
|
498
|
-
* no cause the outer function to rerun.
|
|
510
|
+
* Creates a reactive scope that automatically re-executes the provided function
|
|
511
|
+
* whenever any proxied data (created by {@link proxy}) read during its last execution changes, storing
|
|
512
|
+
* its return value in an observable.
|
|
499
513
|
*
|
|
500
|
-
*
|
|
501
|
-
* @
|
|
502
|
-
* @
|
|
514
|
+
* Updates are batched and run asynchronously shortly after the changes occur.
|
|
515
|
+
* Use {@link clean} to register cleanup logic for the scope.
|
|
516
|
+
* Use {@link peek} or {@link unproxy} within the function to read proxied data without subscribing to it.
|
|
517
|
+
*
|
|
518
|
+
* @param func - The function to execute reactively. Any DOM manipulations should typically
|
|
519
|
+
* be done using {@link $} within this function. Its return value will be made available as an
|
|
520
|
+
* observable returned by the `observe()` function.
|
|
521
|
+
* @returns An observable object, with its `value` property containing whatever the last run of `func` returned.
|
|
522
|
+
*
|
|
523
|
+
* @example Observation creating a UI components
|
|
524
|
+
* ```typescript
|
|
525
|
+
* const data = proxy({ user: 'Frank', notifications: 42 });
|
|
526
|
+
*
|
|
527
|
+
* $('main', () => {
|
|
528
|
+
* console.log('Welcome');
|
|
529
|
+
* $('h3:Welcome, ' + data.user); // Reactive text
|
|
530
|
+
*
|
|
531
|
+
* observe(() => {
|
|
532
|
+
* // When data.notifications changes, only this inner scope reruns,
|
|
533
|
+
* // leaving the `<p>Welcome, ..</p>` untouched.
|
|
534
|
+
* console.log('Notifications');
|
|
535
|
+
* $('code.notification-badge:' + data.notifications);
|
|
536
|
+
* $('a:Notify!', {click: () => data.notifications++});
|
|
537
|
+
* });
|
|
538
|
+
* });
|
|
503
539
|
* ```
|
|
504
|
-
* let number = new Store(0)
|
|
505
|
-
* let doubled = new Store()
|
|
506
|
-
* setInterval(() => number.set(0|Math.random()*100)), 1000)
|
|
507
540
|
*
|
|
508
|
-
*
|
|
509
|
-
* doubled.set(number.get() * 2)
|
|
510
|
-
* })
|
|
541
|
+
* ***Note*** that the above could just as easily be done using `$(func)` instead of `observe(func)`.
|
|
511
542
|
*
|
|
512
|
-
*
|
|
513
|
-
*
|
|
543
|
+
* @example Observation with return value
|
|
544
|
+
* ```typescript
|
|
545
|
+
* const counter = proxy(0);
|
|
546
|
+
* setInterval(() => counter.value++, 1000);
|
|
547
|
+
* const double = observe(() => counter.value * 2);
|
|
548
|
+
*
|
|
549
|
+
* $('h3', () => {
|
|
550
|
+
* $(`:counter=${counter.value} double=${double.value}`);
|
|
514
551
|
* })
|
|
552
|
+
* ```
|
|
553
|
+
*
|
|
554
|
+
* @overload
|
|
555
|
+
* @param func Func without a return value.
|
|
515
556
|
*/
|
|
516
|
-
export declare function observe(func: () =>
|
|
517
|
-
/**
|
|
518
|
-
* Like `observe`, but instead of deferring running the observer function until
|
|
519
|
-
* a setTimeout 0, run it immediately and synchronously when a change to one of
|
|
520
|
-
* the observed `Store`s is made. Use this sparingly, as this prevents Aberdeen
|
|
521
|
-
* from doing the usual batching and smart ordering of observers, leading to
|
|
522
|
-
* performance problems and observing of 'weird' partial states.
|
|
523
|
-
* @param func The function to be (repeatedly) executed.
|
|
524
|
-
* @returns The mount id (usable for `unmount`) if this is a top-level observe.
|
|
525
|
-
*/
|
|
526
|
-
export declare function immediateObserve(func: () => void): number | undefined;
|
|
557
|
+
export declare function observe<T extends (DatumType | void)>(func: () => T): ValueRef<T>;
|
|
527
558
|
/**
|
|
528
|
-
*
|
|
529
|
-
|
|
530
|
-
*
|
|
531
|
-
*
|
|
532
|
-
*
|
|
559
|
+
* Similar to {@link observe}, creates a reactive scope that re-executes the function
|
|
560
|
+
* when its proxied dependencies change.
|
|
561
|
+
*
|
|
562
|
+
* **Difference:** Updates run **synchronously and immediately** after the proxy modification
|
|
563
|
+
* that triggered the update occurs.
|
|
564
|
+
*
|
|
565
|
+
* **Caution:** Use sparingly. Immediate execution bypasses Aberdeen's usual batching and
|
|
566
|
+
* ordering optimizations, which can lead to performance issues or observing inconsistent
|
|
567
|
+
* intermediate states if multiple related updates are applied sequentially.
|
|
568
|
+
* Prefer {@link observe} or {@link $} for most use cases.
|
|
569
|
+
*
|
|
570
|
+
* @param func - The function to execute reactively and synchronously.
|
|
533
571
|
*
|
|
534
572
|
* @example
|
|
535
|
-
* ```
|
|
536
|
-
*
|
|
537
|
-
* setInterval(() => store.modify(v => v+1), 1000)
|
|
573
|
+
* ```javascript
|
|
574
|
+
* const state = proxy({ single: 'A' });
|
|
538
575
|
*
|
|
539
|
-
*
|
|
540
|
-
*
|
|
541
|
-
* })
|
|
542
|
-
*
|
|
576
|
+
* immediateObserve(() => {
|
|
577
|
+
* state.double = state.single + state.single
|
|
578
|
+
* });
|
|
579
|
+
* console.log(state.double); // 'AA'
|
|
543
580
|
*
|
|
544
|
-
*
|
|
581
|
+
* state.single = 'B';
|
|
582
|
+
* // Synchronously:
|
|
583
|
+
* console.log(state.double); // 'BB'
|
|
545
584
|
* ```
|
|
546
|
-
|
|
547
|
-
|
|
585
|
+
*/
|
|
586
|
+
export declare function immediateObserve(func: () => void): void;
|
|
587
|
+
/**
|
|
588
|
+
* Attaches a reactive Aberdeen UI fragment to an existing DOM element. Without the use of
|
|
589
|
+
* this function, {@link $} will assume `document.body` as its root.
|
|
548
590
|
*
|
|
549
|
-
*
|
|
550
|
-
*
|
|
551
|
-
*
|
|
552
|
-
* $('button:>>', {click: () => selected.modify(n => n+1)})
|
|
591
|
+
* It creates a top-level reactive scope associated with the `parentElement`. The provided
|
|
592
|
+
* function `func` is executed immediately within this scope. Any proxied data read by `func`
|
|
593
|
+
* will cause it to re-execute when the data changes, updating the DOM elements created within it.
|
|
553
594
|
*
|
|
554
|
-
*
|
|
555
|
-
*
|
|
556
|
-
*
|
|
557
|
-
* $('input', {type: 'color', value: '#ffffff' bind: colors(selected.get())})
|
|
558
|
-
* })
|
|
595
|
+
* Calls to {@link $} inside `func` will append nodes to `parentElement`.
|
|
596
|
+
* You can nest {@link observe} or other {@link $} scopes within `func`.
|
|
597
|
+
* Use {@link unmountAll} to clean up all mounted scopes and their DOM nodes.
|
|
559
598
|
*
|
|
560
|
-
*
|
|
561
|
-
*
|
|
562
|
-
*
|
|
563
|
-
*
|
|
564
|
-
*
|
|
565
|
-
*
|
|
599
|
+
* Mounting scopes happens reactively, meaning that if this function is called from within another
|
|
600
|
+
* ({@link observe} or {@link $} or {@link mount}) scope that gets cleaned up, so will the mount.
|
|
601
|
+
*
|
|
602
|
+
* @param parentElement - The native DOM `Element` to which the UI fragment will be appended.
|
|
603
|
+
* @param func - The function that defines the UI fragment, typically containing calls to {@link $}.
|
|
604
|
+
*
|
|
605
|
+
* @example Basic Mount
|
|
606
|
+
* ```javascript
|
|
607
|
+
* // Create a pre-existing DOM structure (without Aberdeen)
|
|
608
|
+
* document.body.innerHTML = `<h3>Static content <span id="title-extra"></span></h3><div class="box" id="app-root"></div>`;
|
|
609
|
+
*
|
|
610
|
+
* import { mount, $, proxy } from 'aberdeen';
|
|
611
|
+
*
|
|
612
|
+
* const runTime = proxy(0);
|
|
613
|
+
* setInterval(() => runTime.value++, 1000);
|
|
614
|
+
*
|
|
615
|
+
* mount(document.getElementById('app-root'), () => {
|
|
616
|
+
* $('h4:Aberdeen App');
|
|
617
|
+
* $(`p:Run time: ${runTime.value}s`);
|
|
618
|
+
* // Conditionally render some content somewhere else in the static page
|
|
619
|
+
* if (runTime.value&1) {
|
|
620
|
+
* mount(document.getElementById('title-extra'), () =>
|
|
621
|
+
* $(`i:(${runTime.value}s)`)
|
|
622
|
+
* );
|
|
623
|
+
* }
|
|
624
|
+
* });
|
|
566
625
|
* ```
|
|
567
|
-
|
|
568
|
-
|
|
626
|
+
*
|
|
627
|
+
* Note how the inner mount behaves reactively as well, automatically unmounting when it's parent observer scope re-runs.
|
|
628
|
+
*/
|
|
629
|
+
export declare function mount(parentElement: Element, func: () => void): void;
|
|
569
630
|
/**
|
|
570
|
-
*
|
|
571
|
-
*
|
|
572
|
-
*
|
|
631
|
+
* Removes all Aberdeen-managed DOM nodes and stops all active reactive scopes
|
|
632
|
+
* (created by {@link mount}, {@link observe}, {@link $} with functions, etc.).
|
|
633
|
+
*
|
|
634
|
+
* This effectively cleans up the entire Aberdeen application state.
|
|
573
635
|
*/
|
|
574
|
-
export declare function
|
|
575
|
-
/**
|
|
636
|
+
export declare function unmountAll(): void;
|
|
637
|
+
/**
|
|
638
|
+
* Executes a function *without* creating subscriptions in the current reactive scope, and returns its result.
|
|
576
639
|
*
|
|
577
|
-
*
|
|
578
|
-
*
|
|
579
|
-
* @example
|
|
580
|
-
* ```
|
|
581
|
-
* import {Store, peek, text} from aberdeen
|
|
640
|
+
* This is useful when you need to access reactive data inside a reactive scope (like {@link observe})
|
|
641
|
+
* but do not want changes to that specific data to trigger a re-execute of the scope.
|
|
582
642
|
*
|
|
583
|
-
*
|
|
643
|
+
* @template T The type of the return value of your function.
|
|
584
644
|
*
|
|
585
|
-
*
|
|
586
|
-
*
|
|
587
|
-
*
|
|
588
|
-
*
|
|
589
|
-
*
|
|
645
|
+
* @param func - The function to execute without creating subscriptions.
|
|
646
|
+
* @returns Whatever `func` returns.
|
|
647
|
+
*
|
|
648
|
+
* @example Peeking within observe
|
|
649
|
+
* ```typescript
|
|
650
|
+
* const data = proxy({ a: 1, b: 2 });
|
|
651
|
+
* observe(() => {
|
|
652
|
+
* // re-executes only when data.a changes, because data.b is peeked.
|
|
653
|
+
* const b = peek(() => data.b);
|
|
654
|
+
* console.log(`A is ${data.a}, B was ${b} when A changed.`);
|
|
655
|
+
* });
|
|
656
|
+
* data.b = 3; // Does not trigger console.log
|
|
657
|
+
* data.a = 2; // Triggers console.log (logs "A is 2, B was 3 when A changed.")
|
|
590
658
|
* ```
|
|
591
659
|
*
|
|
592
|
-
* In the above example `store.get(0)` could be replaced with `store.peek(0)` to achieve the
|
|
593
|
-
* same result without `peek()` wrapping everything. There is no non-subscribing equivalent
|
|
594
|
-
* for `count()` however.
|
|
595
660
|
*/
|
|
596
661
|
export declare function peek<T>(func: () => T): T;
|
|
662
|
+
/** When using an object as `source`. */
|
|
663
|
+
export declare function map<IN, OUT>(source: Record<string | symbol, IN>, func: (value: IN, index: string | symbol) => undefined | OUT): Record<string | symbol, OUT>;
|
|
664
|
+
/** When using an array as `source`. */
|
|
665
|
+
export declare function map<IN, OUT>(source: Array<IN>, func: (value: IN, index: number) => undefined | OUT): Array<OUT>;
|
|
666
|
+
/** When using an array as `source`. */
|
|
667
|
+
export declare function multiMap<IN, OUT extends {
|
|
668
|
+
[key: string | symbol]: DatumType;
|
|
669
|
+
}>(source: Array<IN>, func: (value: IN, index: number) => OUT | undefined): OUT;
|
|
670
|
+
/** When using an object as `source`. */
|
|
671
|
+
export declare function multiMap<K extends string | number | symbol, IN, OUT extends {
|
|
672
|
+
[key: string | symbol]: DatumType;
|
|
673
|
+
}>(source: Record<K, IN>, func: (value: IN, index: K) => OUT | undefined): OUT;
|
|
674
|
+
/** When using an object as `array`. */
|
|
675
|
+
export declare function partition<OUT_K extends string | number | symbol, IN_V>(source: IN_V[], func: (value: IN_V, key: number) => undefined | OUT_K | OUT_K[]): Record<OUT_K, Record<number, IN_V>>;
|
|
676
|
+
/** When using an object as `source`. */
|
|
677
|
+
export declare function partition<IN_K extends string | number | symbol, OUT_K extends string | number | symbol, IN_V>(source: Record<IN_K, IN_V>, func: (value: IN_V, key: IN_K) => undefined | OUT_K | OUT_K[]): Record<OUT_K, Record<IN_K, IN_V>>;
|
|
678
|
+
/**
|
|
679
|
+
* Renders a live, recursive dump of a proxied data structure (or any value)
|
|
680
|
+
* into the DOM at the current {@link $} insertion point.
|
|
681
|
+
*
|
|
682
|
+
* Uses `<ul>` and `<li>` elements to display object properties and array items.
|
|
683
|
+
* Updates reactively if the dumped data changes. Primarily intended for debugging purposes.
|
|
684
|
+
*
|
|
685
|
+
* @param data - The proxied data structure (or any value) to display.
|
|
686
|
+
* @returns The original `data` argument, allowing for chaining.
|
|
687
|
+
* @template T - The type of the data being dumped.
|
|
688
|
+
*
|
|
689
|
+
* @example Dumping reactive state
|
|
690
|
+
* ```typescript
|
|
691
|
+
* import { $, proxy, dump } from 'aberdeen';
|
|
692
|
+
*
|
|
693
|
+
* const state = proxy({
|
|
694
|
+
* user: { name: 'Frank', kids: 1 },
|
|
695
|
+
* items: ['a', 'b']
|
|
696
|
+
* });
|
|
697
|
+
*
|
|
698
|
+
* $('h2:Live State Dump');
|
|
699
|
+
* dump(state);
|
|
700
|
+
*
|
|
701
|
+
* // Change state later, the dump in the DOM will update
|
|
702
|
+
* setTimeout(() => { state.user.kids++; state.items.push('c'); }, 2000);
|
|
703
|
+
* ```
|
|
704
|
+
*/
|
|
705
|
+
export declare function dump<T>(data: T): T;
|
|
597
706
|
declare global {
|
|
598
707
|
interface String {
|
|
599
708
|
replaceAll(from: string, to: string): string;
|