aberdeen 0.2.1 → 0.2.2

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 (55) hide show
  1. package/dist/aberdeen.d.ts +573 -0
  2. package/dist/aberdeen.js +1756 -0
  3. package/dist/aberdeen.js.map +1 -0
  4. package/dist/prediction.d.ts +29 -0
  5. package/dist/prediction.js +110 -0
  6. package/dist/prediction.js.map +1 -0
  7. package/dist/route.d.ts +16 -0
  8. package/dist/route.js +119 -0
  9. package/dist/route.js.map +1 -0
  10. package/dist/transitions.d.ts +18 -0
  11. package/dist/transitions.js +67 -0
  12. package/dist/transitions.js.map +1 -0
  13. package/package.json +5 -2
  14. package/.github/workflows/deploy.yml +0 -43
  15. package/.vscode/launch.json +0 -23
  16. package/examples/input/index.html +0 -8
  17. package/examples/input/input.css +0 -56
  18. package/examples/input/input.js +0 -66
  19. package/examples/list/index.html +0 -7
  20. package/examples/list/list.js +0 -47
  21. package/examples/router/index.html +0 -8
  22. package/examples/router/page-home.js +0 -12
  23. package/examples/router/page-list.js +0 -35
  24. package/examples/router/page-settings.js +0 -6
  25. package/examples/router/router.js +0 -76
  26. package/examples/router/style.css +0 -88
  27. package/examples/tic-tac-toe/index.html +0 -8
  28. package/examples/tic-tac-toe/tic-tac-toe.css +0 -50
  29. package/examples/tic-tac-toe/tic-tac-toe.js +0 -90
  30. package/src/aberdeen.ts +0 -2037
  31. package/src/prediction.ts +0 -117
  32. package/src/route.ts +0 -121
  33. package/src/transitions.ts +0 -73
  34. package/tests/_fakedom.js +0 -255
  35. package/tests/_init.js +0 -81
  36. package/tests/array.js +0 -109
  37. package/tests/binding.js +0 -106
  38. package/tests/browsers.js +0 -22
  39. package/tests/clean.js +0 -26
  40. package/tests/count.js +0 -105
  41. package/tests/create.js +0 -92
  42. package/tests/destroy.js +0 -270
  43. package/tests/dom.js +0 -219
  44. package/tests/errors.js +0 -114
  45. package/tests/immediate.js +0 -87
  46. package/tests/map.js +0 -76
  47. package/tests/objmap.js +0 -40
  48. package/tests/onEach.js +0 -392
  49. package/tests/prediction.js +0 -97
  50. package/tests/props.js +0 -49
  51. package/tests/schedule.js +0 -44
  52. package/tests/scope.js +0 -277
  53. package/tests/sort.js +0 -105
  54. package/tests/store.js +0 -254
  55. package/tsconfig.json +0 -67
