aberdeen 1.6.0 → 1.7.1
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/README.md +22 -22
- package/dist/aberdeen.d.ts +173 -129
- package/dist/aberdeen.js +188 -95
- package/dist/aberdeen.js.map +3 -3
- package/dist/dispatcher.d.ts +10 -7
- package/dist/dispatcher.js +11 -10
- package/dist/dispatcher.js.map +3 -3
- package/dist/route.d.ts +17 -0
- package/dist/route.js +62 -20
- package/dist/route.js.map +3 -3
- package/dist-min/aberdeen.js +9 -7
- package/dist-min/aberdeen.js.map +3 -3
- package/dist-min/dispatcher.js +2 -2
- package/dist-min/dispatcher.js.map +3 -3
- package/dist-min/route.js +2 -2
- package/dist-min/route.js.map +3 -3
- package/html-to-aberdeen +3 -6
- package/package.json +1 -1
- package/skill/SKILL.md +286 -76
- package/skill/aberdeen.md +219 -203
- package/skill/dispatcher.md +16 -13
- package/skill/prediction.md +3 -3
- package/skill/route.md +44 -16
- package/skill/transitions.md +3 -3
- package/src/aberdeen.ts +403 -237
- package/src/dispatcher.ts +16 -13
- package/src/route.ts +90 -19
package/skill/dispatcher.md
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
[**Aberdeen v1.
|
|
1
|
+
[**Aberdeen v1.7.1**](README.md)
|
|
2
2
|
|
|
3
3
|
***
|
|
4
4
|
|
|
@@ -10,13 +10,16 @@
|
|
|
10
10
|
|
|
11
11
|
### Dispatcher
|
|
12
12
|
|
|
13
|
-
Defined in: [dispatcher.ts:
|
|
13
|
+
Defined in: [dispatcher.ts:61](https://github.com/vanviegen/aberdeen/blob/bfa4e24ebd7624d1d66bdae5c920bbdd10f3fa80/src/dispatcher.ts#L61)
|
|
14
14
|
|
|
15
15
|
Simple route matcher and dispatcher.
|
|
16
16
|
|
|
17
17
|
Example usage:
|
|
18
18
|
|
|
19
19
|
```ts
|
|
20
|
+
import * as route from 'aberdeen/route';
|
|
21
|
+
import { Dispatcher, MATCH_REST } from 'aberdeen/dispatcher';
|
|
22
|
+
|
|
20
23
|
const dispatcher = new Dispatcher();
|
|
21
24
|
|
|
22
25
|
dispatcher.addRoute("user", Number, "stream", String, (id, stream) => {
|
|
@@ -26,7 +29,7 @@ dispatcher.addRoute("user", Number, "stream", String, (id, stream) => {
|
|
|
26
29
|
dispatcher.dispatch(["user", "42", "stream", "music"]);
|
|
27
30
|
// Logs: User 42, stream music
|
|
28
31
|
|
|
29
|
-
dispatcher.addRoute("search",
|
|
32
|
+
dispatcher.addRoute("search", MATCH_REST, (terms: string[]) => {
|
|
30
33
|
console.log("Search terms:", terms);
|
|
31
34
|
});
|
|
32
35
|
|
|
@@ -50,7 +53,7 @@ dispatcher.dispatch(["search", "classical", "piano"]);
|
|
|
50
53
|
|
|
51
54
|
> **addRoute**\<`T`, `H`\>(...`args`): `void`
|
|
52
55
|
|
|
53
|
-
Defined in: [dispatcher.ts:
|
|
56
|
+
Defined in: [dispatcher.ts:73](https://github.com/vanviegen/aberdeen/blob/bfa4e24ebd7624d1d66bdae5c920bbdd10f3fa80/src/dispatcher.ts#L73)
|
|
54
57
|
|
|
55
58
|
Add a route with matchers and a handler function.
|
|
56
59
|
|
|
@@ -76,8 +79,8 @@ Handler function type, inferred from the matchers.
|
|
|
76
79
|
|
|
77
80
|
An array of matchers followed by a handler function. Each matcher can be:
|
|
78
81
|
- A string: matches exactly that string.
|
|
79
|
-
- A function: takes a string segment and returns a value (of any type) if it matches, or [
|
|
80
|
-
- The special [
|
|
82
|
+
- A function: takes a string segment and returns a value (of any type) if it matches, or [MATCH\_FAILED](#match_failed) if it doesn't match. The return value (if not `MATCH_FAILED` and not `NaN`) is passed as a parameter to the handler function. The standard JavaScript functions `Number` and `String` can be used to match numeric and string segments respectively.
|
|
83
|
+
- The special [MATCH\_REST](#match_rest) symbol: matches the rest of the segments as an array of strings. Only one `MATCH_REST` is allowed.
|
|
81
84
|
|
|
82
85
|
###### Returns
|
|
83
86
|
|
|
@@ -87,7 +90,7 @@ An array of matchers followed by a handler function. Each matcher can be:
|
|
|
87
90
|
|
|
88
91
|
> **dispatch**(`segments`): `boolean`
|
|
89
92
|
|
|
90
|
-
Defined in: [dispatcher.ts:
|
|
93
|
+
Defined in: [dispatcher.ts:94](https://github.com/vanviegen/aberdeen/blob/bfa4e24ebd7624d1d66bdae5c920bbdd10f3fa80/src/dispatcher.ts#L94)
|
|
91
94
|
|
|
92
95
|
Dispatches the given segments to the first route handler that matches.
|
|
93
96
|
|
|
@@ -107,20 +110,20 @@ True if a matching route was found and handled, false otherwise.
|
|
|
107
110
|
|
|
108
111
|
## Variables
|
|
109
112
|
|
|
110
|
-
###
|
|
113
|
+
### MATCH\_FAILED
|
|
111
114
|
|
|
112
|
-
> `const` **
|
|
115
|
+
> `const` **MATCH\_FAILED**: unique `symbol`
|
|
113
116
|
|
|
114
|
-
Defined in: [dispatcher.ts:4](https://github.com/vanviegen/aberdeen/blob/
|
|
117
|
+
Defined in: [dispatcher.ts:4](https://github.com/vanviegen/aberdeen/blob/bfa4e24ebd7624d1d66bdae5c920bbdd10f3fa80/src/dispatcher.ts#L4)
|
|
115
118
|
|
|
116
119
|
Symbol to return when a custom [Dispatcher.addRoute](#addroute) matcher cannot match a segment.
|
|
117
120
|
|
|
118
121
|
***
|
|
119
122
|
|
|
120
|
-
###
|
|
123
|
+
### MATCH\_REST
|
|
121
124
|
|
|
122
|
-
> `const` **
|
|
125
|
+
> `const` **MATCH\_REST**: unique `symbol`
|
|
123
126
|
|
|
124
|
-
Defined in: [dispatcher.ts:9](https://github.com/vanviegen/aberdeen/blob/
|
|
127
|
+
Defined in: [dispatcher.ts:9](https://github.com/vanviegen/aberdeen/blob/bfa4e24ebd7624d1d66bdae5c920bbdd10f3fa80/src/dispatcher.ts#L9)
|
|
125
128
|
|
|
126
129
|
Special [Dispatcher.addRoute](#addroute) matcher that matches the rest of the segments as an array of strings.
|
package/skill/prediction.md
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
[**Aberdeen v1.
|
|
1
|
+
[**Aberdeen v1.7.1**](README.md)
|
|
2
2
|
|
|
3
3
|
***
|
|
4
4
|
|
|
@@ -12,7 +12,7 @@
|
|
|
12
12
|
|
|
13
13
|
> **applyCanon**(`canonFunc?`, `dropPredictions?`): `void`
|
|
14
14
|
|
|
15
|
-
Defined in: [prediction.ts:115](https://github.com/vanviegen/aberdeen/blob/
|
|
15
|
+
Defined in: [prediction.ts:115](https://github.com/vanviegen/aberdeen/blob/bfa4e24ebd7624d1d66bdae5c920bbdd10f3fa80/src/prediction.ts#L115)
|
|
16
16
|
|
|
17
17
|
Temporarily revert all outstanding predictions, optionally run the provided function
|
|
18
18
|
(which will generally make authoritative changes to the data based on a server response),
|
|
@@ -50,7 +50,7 @@ An optional list of predictions (as returned by `applyPrediction`)
|
|
|
50
50
|
|
|
51
51
|
> **applyPrediction**(`predictFunc`): `Patch`
|
|
52
52
|
|
|
53
|
-
Defined in: [prediction.ts:93](https://github.com/vanviegen/aberdeen/blob/
|
|
53
|
+
Defined in: [prediction.ts:93](https://github.com/vanviegen/aberdeen/blob/bfa4e24ebd7624d1d66bdae5c920bbdd10f3fa80/src/prediction.ts#L93)
|
|
54
54
|
|
|
55
55
|
Run the provided function, while treating all changes to Observables as predictions,
|
|
56
56
|
meaning they will be reverted when changes come back from the server (or some other
|
package/skill/route.md
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
[**Aberdeen v1.
|
|
1
|
+
[**Aberdeen v1.7.1**](README.md)
|
|
2
2
|
|
|
3
3
|
***
|
|
4
4
|
|
|
@@ -10,7 +10,7 @@
|
|
|
10
10
|
|
|
11
11
|
### Route
|
|
12
12
|
|
|
13
|
-
Defined in: [route.ts:8](https://github.com/vanviegen/aberdeen/blob/
|
|
13
|
+
Defined in: [route.ts:8](https://github.com/vanviegen/aberdeen/blob/bfa4e24ebd7624d1d66bdae5c920bbdd10f3fa80/src/route.ts#L8)
|
|
14
14
|
|
|
15
15
|
The class for the global `route` object.
|
|
16
16
|
|
|
@@ -20,7 +20,7 @@ The class for the global `route` object.
|
|
|
20
20
|
|
|
21
21
|
> **depth**: `number`
|
|
22
22
|
|
|
23
|
-
Defined in: [route.ts:20](https://github.com/vanviegen/aberdeen/blob/
|
|
23
|
+
Defined in: [route.ts:20](https://github.com/vanviegen/aberdeen/blob/bfa4e24ebd7624d1d66bdae5c920bbdd10f3fa80/src/route.ts#L20)
|
|
24
24
|
|
|
25
25
|
The navigation depth of the current session. Starts at 1. Writing to this property has no effect.
|
|
26
26
|
|
|
@@ -28,7 +28,7 @@ The navigation depth of the current session. Starts at 1. Writing to this proper
|
|
|
28
28
|
|
|
29
29
|
> **hash**: `string`
|
|
30
30
|
|
|
31
|
-
Defined in: [route.ts:14](https://github.com/vanviegen/aberdeen/blob/
|
|
31
|
+
Defined in: [route.ts:14](https://github.com/vanviegen/aberdeen/blob/bfa4e24ebd7624d1d66bdae5c920bbdd10f3fa80/src/route.ts#L14)
|
|
32
32
|
|
|
33
33
|
The hash fragment including the leading `#`, or an empty string. For instance `"#my_section"` or `""`.
|
|
34
34
|
|
|
@@ -36,7 +36,7 @@ The hash fragment including the leading `#`, or an empty string. For instance `"
|
|
|
36
36
|
|
|
37
37
|
> **nav**: `NavType`
|
|
38
38
|
|
|
39
|
-
Defined in: [route.ts:28](https://github.com/vanviegen/aberdeen/blob/
|
|
39
|
+
Defined in: [route.ts:28](https://github.com/vanviegen/aberdeen/blob/bfa4e24ebd7624d1d66bdae5c920bbdd10f3fa80/src/route.ts#L28)
|
|
40
40
|
|
|
41
41
|
The navigation action that got us to this page. Writing to this property has no effect.
|
|
42
42
|
- `"load"`: An initial page load.
|
|
@@ -49,7 +49,7 @@ Mostly useful for page transition animations. Writing to this property has no ef
|
|
|
49
49
|
|
|
50
50
|
> **p**: `string`[]
|
|
51
51
|
|
|
52
|
-
Defined in: [route.ts:12](https://github.com/vanviegen/aberdeen/blob/
|
|
52
|
+
Defined in: [route.ts:12](https://github.com/vanviegen/aberdeen/blob/bfa4e24ebd7624d1d66bdae5c920bbdd10f3fa80/src/route.ts#L12)
|
|
53
53
|
|
|
54
54
|
An convenience array containing path segments, mapping to `path`. For instance `[]` (for `"/"`) or `['users', '123', 'feed']` (for `"/users/123/feed"`).
|
|
55
55
|
|
|
@@ -57,7 +57,7 @@ An convenience array containing path segments, mapping to `path`. For instance `
|
|
|
57
57
|
|
|
58
58
|
> **path**: `string`
|
|
59
59
|
|
|
60
|
-
Defined in: [route.ts:10](https://github.com/vanviegen/aberdeen/blob/
|
|
60
|
+
Defined in: [route.ts:10](https://github.com/vanviegen/aberdeen/blob/bfa4e24ebd7624d1d66bdae5c920bbdd10f3fa80/src/route.ts#L10)
|
|
61
61
|
|
|
62
62
|
The current path of the URL as a string. For instance `"/"` or `"/users/123/feed"`. Paths are normalized to always start with a `/` and never end with a `/` (unless it's the root path).
|
|
63
63
|
|
|
@@ -65,7 +65,7 @@ The current path of the URL as a string. For instance `"/"` or `"/users/123/feed
|
|
|
65
65
|
|
|
66
66
|
> **search**: `Record`\<`string`, `string`\>
|
|
67
67
|
|
|
68
|
-
Defined in: [route.ts:16](https://github.com/vanviegen/aberdeen/blob/
|
|
68
|
+
Defined in: [route.ts:16](https://github.com/vanviegen/aberdeen/blob/bfa4e24ebd7624d1d66bdae5c920bbdd10f3fa80/src/route.ts#L16)
|
|
69
69
|
|
|
70
70
|
The query string interpreted as search parameters. So `"a=x&b=y"` becomes `{a: "x", b: "y"}`.
|
|
71
71
|
|
|
@@ -73,7 +73,7 @@ The query string interpreted as search parameters. So `"a=x&b=y"` becomes `{a: "
|
|
|
73
73
|
|
|
74
74
|
> **state**: `Record`\<`string`, `any`\>
|
|
75
75
|
|
|
76
|
-
Defined in: [route.ts:18](https://github.com/vanviegen/aberdeen/blob/
|
|
76
|
+
Defined in: [route.ts:18](https://github.com/vanviegen/aberdeen/blob/bfa4e24ebd7624d1d66bdae5c920bbdd10f3fa80/src/route.ts#L18)
|
|
77
77
|
|
|
78
78
|
An object to be used for any additional data you want to associate with the current page. Data should be JSON-compatible.
|
|
79
79
|
|
|
@@ -83,7 +83,7 @@ An object to be used for any additional data you want to associate with the curr
|
|
|
83
83
|
|
|
84
84
|
> `const` **current**: [`Route`](#route)
|
|
85
85
|
|
|
86
|
-
Defined in: [route.ts:
|
|
86
|
+
Defined in: [route.ts:332](https://github.com/vanviegen/aberdeen/blob/bfa4e24ebd7624d1d66bdae5c920bbdd10f3fa80/src/route.ts#L332)
|
|
87
87
|
|
|
88
88
|
The global [Route](#route) object reflecting the current URL and browser history state. Changes you make to this affect the current browser history item (modifying the URL if needed).
|
|
89
89
|
|
|
@@ -93,7 +93,7 @@ The global [Route](#route) object reflecting the current URL and browser history
|
|
|
93
93
|
|
|
94
94
|
> **back**(`target`): `void`
|
|
95
95
|
|
|
96
|
-
Defined in: [route.ts:
|
|
96
|
+
Defined in: [route.ts:190](https://github.com/vanviegen/aberdeen/blob/bfa4e24ebd7624d1d66bdae5c920bbdd10f3fa80/src/route.ts#L190)
|
|
97
97
|
|
|
98
98
|
Try to go back in history to the first entry that matches the given target. If none is found, the given state will replace the current page. This is useful for "cancel" or "close" actions that should return to the previous page if possible, but create a new page if not (for instance when arriving at the current page through a direct link).
|
|
99
99
|
|
|
@@ -117,7 +117,7 @@ The target route to go back to. May be a subset of [Route](#route), or a string
|
|
|
117
117
|
|
|
118
118
|
> **go**(`target`, `nav`): `void`
|
|
119
119
|
|
|
120
|
-
Defined in: [route.ts:
|
|
120
|
+
Defined in: [route.ts:156](https://github.com/vanviegen/aberdeen/blob/bfa4e24ebd7624d1d66bdae5c920bbdd10f3fa80/src/route.ts#L156)
|
|
121
121
|
|
|
122
122
|
Navigate to a new URL by pushing a new history entry.
|
|
123
123
|
|
|
@@ -154,11 +154,39 @@ route.go({p: ["users", 123], search: {tab: "feed"}, hash: "top"});
|
|
|
154
154
|
|
|
155
155
|
***
|
|
156
156
|
|
|
157
|
+
### interceptLinks()
|
|
158
|
+
|
|
159
|
+
> **interceptLinks**(): `void`
|
|
160
|
+
|
|
161
|
+
Defined in: [route.ts:277](https://github.com/vanviegen/aberdeen/blob/bfa4e24ebd7624d1d66bdae5c920bbdd10f3fa80/src/route.ts#L277)
|
|
162
|
+
|
|
163
|
+
Intercept clicks and Enter key presses on links (`<a>` tags) and use Aberdeen routing
|
|
164
|
+
instead of browser navigation for local paths (paths without a protocol or host).
|
|
165
|
+
|
|
166
|
+
This allows you to use regular HTML anchor tags for navigation without needing to
|
|
167
|
+
manually attach click handlers to each link.
|
|
168
|
+
|
|
169
|
+
#### Returns
|
|
170
|
+
|
|
171
|
+
`void`
|
|
172
|
+
|
|
173
|
+
#### Example
|
|
174
|
+
|
|
175
|
+
```js
|
|
176
|
+
// In your root component:
|
|
177
|
+
route.interceptLinks();
|
|
178
|
+
|
|
179
|
+
// Now you can use regular anchor tags:
|
|
180
|
+
$('a text=About href=/corporate/about');
|
|
181
|
+
```
|
|
182
|
+
|
|
183
|
+
***
|
|
184
|
+
|
|
157
185
|
### persistScroll()
|
|
158
186
|
|
|
159
187
|
> **persistScroll**(`name`): `void`
|
|
160
188
|
|
|
161
|
-
Defined in: [route.ts:
|
|
189
|
+
Defined in: [route.ts:242](https://github.com/vanviegen/aberdeen/blob/bfa4e24ebd7624d1d66bdae5c920bbdd10f3fa80/src/route.ts#L242)
|
|
162
190
|
|
|
163
191
|
Restore and store the vertical and horizontal scroll position for
|
|
164
192
|
the parent element to the page state.
|
|
@@ -184,7 +212,7 @@ The scroll position will be persisted in `route.aux.scroll.<name>`.
|
|
|
184
212
|
|
|
185
213
|
> **push**(`target`): `void`
|
|
186
214
|
|
|
187
|
-
Defined in: [route.ts:
|
|
215
|
+
Defined in: [route.ts:177](https://github.com/vanviegen/aberdeen/blob/bfa4e24ebd7624d1d66bdae5c920bbdd10f3fa80/src/route.ts#L177)
|
|
188
216
|
|
|
189
217
|
Modify the current route by merging `target` into it (using [merge](aberdeen.md#merge)), pushing a new history entry.
|
|
190
218
|
|
|
@@ -208,7 +236,7 @@ Same as for [go](#go), but merged into the current route instead deleting all st
|
|
|
208
236
|
|
|
209
237
|
> **setLog**(`value`): `void`
|
|
210
238
|
|
|
211
|
-
Defined in: [route.ts:37](https://github.com/vanviegen/aberdeen/blob/
|
|
239
|
+
Defined in: [route.ts:37](https://github.com/vanviegen/aberdeen/blob/bfa4e24ebd7624d1d66bdae5c920bbdd10f3fa80/src/route.ts#L37)
|
|
212
240
|
|
|
213
241
|
Configure logging on route changes.
|
|
214
242
|
|
|
@@ -230,7 +258,7 @@ Configure logging on route changes.
|
|
|
230
258
|
|
|
231
259
|
> **up**(`stripCount`): `void`
|
|
232
260
|
|
|
233
|
-
Defined in: [route.ts:
|
|
261
|
+
Defined in: [route.ts:215](https://github.com/vanviegen/aberdeen/blob/bfa4e24ebd7624d1d66bdae5c920bbdd10f3fa80/src/route.ts#L215)
|
|
234
262
|
|
|
235
263
|
Navigate up in the path hierarchy, by going back to the first history entry
|
|
236
264
|
that has a shorter path than the current one. If there's none, we just shorten
|
package/skill/transitions.md
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
[**Aberdeen v1.
|
|
1
|
+
[**Aberdeen v1.7.1**](README.md)
|
|
2
2
|
|
|
3
3
|
***
|
|
4
4
|
|
|
@@ -12,7 +12,7 @@
|
|
|
12
12
|
|
|
13
13
|
> **grow**(`el`): `Promise`\<`void`\>
|
|
14
14
|
|
|
15
|
-
Defined in: [transitions.ts:33](https://github.com/vanviegen/aberdeen/blob/
|
|
15
|
+
Defined in: [transitions.ts:33](https://github.com/vanviegen/aberdeen/blob/bfa4e24ebd7624d1d66bdae5c920bbdd10f3fa80/src/transitions.ts#L33)
|
|
16
16
|
|
|
17
17
|
Do a grow transition for the given element. This is meant to be used as a
|
|
18
18
|
handler for the `create` property.
|
|
@@ -38,7 +38,7 @@ for other specific cases as well.
|
|
|
38
38
|
|
|
39
39
|
> **shrink**(`el`): `Promise`\<`void`\>
|
|
40
40
|
|
|
41
|
-
Defined in: [transitions.ts:56](https://github.com/vanviegen/aberdeen/blob/
|
|
41
|
+
Defined in: [transitions.ts:56](https://github.com/vanviegen/aberdeen/blob/bfa4e24ebd7624d1d66bdae5c920bbdd10f3fa80/src/transitions.ts#L56)
|
|
42
42
|
|
|
43
43
|
Do a shrink transition for the given element, and remove it from the DOM
|
|
44
44
|
afterwards. This is meant to be used as a handler for the `destroy` property.
|