aberdeen 1.17.0 → 2.0.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/dist/src/aberdeen.d.ts +928 -944
- package/dist/src/aberdeen.js +1693 -1704
- package/dist/src/aberdeen.js.map +3 -3
- package/dist/src/index.d.ts +12 -0
- package/dist/src/index.js +11 -0
- package/dist/src/index.js.map +10 -0
- package/dist/src/prediction.d.ts +7 -4
- package/dist/src/prediction.js +18 -23
- package/dist/src/prediction.js.map +3 -3
- package/dist/src/route.d.ts +112 -99
- package/dist/src/route.js +254 -254
- package/dist/src/route.js.map +3 -3
- package/dist/src/server-dom.d.ts +158 -0
- package/dist/src/server-dom.js +458 -0
- package/dist/src/server-dom.js.map +10 -0
- package/dist/src/server.d.ts +55 -0
- package/dist/src/server.js +25 -0
- package/dist/src/server.js.map +10 -0
- package/dist/src/transitions.js +7 -4
- package/dist/src/transitions.js.map +3 -3
- package/dist/tests/environment.d.ts +24 -0
- package/dist/tests/{fakedom.js → environment.js} +239 -288
- package/dist/tests/environment.js.map +11 -0
- package/dist/tests/helpers.d.ts +15 -3
- package/dist/tests/helpers.js +277 -306
- package/dist/tests/helpers.js.map +6 -5
- package/dist-docs/Tutorial/index.html +30 -30
- package/dist-docs/aberdeen/Aberdeen/index.html +350 -0
- package/dist-docs/aberdeen/InitOptions/index.html +4 -0
- package/dist-docs/aberdeen/KeyToString/index.html +2 -0
- package/dist-docs/aberdeen/PromiseProxy/index.html +6 -6
- package/dist-docs/aberdeen/SortKeyType/index.html +2 -0
- package/dist-docs/aberdeen/TargetType/index.html +2 -0
- package/dist-docs/aberdeen/ValueRef/index.html +2 -0
- package/dist-docs/aberdeen/WindowLike/index.html +5 -0
- package/dist-docs/aberdeen/{clone → createA}/index.html +10 -5
- package/dist-docs/aberdeen/index.html +13 -54
- package/dist-docs/assets/aberdeen/aberdeen.d.ts +928 -944
- package/dist-docs/assets/aberdeen/aberdeen.js +1693 -1704
- package/dist-docs/assets/aberdeen/aberdeen.js.map +3 -3
- package/dist-docs/assets/aberdeen/index.d.ts +12 -0
- package/dist-docs/assets/aberdeen/index.js +11 -0
- package/dist-docs/assets/aberdeen/index.js.map +10 -0
- package/dist-docs/assets/aberdeen/prediction.d.ts +7 -4
- package/dist-docs/assets/aberdeen/prediction.js +18 -23
- package/dist-docs/assets/aberdeen/prediction.js.map +3 -3
- package/dist-docs/assets/aberdeen/route.d.ts +112 -99
- package/dist-docs/assets/aberdeen/route.js +254 -254
- package/dist-docs/assets/aberdeen/route.js.map +3 -3
- package/dist-docs/assets/aberdeen/server-dom.d.ts +158 -0
- package/dist-docs/assets/aberdeen/server-dom.js +458 -0
- package/dist-docs/assets/aberdeen/server-dom.js.map +10 -0
- package/dist-docs/assets/aberdeen/server.d.ts +55 -0
- package/dist-docs/assets/aberdeen/server.js +25 -0
- package/dist-docs/assets/aberdeen/server.js.map +10 -0
- package/dist-docs/assets/aberdeen/transitions.js +7 -4
- package/dist-docs/assets/aberdeen/transitions.js.map +3 -3
- package/dist-docs/assets/navigation.js +1 -1
- package/dist-docs/assets/search.js +1 -1
- package/dist-docs/dispatcher/Dispatcher/index.html +5 -6
- package/dist-docs/dispatcher/MATCH_FAILED/index.html +2 -2
- package/dist-docs/dispatcher/MATCH_REST/index.html +2 -2
- package/dist-docs/dispatcher/index.html +2 -2
- package/dist-docs/hierarchy.html +1 -1
- package/dist-docs/index-1/index.html +2 -0
- package/dist-docs/index.html +2 -2
- package/dist-docs/media/CHANGELOG.md +14 -2
- package/dist-docs/modules.html +1 -1
- package/dist-docs/prediction/applyCanon/index.html +4 -3
- package/dist-docs/prediction/applyPrediction/index.html +4 -3
- package/dist-docs/prediction/index.html +2 -2
- package/dist-docs/route/Route/index.html +9 -9
- package/dist-docs/route/RouteApi/index.html +60 -0
- package/dist-docs/route/index.html +6 -15
- package/dist-docs/route/init/index.html +5 -0
- package/dist-docs/server/RenderToStringOptions/index.html +6 -0
- package/dist-docs/server/RenderToStringResult/index.html +6 -0
- package/dist-docs/server/index.html +4 -0
- package/dist-docs/server/renderToString/index.html +6 -0
- package/dist-docs/sitemap.xml +51 -155
- package/dist-docs/transitions/grow/index.html +2 -2
- package/dist-docs/transitions/index.html +2 -2
- package/dist-docs/transitions/shrink/index.html +2 -2
- package/package.json +17 -7
- package/skill/SKILL.md +28 -28
- package/skill/aberdeen.md +471 -3448
- package/skill/dispatcher.md +6 -16
- package/skill/prediction.md +17 -5
- package/skill/route.md +95 -77
- package/skill/transitions.md +3 -3
- package/src/aberdeen.ts +1226 -740
- package/src/index.ts +13 -0
- package/src/prediction.ts +25 -24
- package/src/route.ts +192 -142
- package/src/server-dom.ts +508 -0
- package/src/server.ts +74 -0
- package/src/transitions.ts +9 -3
- package/dist/tests/fakedom.d.ts +0 -9
- package/dist/tests/fakedom.js.map +0 -10
- package/dist-docs/aberdeen/A/index.html +0 -115
- package/dist-docs/aberdeen/CUSTOM_DUMP/index.html +0 -7
- package/dist-docs/aberdeen/NO_COPY/index.html +0 -2
- package/dist-docs/aberdeen/OPAQUE/index.html +0 -12
- package/dist-docs/aberdeen/clean/index.html +0 -11
- package/dist-docs/aberdeen/copy/index.html +0 -22
- package/dist-docs/aberdeen/count/index.html +0 -7
- package/dist-docs/aberdeen/cssVars/index.html +0 -11
- package/dist-docs/aberdeen/darkMode/index.html +0 -9
- package/dist-docs/aberdeen/default/index.html +0 -341
- package/dist-docs/aberdeen/derive/index.html +0 -18
- package/dist-docs/aberdeen/disableCreateDestroy/index.html +0 -6
- package/dist-docs/aberdeen/dump/index.html +0 -11
- package/dist-docs/aberdeen/insertCss/index.html +0 -30
- package/dist-docs/aberdeen/insertGlobalCss/index.html +0 -19
- package/dist-docs/aberdeen/invertString/index.html +0 -13
- package/dist-docs/aberdeen/isEmpty/index.html +0 -12
- package/dist-docs/aberdeen/map/index.html +0 -26
- package/dist-docs/aberdeen/merge/index.html +0 -11
- package/dist-docs/aberdeen/mount/index.html +0 -17
- package/dist-docs/aberdeen/multiMap/index.html +0 -28
- package/dist-docs/aberdeen/onEach/index.html +0 -19
- package/dist-docs/aberdeen/partition/index.html +0 -36
- package/dist-docs/aberdeen/peek/index.html +0 -40
- package/dist-docs/aberdeen/proxy/index.html +0 -35
- package/dist-docs/aberdeen/ref/index.html +0 -13
- package/dist-docs/aberdeen/runQueue/index.html +0 -13
- package/dist-docs/aberdeen/setErrorHandler/index.html +0 -16
- package/dist-docs/aberdeen/setSpacingCssVars/index.html +0 -8
- package/dist-docs/aberdeen/unmountAll/index.html +0 -5
- package/dist-docs/aberdeen/unproxy/index.html +0 -11
- package/dist-docs/route/back/index.html +0 -4
- package/dist-docs/route/current/index.html +0 -2
- package/dist-docs/route/go/index.html +0 -14
- package/dist-docs/route/interceptLinks/index.html +0 -8
- package/dist-docs/route/matchCurrent/index.html +0 -10
- package/dist-docs/route/persistScroll/index.html +0 -6
- package/dist-docs/route/push/index.html +0 -6
- package/dist-docs/route/setLog/index.html +0 -3
- package/dist-docs/route/up/index.html +0 -5
package/package.json
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "aberdeen",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "2.0.0",
|
|
4
4
|
"author": "Frank van Viegen",
|
|
5
|
-
"main": "dist/src/
|
|
5
|
+
"main": "dist/src/index.js",
|
|
6
6
|
"devDependencies": {
|
|
7
7
|
"@biomejs/biome": "^1.9.4",
|
|
8
8
|
"@types/bun": "^1.3.12",
|
|
@@ -12,9 +12,9 @@
|
|
|
12
12
|
},
|
|
13
13
|
"exports": {
|
|
14
14
|
".": {
|
|
15
|
-
"development": "./dist/src/
|
|
16
|
-
"types": "./dist/src/
|
|
17
|
-
"default": "./dist/src/
|
|
15
|
+
"development": "./dist/src/index.js",
|
|
16
|
+
"types": "./dist/src/index.d.ts",
|
|
17
|
+
"default": "./dist/src/index.js"
|
|
18
18
|
},
|
|
19
19
|
"./route": {
|
|
20
20
|
"development": "./dist/src/route.js",
|
|
@@ -36,6 +36,16 @@
|
|
|
36
36
|
"types": "./dist/src/dispatcher.d.ts",
|
|
37
37
|
"default": "./dist/src/dispatcher.js"
|
|
38
38
|
},
|
|
39
|
+
"./server": {
|
|
40
|
+
"development": "./dist/src/server.js",
|
|
41
|
+
"types": "./dist/src/server.d.ts",
|
|
42
|
+
"default": "./dist/src/server.js"
|
|
43
|
+
},
|
|
44
|
+
"./server-dom": {
|
|
45
|
+
"development": "./dist/src/server-dom.js",
|
|
46
|
+
"types": "./dist/src/server-dom.d.ts",
|
|
47
|
+
"default": "./dist/src/server-dom.js"
|
|
48
|
+
},
|
|
39
49
|
"./test-helpers": {
|
|
40
50
|
"bun": "./tests/helpers.ts",
|
|
41
51
|
"types": "./dist/tests/helpers.d.ts",
|
|
@@ -57,9 +67,9 @@
|
|
|
57
67
|
"scripts": {
|
|
58
68
|
"build": "bun run build:clean && bun run build:src && bun run build:types && bun run build:tests && bun run build:docs && bun run build:skill",
|
|
59
69
|
"build:clean": "rm -rf dist dist-docs",
|
|
60
|
-
"build:src": "bun build src/aberdeen.ts src/dispatcher.ts src/prediction.ts src/route.ts src/transitions.ts --sourcemap --target browser --external '*/aberdeen.js' --outdir dist/src/",
|
|
70
|
+
"build:src": "bun build src/index.ts src/aberdeen.ts src/dispatcher.ts src/prediction.ts src/route.ts src/transitions.ts src/server.ts src/server-dom.ts --sourcemap --target browser --external '*/aberdeen.js' --external '*/server-dom.js' --outdir dist/src/",
|
|
61
71
|
"build:types": "tsc",
|
|
62
|
-
"build:tests": "bun build tests/helpers.ts tests/
|
|
72
|
+
"build:tests": "bun build tests/helpers.ts tests/environment.ts --sourcemap --target bun --external 'aberdeen' --outdir dist/tests/",
|
|
63
73
|
"build:docs": "typedoc && rm -rf dist-docs/assets/aberdeen && cp -r dist/src dist-docs/assets/aberdeen",
|
|
64
74
|
"build:skill": "typedoc --plugin typedoc-plugin-markdown --out skill --tsconfig tsconfig.json --entryPoints src/aberdeen.ts src/dispatcher.ts src/prediction.ts src/route.ts src/transitions.ts --excludeInternal --excludePrivate --hideGenerator --readme none --router module && rm -rf skill/assets skill/documents skill/README.md && cat SKILL.md > skill/SKILL.md && awk '/^-+$/ { count++; next } count >= 2' docs/Tutorial.md >> skill/SKILL.md",
|
|
65
75
|
"test": "bun test --bail",
|
package/skill/SKILL.md
CHANGED
|
@@ -41,7 +41,7 @@ A('h3#Hello world');
|
|
|
41
41
|
|
|
42
42
|
It adds a `<h3>Hello world</h3>` element to the `<body>` (which is the default mount point).
|
|
43
43
|
|
|
44
|
-
The {@link aberdeen
|
|
44
|
+
The {@link aberdeen!Aberdeen | A} function accepts various forms of arguments, which can be combined.
|
|
45
45
|
|
|
46
46
|
When a string is passed:
|
|
47
47
|
- The inital part (if any) is the name of the element to be created.
|
|
@@ -63,7 +63,7 @@ A('button.outline.secondary#Pressing me does nothing!');
|
|
|
63
63
|
A('button', '.outline', '.secondary', '#Pressing me does nothing!');
|
|
64
64
|
```
|
|
65
65
|
|
|
66
|
-
Also, we can create multiple nested DOM elements in a single {@link aberdeen
|
|
66
|
+
Also, we can create multiple nested DOM elements in a single {@link aberdeen!Aberdeen | A} invocation, *if* the parents need to have only a single child. For instance:
|
|
67
67
|
|
|
68
68
|
```javascript
|
|
69
69
|
A('div.box', '#Text within the div element...', 'input');
|
|
@@ -87,7 +87,7 @@ A('div.box input value=Marshmallow input=', el => console.log(el.target.value));
|
|
|
87
87
|
|
|
88
88
|
Note that the example is interactive - try typing something!
|
|
89
89
|
|
|
90
|
-
> **Note:** {@link aberdeen
|
|
90
|
+
> **Note:** {@link aberdeen!Aberdeen | A} also accepts object syntax as an alternative to strings (see the API reference), but the string syntax shown here is more concise and is recommended for most use cases.
|
|
91
91
|
|
|
92
92
|
## Inline styles
|
|
93
93
|
|
|
@@ -118,7 +118,7 @@ A('div mv:10px ph:20px bg:lightblue r:10% #Styled box');
|
|
|
118
118
|
|
|
119
119
|
### CSS variables
|
|
120
120
|
|
|
121
|
-
Values starting with `$` expand to native CSS custom properties via `var(--name)`. The {@link aberdeen.cssVars | A.cssVars} object offers a convenient way of setting and updating CSS custom properties at the `:root` level.
|
|
121
|
+
Values starting with `$` expand to native CSS custom properties via `var(--name)`. The {@link aberdeen!Aberdeen.cssVars | A.cssVars} object offers a convenient way of setting and updating CSS custom properties at the `:root` level.
|
|
122
122
|
|
|
123
123
|
When you add the first property to `A.cssVars`, Aberdeen automatically creates a reactive `<style>` tag in `<head>` containing the CSS custom property declarations.
|
|
124
124
|
|
|
@@ -137,7 +137,7 @@ The above generates CSS like `background: var(--primary)` and automatically inje
|
|
|
137
137
|
|
|
138
138
|
### Spacing variables
|
|
139
139
|
|
|
140
|
-
You can optionally initialize `A.cssVars` with keys `1` through `12` mapping to an exponential `rem` scale using {@link aberdeen.setSpacingCssVars | A.setSpacingCssVars}. Since CSS custom property names can't start with a digit, numeric keys are prefixed with `m` (e.g., `$3` becomes `var(--m3)`):
|
|
140
|
+
You can optionally initialize `A.cssVars` with keys `1` through `12` mapping to an exponential `rem` scale using {@link aberdeen!Aberdeen.setSpacingCssVars | A.setSpacingCssVars}. Since CSS custom property names can't start with a digit, numeric keys are prefixed with `m` (e.g., `$3` becomes `var(--m3)`):
|
|
141
141
|
|
|
142
142
|
```javascript
|
|
143
143
|
import A from 'aberdeen';
|
|
@@ -161,10 +161,10 @@ A('div mt:$3 ph:$4 #This text has 1rem top margin, 2rem left+right padding');
|
|
|
161
161
|
|
|
162
162
|
If you want different spacing, you can customize the base and unit when calling `A.setSpacingCssVars()`, or dynamically modify the values.
|
|
163
163
|
|
|
164
|
-
These shortcuts and variables are also available when using {@link aberdeen.insertCss | A.insertCss}.
|
|
164
|
+
These shortcuts and variables are also available when using {@link aberdeen!Aberdeen.insertCss | A.insertCss}.
|
|
165
165
|
|
|
166
166
|
## Nesting content
|
|
167
|
-
Of course, putting everything in a single {@link aberdeen
|
|
167
|
+
Of course, putting everything in a single {@link aberdeen!Aberdeen | A} call will get messy soon, and you'll often want to nest more than one child within a parent. To do that, you can pass in a *content* function to {@link aberdeen!Aberdeen | A}, like this:
|
|
168
168
|
|
|
169
169
|
```javascript
|
|
170
170
|
A('div.box.row id=cityContainer', () => {
|
|
@@ -176,11 +176,11 @@ A('div.box.row id=cityContainer', () => {
|
|
|
176
176
|
Why are we passing in a function instead of just, say, an array of children? I'm glad you asked! :-) For each such function Aberdeen will create an *observer*, which will play a major part in what comes next...
|
|
177
177
|
|
|
178
178
|
## Observable objects
|
|
179
|
-
Aberdeen's reactivity system is built around observable objects. These are created using the {@link aberdeen.proxy | A.proxy} function:
|
|
179
|
+
Aberdeen's reactivity system is built around observable objects. These are created using the {@link aberdeen!Aberdeen.proxy | A.proxy} function:
|
|
180
180
|
|
|
181
181
|
By convention variables that hold proxied values are prefixed with `$` so reactive reads stand out.
|
|
182
182
|
|
|
183
|
-
When you access properties of a proxied object within an observer function (the function passed to {@link aberdeen
|
|
183
|
+
When you access properties of a proxied object within an observer function (the function passed to {@link aberdeen!Aberdeen | A}), Aberdeen automatically tracks these dependencies. If the values change later, the observer function will re-run, updating only the affected parts of the DOM.
|
|
184
184
|
|
|
185
185
|
```javascript
|
|
186
186
|
import A from 'aberdeen';
|
|
@@ -232,7 +232,7 @@ Now, updating `$user.name` would only cause the *Hello* text node to be replaced
|
|
|
232
232
|
|
|
233
233
|
## Conditional rendering
|
|
234
234
|
|
|
235
|
-
Within an observer function (such as created by passing a function to {@link aberdeen
|
|
235
|
+
Within an observer function (such as created by passing a function to {@link aberdeen!Aberdeen | A}), you can use regular JavaScript logic. Like `if` and `else`, for instance:
|
|
236
236
|
|
|
237
237
|
```javascript
|
|
238
238
|
const $user = A.proxy({
|
|
@@ -250,7 +250,7 @@ A('div', () => {
|
|
|
250
250
|
|
|
251
251
|
## Observable primitive values
|
|
252
252
|
|
|
253
|
-
The {@link aberdeen.proxy | A.proxy} method wraps an object in a JavaScript [Proxy](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Proxy). As this doesn't work for primitive values (like numbers, strings and booleans), the method will *create* an object in order to make it observable. The observable value is made available as its `.value` property.
|
|
253
|
+
The {@link aberdeen!Aberdeen.proxy | A.proxy} method wraps an object in a JavaScript [Proxy](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Proxy). As this doesn't work for primitive values (like numbers, strings and booleans), the method will *create* an object in order to make it observable. The observable value is made available as its `.value` property.
|
|
254
254
|
|
|
255
255
|
```javascript
|
|
256
256
|
const $count = A.proxy(42);
|
|
@@ -341,11 +341,11 @@ A('h3', () => A('#'+$graph));
|
|
|
341
341
|
A('button text=Grow click=', () => $graph.grow());
|
|
342
342
|
```
|
|
343
343
|
|
|
344
|
-
The type returned by {@link aberdeen.proxy | A.proxy} matches the input type, meaning the type system does not distinguish proxied and unproxied objects. That makes sense, as they have the exact same methods and properties (though proxied objects may have additional side effects).
|
|
344
|
+
The type returned by {@link aberdeen!Aberdeen.proxy | A.proxy} matches the input type, meaning the type system does not distinguish proxied and unproxied objects. That makes sense, as they have the exact same methods and properties (though proxied objects may have additional side effects).
|
|
345
345
|
|
|
346
346
|
|
|
347
347
|
## Efficient list rendering with A.onEach
|
|
348
|
-
For rendering lists efficiently, Aberdeen provides the {@link aberdeen.onEach | A.onEach} function. It takes three arguments:
|
|
348
|
+
For rendering lists efficiently, Aberdeen provides the {@link aberdeen!Aberdeen.onEach | A.onEach} function. It takes three arguments:
|
|
349
349
|
1. The array to iterate over.
|
|
350
350
|
2. A render function that receives the item and its index.
|
|
351
351
|
3. An optional order function, that returns the value by which the item is to be sorted. By default, the output is sorted by array index.
|
|
@@ -384,7 +384,7 @@ A('div.row.wide height:250px', () => {
|
|
|
384
384
|
})
|
|
385
385
|
```
|
|
386
386
|
|
|
387
|
-
We can also use {@link aberdeen.onEach | A.onEach} to reactively iterate over *objects*, arrays, `Map`s and `Set`s. For objects and `Map`s, the render and order functions receive `(value, key)` instead of `(value, index)`. For `Set`s, they receive only the value. By default, Sets are ordered by that value, which only works for numbers, strings and arrays of those, so Sets of objects need an explicit order function.
|
|
387
|
+
We can also use {@link aberdeen!Aberdeen.onEach | A.onEach} to reactively iterate over *objects*, arrays, `Map`s and `Set`s. For objects and `Map`s, the render and order functions receive `(value, key)` instead of `(value, index)`. For `Set`s, they receive only the value. By default, Sets are ordered by that value, which only works for numbers, strings and arrays of those, so Sets of objects need an explicit order function.
|
|
388
388
|
|
|
389
389
|
```javascript
|
|
390
390
|
const $pairs = A.proxy({A: 'Y', B: 'X',});
|
|
@@ -407,12 +407,12 @@ A('div.row.wide margin-top:1em', () => {
|
|
|
407
407
|
})
|
|
408
408
|
```
|
|
409
409
|
|
|
410
|
-
Note the use of the provided {@link aberdeen.invertString | A.invertString} function to reverse-sort by a string value.
|
|
410
|
+
Note the use of the provided {@link aberdeen!Aberdeen.invertString | A.invertString} function to reverse-sort by a string value.
|
|
411
411
|
|
|
412
412
|
## Two-way binding
|
|
413
|
-
Aberdeen makes it easy to create two-way bindings between form elements (the various `<input>` types, `<textarea>` and `<select>`) and your data, by passing an observable object with a `.value` as `bind:` property to {@link aberdeen
|
|
413
|
+
Aberdeen makes it easy to create two-way bindings between form elements (the various `<input>` types, `<textarea>` and `<select>`) and your data, by passing an observable object with a `.value` as `bind:` property to {@link aberdeen!Aberdeen | A}.
|
|
414
414
|
|
|
415
|
-
To bind to object properties not named `.value` (e.g., `$user.name`), use {@link aberdeen.ref | A.ref}. This creates a new observable A.proxy whose `.value` property directly maps to the specified property (e.g., `name`) on your original observable object (e.g., `$user`).
|
|
415
|
+
To bind to object properties not named `.value` (e.g., `$user.name`), use {@link aberdeen!Aberdeen.ref | A.ref}. This creates a new observable A.proxy whose `.value` property directly maps to the specified property (e.g., `name`) on your original observable object (e.g., `$user`).
|
|
416
416
|
|
|
417
417
|
```javascript
|
|
418
418
|
import A from 'aberdeen';
|
|
@@ -443,7 +443,7 @@ A('div.box', () => {
|
|
|
443
443
|
```
|
|
444
444
|
|
|
445
445
|
## CSS
|
|
446
|
-
Through the {@link aberdeen.insertCss | A.insertCss} function, Aberdeen provides a way to create component-local CSS.
|
|
446
|
+
Through the {@link aberdeen!Aberdeen.insertCss | A.insertCss} function, Aberdeen provides a way to create component-local CSS.
|
|
447
447
|
|
|
448
448
|
For simple single-element styles, you can pass a string directly:
|
|
449
449
|
|
|
@@ -474,7 +474,7 @@ A('div.box', myBoxStyle, 'button#Click me');
|
|
|
474
474
|
|
|
475
475
|
The `"&"` selector refers to the element with the generated class itself. Child selectors like `"button"` are scoped to descendants of that element, while pseudo-selectors like `"&:hover"` apply to the element itself.
|
|
476
476
|
|
|
477
|
-
This allows you to create single-file components with advanced CSS rules. The {@link aberdeen.insertGlobalCss | A.insertGlobalCss} function can be used to add CSS without a class prefix - it accepts the same string or object syntax.
|
|
477
|
+
This allows you to create single-file components with advanced CSS rules. The {@link aberdeen!Aberdeen.insertGlobalCss | A.insertGlobalCss} function can be used to add CSS without a class prefix - it accepts the same string or object syntax.
|
|
478
478
|
|
|
479
479
|
Both functions support the same CSS shortcuts and variables as inline styles (see above). For example:
|
|
480
480
|
|
|
@@ -552,7 +552,7 @@ A('div.row.wide height:250px', () => {
|
|
|
552
552
|
|
|
553
553
|
## Advanced: Peeking without subscribing
|
|
554
554
|
|
|
555
|
-
Sometimes you need to read reactive data inside an observer scope without creating a subscription to that data. The {@link aberdeen.peek | A.peek} function allows you to do this:
|
|
555
|
+
Sometimes you need to read reactive data inside an observer scope without creating a subscription to that data. The {@link aberdeen!Aberdeen.peek | A.peek} function allows you to do this:
|
|
556
556
|
|
|
557
557
|
```javascript
|
|
558
558
|
import A from 'aberdeen';
|
|
@@ -596,7 +596,7 @@ A('h3 text=', $derived);
|
|
|
596
596
|
A('button text=Increment click=', () => $original.value++);
|
|
597
597
|
```
|
|
598
598
|
|
|
599
|
-
The {@link aberdeen.derive | A.derive} function makes the above a little easier. It works just like passing a function to {@link aberdeen
|
|
599
|
+
The {@link aberdeen!Aberdeen.derive | A.derive} function makes the above a little easier. It works just like passing a function to {@link aberdeen!Aberdeen | A}, creating an observer, the only difference being that the value returned by the function is reactively assigned to the `value` property of the observable object returned by `derive`. So the above could also be written as:
|
|
600
600
|
|
|
601
601
|
```javascript
|
|
602
602
|
const $original = A.proxy(1);
|
|
@@ -606,7 +606,7 @@ A('h3 text=', $derived);
|
|
|
606
606
|
A('button text=Increment click=', () => $original.value++);
|
|
607
607
|
```
|
|
608
608
|
|
|
609
|
-
For deriving values from (possibly large) arrays, objects, Maps or Sets, Aberdeen provides specialized functions that enable fast, incremental updates to derived data: {@link aberdeen.map | A.map} (each item becomes zero or one derived item), {@link aberdeen.multiMap | A.multiMap} (each item becomes any number of derived items), {@link aberdeen.count | A.count} (reactively counts the number of object properties or collection items), {@link aberdeen.isEmpty | A.isEmpty} (true when the object/array/Map/Set has no items) and {@link aberdeen.partition | A.partition} (sorts each item into one or more buckets). An example:
|
|
609
|
+
For deriving values from (possibly large) arrays, objects, Maps or Sets, Aberdeen provides specialized functions that enable fast, incremental updates to derived data: {@link aberdeen!Aberdeen.map | A.map} (each item becomes zero or one derived item), {@link aberdeen!Aberdeen.multiMap | A.multiMap} (each item becomes any number of derived items), {@link aberdeen!Aberdeen.count | A.count} (reactively counts the number of object properties or collection items), {@link aberdeen!Aberdeen.isEmpty | A.isEmpty} (true when the object/array/Map/Set has no items) and {@link aberdeen!Aberdeen.partition | A.partition} (sorts each item into one or more buckets). An example:
|
|
610
610
|
|
|
611
611
|
```javascript
|
|
612
612
|
import A from 'aberdeen';
|
|
@@ -645,7 +645,7 @@ A(() => {
|
|
|
645
645
|
|
|
646
646
|
## UI Components
|
|
647
647
|
|
|
648
|
-
UI Components in Aberdeen are just functions, named `draw<Something>` by convention, that use {@link aberdeen
|
|
648
|
+
UI Components in Aberdeen are just functions, named `draw<Something>` by convention, that use {@link aberdeen!Aberdeen | A} to create some DOM structure. They can accept arguments, return (proxied) values and create local (proxied) state just like any other function.
|
|
649
649
|
|
|
650
650
|
```javascript
|
|
651
651
|
function drawCounter(initialValue = 0) {
|
|
@@ -665,7 +665,7 @@ A('input value=', $second); // Bind the second counter to an input field
|
|
|
665
665
|
|
|
666
666
|
## Debugging with A.dump()
|
|
667
667
|
|
|
668
|
-
The {@link aberdeen.dump | A.dump} function creates a live, interactive tree view of any data structure in the DOM. It's particularly useful for debugging reactive state:
|
|
668
|
+
The {@link aberdeen!Aberdeen.dump | A.dump} function creates a live, interactive tree view of any data structure in the DOM. It's particularly useful for debugging reactive state:
|
|
669
669
|
|
|
670
670
|
```javascript
|
|
671
671
|
import A from 'aberdeen';
|
|
@@ -704,7 +704,7 @@ It takes HTML on stdin (paste it and press `ctrl-d` for end-of-file), and output
|
|
|
704
704
|
|
|
705
705
|
Aberdeen provides an optional built-in router via the {@link route} module. The router is reactive and integrates seamlessly with browser history.
|
|
706
706
|
|
|
707
|
-
The {@link route.current} object is an observable that reflects the current URL:
|
|
707
|
+
The {@link route!RouteApi.current | route.current} object is an observable that reflects the current URL:
|
|
708
708
|
|
|
709
709
|
```javascript
|
|
710
710
|
import A from 'aberdeen';
|
|
@@ -716,7 +716,7 @@ A(() => {
|
|
|
716
716
|
});
|
|
717
717
|
```
|
|
718
718
|
|
|
719
|
-
To navigate programmatically, use {@link route.go}:
|
|
719
|
+
To navigate programmatically, use {@link route!RouteApi.go | route.go}:
|
|
720
720
|
|
|
721
721
|
```javascript
|
|
722
722
|
import A from 'aberdeen';
|
|
@@ -733,7 +733,7 @@ A('button ml:1rem #Go to user 123', {
|
|
|
733
733
|
});
|
|
734
734
|
```
|
|
735
735
|
|
|
736
|
-
For convenience, you can call {@link route.interceptLinks} once to automatically convert clicks on local `<a>` tags into Aberdeen routing, so you can use regular anchor tags without manual click handlers. Example: `A('a href=/settings text=Settings')`.
|
|
736
|
+
For convenience, you can call {@link route!RouteApi.interceptLinks | route.interceptLinks} once to automatically convert clicks on local `<a>` tags into Aberdeen routing, so you can use regular anchor tags without manual click handlers. Example: `A('a href=/settings text=Settings')`.
|
|
737
737
|
|
|
738
738
|
```javascript
|
|
739
739
|
import A from 'aberdeen';
|
|
@@ -744,7 +744,7 @@ route.interceptLinks(); // Just once on startup:
|
|
|
744
744
|
A('a role=button href=/settings #Go to settings')
|
|
745
745
|
```
|
|
746
746
|
|
|
747
|
-
The {@link route.push} function is useful for overlays that should be closeable with browser back:
|
|
747
|
+
The {@link route!RouteApi.push | route.push} function is useful for overlays that should be closeable with browser back:
|
|
748
748
|
|
|
749
749
|
```javascript
|
|
750
750
|
import A from 'aberdeen';
|