@@ -0,0 +1,573 @@
1
+ /**
2
+ * Schedule a DOM read operation to be executed in Aberdeen's internal task queue.
3
+ *
4
+ * This function is used to batch DOM read operations together, avoiding unnecessary
5
+ * layout recalculations and improving browser performance. A DOM read operation should
6
+ * only *read* from the DOM, such as measuring element dimensions or retrieving computed styles.
7
+ *
8
+ * By batching DOM reads separately from DOM writes, this prevents the browser from
9
+ * interleaving layout reads and writes, which can force additional layout recalculations.
10
+ * This helps reduce visual glitches and flashes by ensuring the browser doesn't render
11
+ * intermediate DOM states during updates.
12
+ *
13
+ * Unlike `setTimeout` or `requestAnimationFrame`, this mechanism ensures that DOM read
14
+ * operations happen before any DOM writes in the same queue cycle, minimizing layout thrashing.
15
+ *
16
+ * @param func The function to be executed as a DOM read operation.
17
+ */
18
+ export declare function scheduleDomReader(func: () => void): void;
19
+ /**
20
+ * Schedule a DOM write operation to be executed in Aberdeen's internal task queue.
21
+ *
22
+ * This function is used to batch DOM write operations together, avoiding unnecessary
23
+ * layout recalculations and improving browser performance. A DOM write operation should
24
+ * only *write* to the DOM, such as modifying element properties or applying styles.
25
+ *
26
+ * By batching DOM writes separately from DOM reads, this prevents the browser from
27
+ * interleaving layout reads and writes, which can force additional layout recalculations.
28
+ * This helps reduce visual glitches and flashes by ensuring the browser doesn't render
29
+ * intermediate DOM states during updates.
30
+ *
31
+ * Unlike `setTimeout` or `requestAnimationFrame`, this mechanism ensures that DOM write
32
+ * operations happen after all DOM reads in the same queue cycle, minimizing layout thrashing.
33
+ *
34
+ * @param func The function to be executed as a DOM write operation.
35
+ */
36
+ export declare function scheduleDomWriter(func: () => void): void;
37
+ /**
38
+ * A data store that automatically subscribes the current scope to updates
39
+ * whenever data is read from it.
40
+ *
41
+ * Supported data types are: `string`, `number`, `boolean`, `undefined`, `null`,
42
+ * `Array`, `object` and `Map`. The latter three will always have `Store` objects as
43
+ * values, creating a tree of `Store`-objects.
44
+ */
45
+ export declare class Store {
46
+ /**
47
+ * Create a new store with the given `value` as its value. Defaults to `undefined` if no value is given.
48
+ * When the value is a plain JavaScript object, an `Array` or a `Map`, it will be stored as a tree of
49
+ * `Store`s. (Calling {@link Store.get} on the store will recreate the original data strucure, though.)
50
+ *
51
+ * @example
52
+ * ```
53
+ * let emptyStore = new Store()
54
+ * let numStore = new Store(42)
55
+ * let objStore = new Store({x: {alice: 1, bob: 2}, y: [9,7,5,3,1]})
56
+ * ```
57
+ */
58
+ constructor();
59
+ constructor(value: any);
60
+ /**
61
+ *
62
+ * @returns The index for this Store within its parent collection. This will be a `number`
63
+ * when the parent collection is an array, a `string` when it's an object, or any data type
64
+ * when it's a `Map`.
65
+ *
66
+ * @example
67
+ * ```
68
+ * let store = new Store({x: 123})
69
+ * let subStore = store.ref('x')
70
+ * assert(subStore.get() === 123)
71
+ * assert(subStore.index() === 'x') // <----
72
+ * ```
73
+ */
74
+ index(): any;
75
+ /**
76
+ * @returns Resolves `path` and then retrieves the value that is there, subscribing
77
+ * to all read `Store` values. If `path` does not exist, `undefined` is returned.
78
+ * @param path - Any path terms to resolve before retrieving the value.
79
+ * @example
80
+ * ```
81
+ * let store = new Store({a: {b: {c: {d: 42}}}})
82
+ * assert('a' in store.get())
83
+ * assert(store.get('a', 'b') === {c: {d: 42}})
84
+ * ```
85
+ */
86
+ get(...path: any[]): any;
87
+ /**
88
+ * Like {@link Store.get}, but doesn't subscribe to changes.
89
+ */
90
+ peek(...path: any[]): any;
91
+ /**
92
+ * @returns Like {@link Store.get}, but throws a `TypeError` if the resulting value is not of type `number`.
93
+ * Using this instead of just {@link Store.get} is especially useful from within TypeScript.
94
+ */
95
+ getNumber(...path: any[]): number;
96
+ /**
97
+ * @returns Like {@link Store.get}, but throws a `TypeError` if the resulting value is not of type `string`.
98
+ * Using this instead of just {@link Store.get} is especially useful from within TypeScript.
99
+ */
100
+ getString(...path: any[]): string;
101
+ /**
102
+ * @returns Like {@link Store.get}, but throws a `TypeError` if the resulting value is not of type `boolean`.
103
+ * Using this instead of just {@link Store.get} is especially useful from within TypeScript.
104
+ */
105
+ getBoolean(...path: any[]): boolean;
106
+ /**
107
+ * @returns Like {@link Store.get}, but throws a `TypeError` if the resulting value is not of type `function`.
108
+ * Using this instead of just {@link Store.get} is especially useful from within TypeScript.
109
+ */
110
+ getFunction(...path: any[]): (Function);
111
+ /**
112
+ * @returns Like {@link Store.get}, but throws a `TypeError` if the resulting value is not of type `array`.
113
+ * Using this instead of just {@link Store.get} is especially useful from within TypeScript.
114
+ */
115
+ getArray(...path: any[]): any[];
116
+ /**
117
+ * @returns Like {@link Store.get}, but throws a `TypeError` if the resulting value is not of type `object`.
118
+ * Using this instead of just {@link Store.get} is especially useful from within TypeScript.
119
+ */
120
+ getObject(...path: any[]): object;
121
+ /**
122
+ * @returns Like {@link Store.get}, but throws a `TypeError` if the resulting value is not of type `map`.
123
+ * Using this instead of just {@link Store.get} is especially useful from within TypeScript.
124
+ */
125
+ getMap(...path: any[]): Map<any, any>;
126
+ /**
127
+ * Like {@link Store.get}, but the first parameter is the default value (returned when the Store
128
+ * contains `undefined`). This default value is also used to determine the expected type,
129
+ * and to throw otherwise.
130
+ *
131
+ * @example
132
+ * ```
133
+ * let store = {x: 42}
134
+ * assert(getOr(99, 'x') == 42)
135
+ * assert(getOr(99, 'y') == 99)
136
+ * getOr('hello', x') # throws TypeError (because 42 is not a string)
137
+ * ```
138
+ */
139
+ getOr<T>(defaultValue: T, ...path: any[]): T;
140
+ /** Retrieve a value, subscribing to all read `Store` values. This is a more flexible
141
+ * form of the {@link Store.get} and {@link Store.peek} methods.
142
+ *
143
+ * @returns The resulting value, or `undefined` if the `path` does not exist.
144
+ */
145
+ query(opts: {
146
+ /** The value for this path should be retrieved. Defaults to `[]`, meaning the entire `Store`. */
147
+ path?: any[];
148
+ /** A string specifying what type the query is expected to return. Options are:
149
+ * "undefined", "null", "boolean", "number", "string", "function", "array", "map"
150
+ * and "object". If the store holds a different type of value, a `TypeError`
151
+ * exception is thrown. By default (when `type` is `undefined`) no type checking
152
+ * is done.
153
+ */
154
+ type?: string;
155
+ /** Limit the depth of the retrieved data structure to this positive integer.
156
+ * When `depth` is `1`, only a single level of the value at `path` is unpacked. This
157
+ * makes no difference for primitive values (like strings), but for objects, maps and
158
+ * arrays, it means that each *value* in the resulting data structure will be a
159
+ * reference to the `Store` for that value.
160
+ */
161
+ depth?: number;
162
+ /** Return this value when the `path` does not exist. Defaults to `undefined`. */
163
+ defaultValue?: any;
164
+ /** When peek is `undefined` or `false`, the current scope will automatically be
165
+ * subscribed to changes of any parts of the store being read. When `true`, no
166
+ * subscribers will be performed.
167
+ */
168
+ peek?: boolean;
169
+ }): any;
170
+ /**
171
+ * Checks if the specified collection is empty, and subscribes the current scope to changes of the emptiness of this collection.
172
+ *
173
+ * @param path Any path terms to resolve before retrieving the value.
174
+ * @returns When the specified collection is not empty `true` is returned. If it is empty or if the value is undefined, `false` is returned.
175
+ * @throws When the value is not a collection and not undefined, an Error will be thrown.
176
+ */
177
+ isEmpty(...path: any[]): boolean;
178
+ /**
179
+ * Returns the number of items in the specified collection, and subscribes the current scope to changes in this count.
180
+ *
181
+ * @param path Any path terms to resolve before retrieving the value.
182
+ * @returns The number of items contained in the collection, or 0 if the value is undefined.
183
+ * @throws When the value is not a collection and not undefined, an Error will be thrown.
184
+ */
185
+ count(...path: any[]): number;
186
+ /**
187
+ * Returns a strings describing the type of the store value, subscribing to changes of this type.
188
+ * Note: this currently also subscribes to changes of primitive values, so changing a value from 3 to 4
189
+ * would cause the scope to be rerun. This is not great, and may change in the future. This caveat does
190
+ * not apply to changes made *inside* an object, `Array` or `Map`.
191
+ *
192
+ * @param path Any path terms to resolve before retrieving the value.
193
+ * @returns Possible options: "undefined", "null", "boolean", "number", "string", "function", "array", "map" or "object".
194
+ */
195
+ getType(...path: any[]): string;
196
+ /**
197
+ * Sets the value to the last given argument. Any earlier argument are a Store-path that is first
198
+ * resolved/created using {@link Store.makeRef}.
199
+ *
200
+ * When a `Store` is passed in as the value, its value will be copied (subscribing to changes). In
201
+ * case the value is an object, an `Array` or a `Map`, a *reference* to that data structure will
202
+ * be created, so that changes made through one `Store` will be reflected through the other. Be
203
+ * carefull not to create loops in your `Store` tree that way, as that would cause any future
204
+ * call to {@link Store.get} to throw a `RangeError` (Maximum call stack size exceeded.)
205
+ *
206
+ * If you intent to make a copy instead of a reference, call {@link Store.get} on the origin `Store`.
207
+ *
208
+ *
209
+ * @example
210
+ * ```
211
+ * let store = new Store() // Value is `undefined`
212
+ *
213
+ * store.set('x', 6) // Causes the store to become an object
214
+ * assert(store.get() == {x: 6})
215
+ *
216
+ * store.set('a', 'b', 'c', 'd') // Create parent path as objects
217
+ * assert(store.get() == {x: 6, a: {b: {c: 'd'}}})
218
+ *
219
+ * store.set(42) // Overwrites all of the above
220
+ * assert(store.get() == 42)
221
+ *
222
+ * store.set('x', 6) // Throw Error (42 is not a collection)
223
+ * ```
224
+ */
225
+ set(...pathAndValue: any[]): void;
226
+ /**
227
+ * Sets the `Store` to the given `mergeValue`, but without deleting any pre-existing
228
+ * items when a collection overwrites a similarly typed collection. This results in
229
+ * a deep merge.
230
+ *
231
+ * @example
232
+ * ```
233
+ * let store = new Store({a: {x: 1}})
234
+ * store.merge({a: {y: 2}, b: 3})
235
+ * assert(store.get() == {a: {x: 1, y: 2}, b: 3})
236
+ * ```
237
+ */
238
+ merge(...pathAndValue: any): void;
239
+ /**
240
+ * 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)
241
+ *
242
+ * @example
243
+ * ```
244
+ * let store = new Store({a: 1, b: 2})
245
+ * store.delete('a')
246
+ * assert(store.get() == {b: 2})
247
+ *
248
+ * store = new Store(['a','b','c'])
249
+ * store.delete(1)
250
+ * assert(store.get() == ['a', undefined, 'c'])
251
+ * store.delete(2)
252
+ * assert(store.get() == ['a'])
253
+ * ```
254
+ */
255
+ delete(...path: any): void;
256
+ /**
257
+ * Pushes a value to the end of the Array that is at the specified path in the store.
258
+ * If that store path is `undefined`, an Array is created first.
259
+ * The last argument is the value to be added, any earlier arguments indicate the path.
260
+ *
261
+ * @example
262
+ * ```
263
+ * let store = new Store()
264
+ * store.push(3) // Creates the array
265
+ * store.push(6)
266
+ * assert(store.get() == [3,6])
267
+ *
268
+ * store = new Store({myArray: [1,2]})
269
+ * store.push('myArray', 3)
270
+ * assert(store.get() == {myArray: [1,2,3]})
271
+ * ```
272
+ */
273
+ push(...pathAndValue: any[]): number;
274
+ /**
275
+ * {@link Store.peek} the current value, pass it through `func`, and {@link Store.set} the resulting
276
+ * value.
277
+ * @param func The function transforming the value.
278
+ */
279
+ modify(func: (value: any) => any): void;
280
+ /**
281
+ * Return a `Store` deeper within the tree by resolving the given `path`,
282
+ * subscribing to every level.
283
+ * In case `undefined` is encountered while resolving the path, a newly
284
+ * created `Store` containing `undefined` is returned. In that case, the
285
+ * `Store`'s {@link Store.isDetached} method will return `true`.
286
+ * In case something other than a collection is encountered, an error is thrown.
287
+ */
288
+ ref(...path: any[]): Store;
289
+ /**
290
+ * Similar to `ref()`, but instead of returning `undefined`, new objects are created when
291
+ * a path does not exist yet. An error is still thrown when the path tries to index an invalid
292
+ * type.
293
+ * Unlike `ref`, `makeRef` does *not* subscribe to the path levels, as it is intended to be
294
+ * a write-only operation.
295
+ *
296
+ * @example
297
+ * ```
298
+ * let store = new Store() // Value is `undefined`
299
+ *
300
+ * let ref = store.makeRef('a', 'b', 'c')
301
+ * assert(store.get() == {a: {b: {}}}
302
+ *
303
+ * ref.set(42)
304
+ * assert(store.get() == {a: {b: {c: 42}}}
305
+ *
306
+ * ref.makeRef('d') // Throw Error (42 is not a collection)
307
+ * ```
308
+ */
309
+ makeRef(...path: any[]): Store;
310
+ /**
311
+ * Iterate the specified collection (Array, Map or object), running the given code block for each item.
312
+ * When items are added to the collection at some later point, the code block will be ran for them as well.
313
+ * When an item is removed, the {@link Store.clean} handlers left by its code block are executed.
314
+ *
315
+ *
316
+ *
317
+ * @param pathAndFuncs
318
+ */
319
+ onEach(...pathAndFuncs: any): void;
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 map `Store` with the values returned by `func` and the corresponding
328
+ * 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
+ * @returns Returns `true` when the `Store` was created by {@link Store.ref}ing a path that
354
+ * does not exist.
355
+ */
356
+ isDetached(): boolean;
357
+ /**
358
+ * Dump a live view of the `Store` tree as HTML text, `ul` and `li` nodes at
359
+ * the current mount position. Meant for debugging purposes.
360
+ */
361
+ dump(): void;
362
+ }
363
+ /**
364
+ * Create a new DOM element, and insert it into the DOM at the position held by the current scope.
365
+ * @param tag - The tag of the element to be created and optionally dot-separated class names. For example: `h1` or `p.intro.has_avatar`.
366
+ * @param rest - The other arguments are flexible and interpreted based on their types:
367
+ * - `string`: Used as textContent for the element.
368
+ * - `object`: Used as attributes, properties or event listeners for the element. See {@link Store.prop} on how the distinction is made and to read about a couple of special keys.
369
+ * - `function`: The render function used to draw the scope of the element. This function gets its own `Scope`, so that if any `Store` it reads changes, it will redraw by itself.
370
+ * - `Store`: Presuming `tag` is `"input"`, `"textarea"` or `"select"`, create a two-way binding between this `Store` value and the input element. The initial value of the input will be set to the initial value of the `Store`, or the other way around if the `Store` holds `undefined`. After that, the `Store` will be updated when the input changes and vice versa.
371
+ * @example
372
+ * node('aside.editorial', 'Yada yada yada....', () => {
373
+ * node('a', {href: '/bio'}, () => {
374
+ * node('img.author', {src: '/me.jpg', alt: 'The author'})
375
+ * })
376
+ * })
377
+ */
378
+ export declare function node(tag?: string | Element, ...rest: any[]): void;
379
+ /**
380
+ * Convert an HTML string to one or more DOM elements, and add them to the current DOM scope.
381
+ * @param html - The HTML string. For example `"<section><h2>Test</h2><p>Info..</p></section>"`.
382
+ */
383
+ export declare function html(html: string): void;
384
+ /**
385
+ * Add a text node at the current Scope position.
386
+ */
387
+ export declare function text(text: string): void;
388
+ /**
389
+ * Set properties and attributes for the containing DOM element. Doing it this way
390
+ * as opposed to setting them directly from node() allows changing them later on
391
+ * without recreating the element itself. Also, code can be more readable this way.
392
+ * Note that when a nested `observe()` is used, properties set this way do NOT
393
+ * automatically revert to their previous values.
394
+ *
395
+ * Here's how properties are handled:
396
+ * - If `name` is `"create"`, `value` should be either a function that gets
397
+ * called with the element as its only argument immediately after creation,
398
+ * or a string being the name of a CSS class that gets added immediately
399
+ * after element creation, and removed shortly afterwards. This allows for
400
+ * reveal animations. However, this is intentionally *not* done
401
+ * for elements that are created as part of a larger (re)draw, to prevent
402
+ * all elements from individually animating on page creation.
403
+ * - If `name` is `"destroy"`, `value` should be a function that gets called
404
+ * with the element as its only argument, *instead of* the element being
405
+ * removed from the DOM (which the function will presumably need to do
406
+ * eventually). This can be used for a conceal animation.
407
+ * As a convenience, it's also possible to provide a string instead of
408
+ * a function, which will be added to the element as a CSS class, allowing
409
+ * for simple transitions. In this case, the DOM element in removed 2 seconds
410
+ * later (currently not configurable).
411
+ * Similar to `"create"` (and in this case doing anything else would make little
412
+ * sense), this only happens when the element being is the top-level element
413
+ * being removed from the DOM.
414
+ * - If `value` is a function, it is registered as an event handler for the
415
+ * `name` event.
416
+ * - If `name` is `"class"` or `"className"` and the `value` is an
417
+ * object, all keys of the object are either added or removed from `classList`,
418
+ * depending on whether `value` is true-like or false-like.
419
+ * - If `value` is a boolean *or* `name` is `"value"`, `"className"` or
420
+ * `"selectedIndex"`, it is set as a DOM element *property*.
421
+ * - If `name` is `"text"`, the `value` is set as the element's `textContent`.
422
+ * - If `name` is `"style"` and `value` is an object, each of its
423
+ * key/value pairs are assigned to the element's `.style`.
424
+ * - In other cases, the `value` is set as the `name` HTML *attribute*.
425
+ *
426
+ * @example
427
+ * ```
428
+ * node('input', () => {
429
+ * prop('type', 'password')
430
+ * prop('readOnly', true)
431
+ * prop('class', 'my-class')
432
+ * prop('class', {
433
+ * 'my-disabled-class': false,
434
+ * 'my-enabled-class': true,
435
+ * })
436
+ * prop({
437
+ * class: 'my-class',
438
+ * text: 'Here is something to read...',
439
+ * style: {
440
+ * backgroundColor: 'red',
441
+ * fontWeight: 'bold',
442
+ * },
443
+ * create: aberdeen.fadeIn,
444
+ * destroy: 'my-fade-out-class',
445
+ * click: myClickHandler,
446
+ * })
447
+ * })
448
+ * ```
449
+ */
450
+ export declare function prop(name: string, value: any): void;
451
+ export declare function prop(props: object): void;
452
+ /**
453
+ * Return the browser Element that `node()`s would be rendered to at this point.
454
+ * NOTE: Manually changing the DOM is not recommended in most cases. There is
455
+ * usually a better, declarative way. Although there are no hard guarantees on
456
+ * how your changes interact with Aberdeen, in most cases results will not be
457
+ * terribly surprising. Be careful within the parent element of onEach() though.
458
+ */
459
+ export declare function getParentElement(): Element;
460
+ /**
461
+ * Register a function that is to be executed right before the current reactive scope
462
+ * disappears or redraws.
463
+ * @param clean - The function to be executed.
464
+ */
465
+ export declare function clean(clean: () => void): void;
466
+ /**
467
+ * Reactively run a function, meaning the function will rerun when any `Store` that was read
468
+ * during its execution is updated.
469
+ * Calls to `observe` can be nested, such that changes to `Store`s read by the inner function do
470
+ * no cause the outer function to rerun.
471
+ *
472
+ * @param func - The function to be (repeatedly) executed.
473
+ * @returns The mount id (usable for `unmount`) if this is a top-level observe.
474
+ * @example
475
+ * ```
476
+ * let number = new Store(0)
477
+ * let doubled = new Store()
478
+ * setInterval(() => number.set(0|Math.random()*100)), 1000)
479
+ *
480
+ * observe(() => {
481
+ * doubled.set(number.get() * 2)
482
+ * })
483
+ *
484
+ * observe(() => {
485
+ * console.log(doubled.get())
486
+ * })
487
+ */
488
+ export declare function observe(func: () => void): number | undefined;
489
+ /**
490
+ * Like `observe`, but instead of deferring running the observer function until
491
+ * a setTimeout 0, run it immediately and synchronously when a change to one of
492
+ * the observed `Store`s is made. Use this sparingly, as this prevents Aberdeen
493
+ * from doing the usual batching and smart ordering of observers, leading to
494
+ * performance problems and observing of 'weird' partial states.
495
+ * @param func The function to be (repeatedly) executed.
496
+ * @returns The mount id (usable for `unmount`) if this is a top-level observe.
497
+ */
498
+ export declare function immediateObserve(func: () => void): number | undefined;
499
+ /**
500
+ * Like {@link Store.observe}, but allow the function to create DOM elements using {@link Store.node}.
501
+
502
+ * @param func - The function to be (repeatedly) executed, possibly adding DOM elements to `parentElement`.
503
+ * @param parentElement - A DOM element that will be used as the parent element for calls to `node`.
504
+ * @returns The mount id (usable for `unmount`) if this is a top-level mount.
505
+ *
506
+ * @example
507
+ * ```
508
+ * let store = new Store(0)
509
+ * setInterval(() => store.modify(v => v+1), 1000)
510
+ *
511
+ * mount(document.body, () => {
512
+ * node('h2', `${store.get()} seconds have passed`)
513
+ * })
514
+ * ```
515
+ *
516
+ * An example nesting {@link Store.observe} within `mount`:
517
+ * ```
518
+ * let selected = new Store(0)
519
+ * let colors = new Store(new Map())
520
+ *
521
+ * mount(document.body, () => {
522
+ * // This function will never rerun (as it does not read any `Store`s)
523
+ * node('button', '<<', {click: () => selected.modify(n => n-1)})
524
+ * node('button', '>>', {click: () => selected.modify(n => n+1)})
525
+ *
526
+ * observe(() => {
527
+ * // This will rerun whenever `selected` changes, recreating the <h2> and <input>.
528
+ * node('h2', '#'+selected.get())
529
+ * node('input', {type: 'color', value: '#ffffff'}, colors.ref(selected.get()))
530
+ * })
531
+ *
532
+ * observe(() => {
533
+ * // This function will rerun when `selected` or the selected color changes.
534
+ * // It will change the <body> background-color.
535
+ * prop({style: {backgroundColor: colors.get(selected.get()) || 'white'}})
536
+ * })
537
+ * })
538
+ * ```
539
+ */
540
+ export declare function mount(parentElement: Element, func: () => void): number | undefined;
541
+ /**
542
+ * Unmount one specific or all top-level mounts or observes, meaning those that were created outside of the scope
543
+ * of any other mount or observe.
544
+ * @param id Optional mount number (as returned by `mount`, `observe` or `immediateObserve`). If `undefined`, unmount all.
545
+ */
546
+ export declare function unmount(id?: number): void;
547
+ /** Runs the given function, while not subscribing the current scope when reading {@link Store.Store} values.
548
+ *
549
+ * @param func Function to be executed immediately.
550
+ * @returns Whatever `func()` returns.
551
+ * @example
552
+ * ```
553
+ * import {Store, peek, text} from aberdeen
554
+ *
555
+ * let store = new Store(['a', 'b', 'c'])
556
+ *
557
+ * mount(document.body, () => {
558
+ * // Prevent rerender when store changes
559
+ * let msg = peek(() => `Store has ${store.count()} elements, and the first is ${store.get(0)}`))
560
+ * text(msg)
561
+ * })
562
+ * ```
563
+ *
564
+ * In the above example `store.get(0)` could be replaced with `store.peek(0)` to achieve the
565
+ * same result without `peek()` wrapping everything. There is no non-subscribing equivalent
566
+ * for `count()` however.
567
+ */
568
+ export declare function peek<T>(func: () => T): T;
569
+ /**
570
+ * Run a function, while *not* causing reactive effects for any changes it makes to `Store`s.
571
+ * @param func The function to be executed once immediately.
572
+ */
573
+ export declare function inhibitEffects(func: () => void): void;