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
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Default browser entry point for Aberdeen.
|
|
3
|
+
*
|
|
4
|
+
* It exports a ready-to-use Aberdeen instance (`A`) bound to the global `window`, so you can
|
|
5
|
+
* `import A from 'aberdeen'` and start building UI with zero setup. Advanced users (and the
|
|
6
|
+
* `aberdeen/server` SSR entry) can instead import {@link createA} to create instances bound to a
|
|
7
|
+
* specific window, including multiple isolated instances.
|
|
8
|
+
*/
|
|
9
|
+
export { createA } from "./aberdeen.js";
|
|
10
|
+
export type { Aberdeen, WindowLike, InitOptions, ValueRef, PromiseProxy } from "./aberdeen.js";
|
|
11
|
+
declare const _default: import("./aberdeen.js").Aberdeen;
|
|
12
|
+
export default _default;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
// src/index.ts
|
|
2
|
+
import { createA } from "./aberdeen.js";
|
|
3
|
+
import { createA as createA2 } from "./aberdeen.js";
|
|
4
|
+
var src_default = createA2(typeof window !== "undefined" ? window : undefined);
|
|
5
|
+
export {
|
|
6
|
+
src_default as default,
|
|
7
|
+
createA
|
|
8
|
+
};
|
|
9
|
+
|
|
10
|
+
//# debugId=5E2A1B4525639B1164756E2164756E21
|
|
11
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../src/index.ts"],
|
|
4
|
+
"sourcesContent": [
|
|
5
|
+
"/**\n * Default browser entry point for Aberdeen.\n *\n * It exports a ready-to-use Aberdeen instance (`A`) bound to the global `window`, so you can\n * `import A from 'aberdeen'` and start building UI with zero setup. Advanced users (and the\n * `aberdeen/server` SSR entry) can instead import {@link createA} to create instances bound to a\n * specific window, including multiple isolated instances.\n */\nexport { createA } from \"./aberdeen.js\";\nexport type { Aberdeen, WindowLike, InitOptions, ValueRef, PromiseProxy } from \"./aberdeen.js\";\nimport { createA } from \"./aberdeen.js\";\n\nexport default createA(typeof window !== \"undefined\" ? (window as any) : undefined);\n"
|
|
6
|
+
],
|
|
7
|
+
"mappings": ";AAQA;AAEA,oBAAS;AAET,IAAe,uBAAQ,OAAO,WAAW,cAAe,SAAiB,SAAS;",
|
|
8
|
+
"debugId": "5E2A1B4525639B1164756E2164756E21",
|
|
9
|
+
"names": []
|
|
10
|
+
}
|
package/dist/src/prediction.d.ts
CHANGED
|
@@ -1,20 +1,21 @@
|
|
|
1
|
-
|
|
1
|
+
type Aberdeen = any;
|
|
2
2
|
/**
|
|
3
3
|
* Represents a set of changes that can be applied to proxied objects.
|
|
4
4
|
* This is an opaque type - its internal structure is not part of the public API.
|
|
5
5
|
* @private
|
|
6
6
|
*/
|
|
7
|
-
export type Patch = Map<
|
|
7
|
+
export type Patch = Map<any, Map<any, [any, any]>>;
|
|
8
8
|
/**
|
|
9
9
|
* Run the provided function, while treating all changes to Observables as predictions,
|
|
10
10
|
* meaning they will be reverted when changes come back from the server (or some other
|
|
11
11
|
* async source).
|
|
12
|
+
* @param A The Aberdeen instance (the default export of `aberdeen`, or one from `init`).
|
|
12
13
|
* @param predictFunc The function to run. It will generally modify some Observables
|
|
13
14
|
* to immediately reflect state (as closely as possible) that we expect the server
|
|
14
15
|
* to communicate back to us later on.
|
|
15
16
|
* @returns A `Patch` object. Don't modify it. This is only meant to be passed to `applyCanon`.
|
|
16
17
|
*/
|
|
17
|
-
export declare function applyPrediction(predictFunc: () => void): Patch;
|
|
18
|
+
export declare function applyPrediction(A: Aberdeen, predictFunc: () => void): Patch;
|
|
18
19
|
/**
|
|
19
20
|
* Temporarily revert all outstanding predictions, optionally run the provided function
|
|
20
21
|
* (which will generally make authoritative changes to the data based on a server response),
|
|
@@ -24,10 +25,12 @@ export declare function applyPrediction(predictFunc: () => void): Patch;
|
|
|
24
25
|
*
|
|
25
26
|
* All of this is done such that redraws are only triggered if the overall effect is an
|
|
26
27
|
* actual change to an `Observable`.
|
|
28
|
+
* @param A The Aberdeen instance (the default export of `aberdeen`, or one from `init`).
|
|
27
29
|
* @param canonFunc The function to run without any predictions applied. This will typically
|
|
28
30
|
* make authoritative changes to the data, based on a server response.
|
|
29
31
|
* @param dropPredictions An optional list of predictions (as returned by `applyPrediction`)
|
|
30
32
|
* to undo. Typically, when a server response for a certain request is being handled,
|
|
31
33
|
* you'd want to drop the prediction that was done for that request.
|
|
32
34
|
*/
|
|
33
|
-
export declare function applyCanon(canonFunc?: () => void, dropPredictions?: Array<Patch>): void;
|
|
35
|
+
export declare function applyCanon(A: Aberdeen, canonFunc?: () => void, dropPredictions?: Array<Patch>): void;
|
|
36
|
+
export {};
|
package/dist/src/prediction.js
CHANGED
|
@@ -1,13 +1,7 @@
|
|
|
1
1
|
// src/prediction.ts
|
|
2
|
-
|
|
3
|
-
defaultEmitHandler,
|
|
4
|
-
withEmitHandler,
|
|
5
|
-
EMPTY,
|
|
6
|
-
MAP_SIZE_SYMBOL
|
|
7
|
-
} from "./aberdeen.js";
|
|
8
|
-
function recordPatch(func) {
|
|
2
|
+
function recordPatch(A, func) {
|
|
9
3
|
const recordingPatch = new Map;
|
|
10
|
-
withEmitHandler((target, index, newData, oldData) => {
|
|
4
|
+
A.withEmitHandler((target, index, newData, oldData) => {
|
|
11
5
|
addToPatch(recordingPatch, target, index, newData, oldData);
|
|
12
6
|
}, func);
|
|
13
7
|
return recordingPatch;
|
|
@@ -25,10 +19,10 @@ function addToPatch(patch, collection, index, newData, oldData) {
|
|
|
25
19
|
else
|
|
26
20
|
collectionMap.set(index, [newData, oldData0]);
|
|
27
21
|
}
|
|
28
|
-
function emitPatch(patch) {
|
|
22
|
+
function emitPatch(A, patch) {
|
|
29
23
|
for (const [collection, collectionMap] of patch) {
|
|
30
24
|
for (const [index, [newData, oldData]] of collectionMap) {
|
|
31
|
-
defaultEmitHandler(collection, index, newData, oldData);
|
|
25
|
+
A.defaultEmitHandler(collection, index, newData, oldData);
|
|
32
26
|
}
|
|
33
27
|
}
|
|
34
28
|
}
|
|
@@ -39,15 +33,16 @@ function mergePatch(target, source, reverse = false) {
|
|
|
39
33
|
}
|
|
40
34
|
}
|
|
41
35
|
}
|
|
42
|
-
function silentlyApplyPatch(patch, force = false) {
|
|
36
|
+
function silentlyApplyPatch(A, patch, force = false) {
|
|
37
|
+
const EMPTY = A.EMPTY;
|
|
43
38
|
for (const [collection, collectionMap] of patch) {
|
|
44
39
|
for (const [index, [newData, oldData]] of collectionMap) {
|
|
45
|
-
if (index === MAP_SIZE_SYMBOL)
|
|
40
|
+
if (index === A.MAP_SIZE_SYMBOL)
|
|
46
41
|
continue;
|
|
47
42
|
const actualData = collection instanceof Map ? collection.has(index) ? collection.get(index) : EMPTY : (index in collection) ? collection[index] : EMPTY;
|
|
48
43
|
if (actualData !== oldData) {
|
|
49
44
|
if (force)
|
|
50
|
-
setTimeout(() => {
|
|
45
|
+
(A.window?.setTimeout ?? setTimeout)(() => {
|
|
51
46
|
throw new Error(`Applying invalid patch: data ${String(actualData)} is unequal to expected old data ${String(oldData)} for index ${String(index)}`);
|
|
52
47
|
}, 0);
|
|
53
48
|
else
|
|
@@ -57,7 +52,7 @@ function silentlyApplyPatch(patch, force = false) {
|
|
|
57
52
|
}
|
|
58
53
|
for (const [collection, collectionMap] of patch) {
|
|
59
54
|
for (const [index, [newData, oldData]] of collectionMap) {
|
|
60
|
-
if (index === MAP_SIZE_SYMBOL)
|
|
55
|
+
if (index === A.MAP_SIZE_SYMBOL)
|
|
61
56
|
continue;
|
|
62
57
|
if (collection instanceof Map) {
|
|
63
58
|
if (newData === EMPTY)
|
|
@@ -75,38 +70,38 @@ function silentlyApplyPatch(patch, force = false) {
|
|
|
75
70
|
return true;
|
|
76
71
|
}
|
|
77
72
|
var appliedPredictions = [];
|
|
78
|
-
function applyPrediction(predictFunc) {
|
|
79
|
-
const patch = recordPatch(predictFunc);
|
|
73
|
+
function applyPrediction(A, predictFunc) {
|
|
74
|
+
const patch = recordPatch(A, predictFunc);
|
|
80
75
|
appliedPredictions.push(patch);
|
|
81
|
-
emitPatch(patch);
|
|
76
|
+
emitPatch(A, patch);
|
|
82
77
|
return patch;
|
|
83
78
|
}
|
|
84
|
-
function applyCanon(canonFunc, dropPredictions = []) {
|
|
79
|
+
function applyCanon(A, canonFunc, dropPredictions = []) {
|
|
85
80
|
const resultPatch = new Map;
|
|
86
81
|
for (const prediction of appliedPredictions)
|
|
87
82
|
mergePatch(resultPatch, prediction, true);
|
|
88
|
-
silentlyApplyPatch(resultPatch, true);
|
|
83
|
+
silentlyApplyPatch(A, resultPatch, true);
|
|
89
84
|
for (const prediction of dropPredictions) {
|
|
90
85
|
const pos = appliedPredictions.indexOf(prediction);
|
|
91
86
|
if (pos >= 0)
|
|
92
87
|
appliedPredictions.splice(pos, 1);
|
|
93
88
|
}
|
|
94
89
|
if (canonFunc)
|
|
95
|
-
mergePatch(resultPatch, recordPatch(canonFunc));
|
|
90
|
+
mergePatch(resultPatch, recordPatch(A, canonFunc));
|
|
96
91
|
for (let idx = 0;idx < appliedPredictions.length; idx++) {
|
|
97
|
-
if (silentlyApplyPatch(appliedPredictions[idx])) {
|
|
92
|
+
if (silentlyApplyPatch(A, appliedPredictions[idx])) {
|
|
98
93
|
mergePatch(resultPatch, appliedPredictions[idx]);
|
|
99
94
|
} else {
|
|
100
95
|
appliedPredictions.splice(idx, 1);
|
|
101
96
|
idx--;
|
|
102
97
|
}
|
|
103
98
|
}
|
|
104
|
-
emitPatch(resultPatch);
|
|
99
|
+
emitPatch(A, resultPatch);
|
|
105
100
|
}
|
|
106
101
|
export {
|
|
107
102
|
applyPrediction,
|
|
108
103
|
applyCanon
|
|
109
104
|
};
|
|
110
105
|
|
|
111
|
-
//# debugId=
|
|
106
|
+
//# debugId=908A3B91728A6C4A64756E2164756E21
|
|
112
107
|
//# sourceMappingURL=prediction.js.map
|
|
@@ -2,9 +2,9 @@
|
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/prediction.ts"],
|
|
4
4
|
"sourcesContent": [
|
|
5
|
-
"
|
|
5
|
+
"// This module operates on a specific Aberdeen instance, which is passed as the first argument\n// (`A`) to its public functions. `A` provides the emit handlers and the EMPTY/MAP_SIZE_SYMBOL\n// markers it needs.\ntype Aberdeen = any;\n\n/**\n * Represents a set of changes that can be applied to proxied objects.\n * This is an opaque type - its internal structure is not part of the public API.\n * @private\n */\nexport type Patch = Map<any, Map<any, [any, any]>>;\n\nfunction recordPatch(A: Aberdeen, func: () => void): Patch {\n\tconst recordingPatch = new Map();\n\tA.withEmitHandler((target: any, index: any, newData: any, oldData: any) => {\n\t\taddToPatch(recordingPatch, target, index, newData, oldData);\n\t}, func);\n\treturn recordingPatch;\n}\n\nfunction addToPatch(\n\tpatch: Patch,\n\tcollection: any,\n\tindex: any,\n\tnewData: any,\n\toldData: any,\n) {\n\tlet collectionMap = patch.get(collection);\n\tif (!collectionMap) {\n\t\tcollectionMap = new Map();\n\t\tpatch.set(collection, collectionMap);\n\t}\n\tconst prev = collectionMap.get(index);\n\tconst oldData0 = prev ? prev[1] : oldData;\n\tif (newData === oldData0) collectionMap.delete(index);\n\telse collectionMap.set(index, [newData, oldData0]);\n}\n\nfunction emitPatch(A: Aberdeen, patch: Patch) {\n\tfor (const [collection, collectionMap] of patch) {\n\t\tfor (const [index, [newData, oldData]] of collectionMap) {\n\t\t\tA.defaultEmitHandler(collection, index, newData, oldData);\n\t\t}\n\t}\n}\n\nfunction mergePatch(target: Patch, source: Patch, reverse = false) {\n\tfor (const [collection, collectionMap] of source) {\n\t\tfor (const [index, [newData, oldData]] of collectionMap) {\n\t\t\taddToPatch(\n\t\t\t\ttarget,\n\t\t\t\tcollection,\n\t\t\t\tindex,\n\t\t\t\treverse ? oldData : newData,\n\t\t\t\treverse ? newData : oldData,\n\t\t\t);\n\t\t}\n\t}\n}\n\nfunction silentlyApplyPatch(A: Aberdeen, patch: Patch, force = false): boolean {\n\tconst EMPTY = A.EMPTY;\n\tfor (const [collection, collectionMap] of patch) {\n\t\tfor (const [index, [newData, oldData]] of collectionMap) {\n\t\t\t// MAP_SIZE_SYMBOL is synthetic - size is derived from add/delete operations\n\t\t\tif (index === A.MAP_SIZE_SYMBOL) continue;\n\t\t\tconst actualData =\n\t\t\t\tcollection instanceof Map\n\t\t\t\t\t? collection.has(index)\n\t\t\t\t\t\t? collection.get(index)\n\t\t\t\t\t\t: EMPTY\n\t\t\t\t\t: index in (collection as any)\n\t\t\t\t\t\t? (collection as any)[index]\n\t\t\t\t\t\t: EMPTY;\n\t\t\tif (actualData !== oldData) {\n\t\t\t\tif (force)\n\t\t\t\t\t(A.window?.setTimeout ?? setTimeout)(() => {\n\t\t\t\t\t\tthrow new Error(\n\t\t\t\t\t\t\t`Applying invalid patch: data ${String(actualData)} is unequal to expected old data ${String(oldData)} for index ${String(index)}`,\n\t\t\t\t\t\t);\n\t\t\t\t\t}, 0);\n\t\t\t\telse return false;\n\t\t\t}\n\t\t}\n\t}\n\tfor (const [collection, collectionMap] of patch) {\n\t\tfor (const [index, [newData, oldData]] of collectionMap) {\n\t\t\tif (index === A.MAP_SIZE_SYMBOL) continue;\n\t\t\tif (collection instanceof Map) {\n\t\t\t\tif (newData === EMPTY) collection.delete(index);\n\t\t\t\telse collection.set(index, newData);\n\t\t\t} else {\n\t\t\t\tif (newData === EMPTY) delete (collection as any)[index];\n\t\t\t\telse (collection as any)[index] = newData;\n\t\t\t}\n\t\t}\n\t}\n\treturn true;\n}\n\nconst appliedPredictions: Array<Patch> = [];\n\n/**\n * Run the provided function, while treating all changes to Observables as predictions,\n * meaning they will be reverted when changes come back from the server (or some other\n * async source).\n * @param A The Aberdeen instance (the default export of `aberdeen`, or one from `init`).\n * @param predictFunc The function to run. It will generally modify some Observables\n * \tto immediately reflect state (as closely as possible) that we expect the server\n * to communicate back to us later on.\n * @returns A `Patch` object. Don't modify it. This is only meant to be passed to `applyCanon`.\n */\nexport function applyPrediction(A: Aberdeen, predictFunc: () => void): Patch {\n\tconst patch = recordPatch(A, predictFunc);\n\tappliedPredictions.push(patch);\n\temitPatch(A, patch);\n\treturn patch;\n}\n\n/**\n * Temporarily revert all outstanding predictions, optionally run the provided function\n * (which will generally make authoritative changes to the data based on a server response),\n * and then attempt to reapply the predictions on top of the new canonical state, dropping\n * any predictions that can no longer be applied cleanly (the data has been modified) or\n * that were specified in `dropPredictions`.\n *\n * All of this is done such that redraws are only triggered if the overall effect is an\n * actual change to an `Observable`.\n * @param A The Aberdeen instance (the default export of `aberdeen`, or one from `init`).\n * @param canonFunc The function to run without any predictions applied. This will typically\n * make authoritative changes to the data, based on a server response.\n * @param dropPredictions An optional list of predictions (as returned by `applyPrediction`)\n * to undo. Typically, when a server response for a certain request is being handled,\n * you'd want to drop the prediction that was done for that request.\n */\nexport function applyCanon(\n\tA: Aberdeen,\n\tcanonFunc?: () => void,\n\tdropPredictions: Array<Patch> = [],\n) {\n\tconst resultPatch = new Map();\n\tfor (const prediction of appliedPredictions)\n\t\tmergePatch(resultPatch, prediction, true);\n\tsilentlyApplyPatch(A, resultPatch, true);\n\n\tfor (const prediction of dropPredictions) {\n\t\tconst pos = appliedPredictions.indexOf(prediction);\n\t\tif (pos >= 0) appliedPredictions.splice(pos, 1);\n\t}\n\tif (canonFunc) mergePatch(resultPatch, recordPatch(A, canonFunc));\n\n\tfor (let idx = 0; idx < appliedPredictions.length; idx++) {\n\t\tif (silentlyApplyPatch(A, appliedPredictions[idx])) {\n\t\t\tmergePatch(resultPatch, appliedPredictions[idx]);\n\t\t} else {\n\t\t\tappliedPredictions.splice(idx, 1);\n\t\t\tidx--;\n\t\t}\n\t}\n\n\temitPatch(A, resultPatch);\n}\n"
|
|
6
6
|
],
|
|
7
|
-
"mappings": ";
|
|
8
|
-
"debugId": "
|
|
7
|
+
"mappings": "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",
|
|
8
|
+
"debugId": "908A3B91728A6C4A64756E2164756E21",
|
|
9
9
|
"names": []
|
|
10
10
|
}
|
package/dist/src/route.d.ts
CHANGED
|
@@ -24,11 +24,6 @@ export interface Route {
|
|
|
24
24
|
*/
|
|
25
25
|
nav: NavType;
|
|
26
26
|
}
|
|
27
|
-
/**
|
|
28
|
-
* Configure logging on route changes.
|
|
29
|
-
* @param value `true` to enable logging to console, `false` to disable logging, or a custom logging function. Defaults to `false`.
|
|
30
|
-
*/
|
|
31
|
-
export declare function setLog(value: boolean | ((...args: any[]) => void)): void;
|
|
32
27
|
type RouteTarget = string | (string | number)[] | Partial<Omit<Omit<Route, "p">, "search"> & {
|
|
33
28
|
/** An convenience array containing path segments, mapping to `path`. For instance `[]` (for `"/"`) or `['users', 123, 'feed']` (for `"/users/123/feed"`). Values may be integers but will be converted to strings.*/
|
|
34
29
|
p: (string | number)[];
|
|
@@ -36,102 +31,120 @@ type RouteTarget = string | (string | number)[] | Partial<Omit<Omit<Route, "p">,
|
|
|
36
31
|
search: Record<string, string | number>;
|
|
37
32
|
}>;
|
|
38
33
|
/**
|
|
39
|
-
*
|
|
40
|
-
*
|
|
41
|
-
* Note that this happens synchronously, immediately updating `route` and processing any reactive updates based on that.
|
|
42
|
-
*
|
|
43
|
-
* @param target A subset of the {@link Route} properties to navigate to. If neither `p` nor `path` is given, the current path is used. For other properties, an empty/default value is assumed if not given. For convenience:
|
|
44
|
-
* - You may pass a string instead of an object, which is interpreted as the `path`.
|
|
45
|
-
* - You may pass an array instead of an object, which is interpreted as the `p` array.
|
|
46
|
-
* - If you pass `p`, it may contain numbers, which will be converted to strings.
|
|
47
|
-
* - If you pass `search`, its values may be numbers, which will be converted to strings.
|
|
48
|
-
*
|
|
49
|
-
* Examples:
|
|
50
|
-
* ```js
|
|
51
|
-
* // Navigate to /users/123
|
|
52
|
-
* route.go("/users/123");
|
|
53
|
-
*
|
|
54
|
-
* // Navigate to /users/123?tab=feed#top
|
|
55
|
-
* route.go({p: ["users", 123], search: {tab: "feed"}, hash: "top"});
|
|
56
|
-
* ```
|
|
57
|
-
*/
|
|
58
|
-
export declare function go(target: RouteTarget, nav?: NavType): void;
|
|
59
|
-
/**
|
|
60
|
-
* Returns `true` if the current route matches `target`.
|
|
61
|
-
*
|
|
62
|
-
* Path must match exactly. Any search params specified in `target` must be present
|
|
63
|
-
* in the current URL, but extra params in the current URL are allowed.
|
|
64
|
-
*
|
|
65
|
-
* Reactive: only reevaluates when the path changes to/from the target path, and
|
|
66
|
-
* when target k/v search pairs are (un)set.
|
|
67
|
-
*
|
|
68
|
-
* Primary usage: 'active' status for menu items.
|
|
69
|
-
*
|
|
70
|
-
* @example
|
|
71
|
-
* ```js
|
|
72
|
-
* // This example assumes interceptLinks() has been called
|
|
73
|
-
* A('a.my-button text=Users href=/users .is-active=', route.matchCurrent('/users'));
|
|
74
|
-
*
|
|
75
|
-
* // Alternatively a route object can be given
|
|
76
|
-
* route.matchCurrent({path: '/users', search: {tab: 'profile'}});
|
|
77
|
-
* ```
|
|
78
|
-
*/
|
|
79
|
-
export declare function matchCurrent(target: RouteTarget): boolean;
|
|
80
|
-
/**
|
|
81
|
-
* Modify the current route by merging `target` into it (using {@link aberdeen.merge | A.merge}), pushing a new history entry.
|
|
82
|
-
*
|
|
83
|
-
* This is useful for things like opening modals or side panels, where you want a browser back action to return to the previous state.
|
|
84
|
-
*
|
|
85
|
-
* @param target Same as for {@link go}, but merged into the current route instead deleting all state.
|
|
86
|
-
* @param nav The navigation type to use. Defaults to `undefined`, meaning the navigation type is unchanged from the current route,
|
|
87
|
-
* preventing unwanted page transition animations.
|
|
88
|
-
*/
|
|
89
|
-
export declare function push(target: RouteTarget, nav?: NavType): void;
|
|
90
|
-
/**
|
|
91
|
-
* 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).
|
|
92
|
-
*
|
|
93
|
-
* Consider using {@link up} to go up in the path hierarchy.
|
|
94
|
-
*
|
|
95
|
-
* @param target The target route to go back to. May be a subset of {@link Route}, or a string (for `path`), or an array of strings (for `p`).
|
|
34
|
+
* The router API returned by {@link init}, bound to a specific Aberdeen instance's window.
|
|
96
35
|
*/
|
|
97
|
-
export
|
|
98
|
-
/**
|
|
99
|
-
*
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
*
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
*
|
|
112
|
-
* the
|
|
113
|
-
*
|
|
114
|
-
*
|
|
115
|
-
*
|
|
116
|
-
*
|
|
117
|
-
*
|
|
118
|
-
|
|
119
|
-
|
|
36
|
+
export interface RouteApi {
|
|
37
|
+
/**
|
|
38
|
+
* The global {@link 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).
|
|
39
|
+
*/
|
|
40
|
+
current: Route;
|
|
41
|
+
/**
|
|
42
|
+
* Configure logging on route changes.
|
|
43
|
+
* @param value `true` to enable logging to console, `false` to disable logging, or a custom logging function. Defaults to `false`.
|
|
44
|
+
*/
|
|
45
|
+
setLog(value: boolean | ((...args: any[]) => void)): void;
|
|
46
|
+
/**
|
|
47
|
+
* Navigate to a new URL by pushing a new history entry.
|
|
48
|
+
*
|
|
49
|
+
* Note that this happens synchronously, immediately updating `route` and processing any reactive updates based on that.
|
|
50
|
+
*
|
|
51
|
+
* @param target A subset of the {@link Route} properties to navigate to. If neither `p` nor `path` is given, the current path is used. For other properties, an empty/default value is assumed if not given. For convenience:
|
|
52
|
+
* - You may pass a string instead of an object, which is interpreted as the `path`.
|
|
53
|
+
* - You may pass an array instead of an object, which is interpreted as the `p` array.
|
|
54
|
+
* - If you pass `p`, it may contain numbers, which will be converted to strings.
|
|
55
|
+
* - If you pass `search`, its values may be numbers, which will be converted to strings.
|
|
56
|
+
*
|
|
57
|
+
* Examples:
|
|
58
|
+
* ```js
|
|
59
|
+
* // Navigate to /users/123
|
|
60
|
+
* route.go("/users/123");
|
|
61
|
+
*
|
|
62
|
+
* // Navigate to /users/123?tab=feed#top
|
|
63
|
+
* route.go({p: ["users", 123], search: {tab: "feed"}, hash: "top"});
|
|
64
|
+
* ```
|
|
65
|
+
*/
|
|
66
|
+
go(target: RouteTarget, nav?: NavType): void;
|
|
67
|
+
/**
|
|
68
|
+
* Returns `true` if the current route matches `target`.
|
|
69
|
+
*
|
|
70
|
+
* Path must match exactly. Any search params specified in `target` must be present
|
|
71
|
+
* in the current URL, but extra params in the current URL are allowed.
|
|
72
|
+
*
|
|
73
|
+
* Reactive: only reevaluates when the path changes to/from the target path, and
|
|
74
|
+
* when target k/v search pairs are (un)set.
|
|
75
|
+
*
|
|
76
|
+
* Primary usage: 'active' status for menu items.
|
|
77
|
+
*
|
|
78
|
+
* @example
|
|
79
|
+
* ```js
|
|
80
|
+
* // This example assumes interceptLinks() has been called
|
|
81
|
+
* A('a.my-button text=Users href=/users .is-active=', route.matchCurrent('/users'));
|
|
82
|
+
*
|
|
83
|
+
* // Alternatively a route object can be given
|
|
84
|
+
* route.matchCurrent({path: '/users', search: {tab: 'profile'}});
|
|
85
|
+
* ```
|
|
86
|
+
*/
|
|
87
|
+
matchCurrent(target: RouteTarget): boolean;
|
|
88
|
+
/**
|
|
89
|
+
* Modify the current route by merging `target` into it (using {@link aberdeen!Aberdeen.merge | A.merge}), pushing a new history entry.
|
|
90
|
+
*
|
|
91
|
+
* This is useful for things like opening modals or side panels, where you want a browser back action to return to the previous state.
|
|
92
|
+
*
|
|
93
|
+
* @param target Same as for {@link go}, but merged into the current route instead deleting all state.
|
|
94
|
+
* @param nav The navigation type to use. Defaults to `undefined`, meaning the navigation type is unchanged from the current route,
|
|
95
|
+
* preventing unwanted page transition animations.
|
|
96
|
+
*/
|
|
97
|
+
push(target: RouteTarget, nav?: NavType): void;
|
|
98
|
+
/**
|
|
99
|
+
* 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).
|
|
100
|
+
*
|
|
101
|
+
* Consider using {@link up} to go up in the path hierarchy.
|
|
102
|
+
*
|
|
103
|
+
* @param target The target route to go back to. May be a subset of {@link Route}, or a string (for `path`), or an array of strings (for `p`).
|
|
104
|
+
*/
|
|
105
|
+
back(target?: RouteTarget): void;
|
|
106
|
+
/**
|
|
107
|
+
* Navigate up in the path hierarchy, by going back to the first history entry
|
|
108
|
+
* that has a shorter path than the current one. If there's none, we just shorten
|
|
109
|
+
* the current path.
|
|
110
|
+
*
|
|
111
|
+
* Note that going back in browser history happens asynchronously, so `route` will not be updated immediately.
|
|
112
|
+
*/
|
|
113
|
+
up(stripCount?: number): void;
|
|
114
|
+
/**
|
|
115
|
+
* Restore and store the vertical and horizontal scroll position for
|
|
116
|
+
* the parent element to the page state.
|
|
117
|
+
*
|
|
118
|
+
* @param {string} name - A unique (within this page) name for this
|
|
119
|
+
* scrollable element. Defaults to 'main'.
|
|
120
|
+
*
|
|
121
|
+
* The scroll position will be persisted in `route.aux.scroll.<name>`.
|
|
122
|
+
*/
|
|
123
|
+
persistScroll(name?: string): void;
|
|
124
|
+
/**
|
|
125
|
+
* Intercept clicks and Enter key presses on links (`<a>` tags) and use Aberdeen routing
|
|
126
|
+
* instead of browser navigation for local paths (paths without a protocol or host).
|
|
127
|
+
*
|
|
128
|
+
* This allows you to use regular HTML anchor tags for navigation without needing to
|
|
129
|
+
* manually attach click handlers to each link.
|
|
130
|
+
*
|
|
131
|
+
* @example
|
|
132
|
+
* ```js
|
|
133
|
+
* // In your root component:
|
|
134
|
+
* route.interceptLinks();
|
|
135
|
+
*
|
|
136
|
+
* // Now you can use regular anchor tags:
|
|
137
|
+
* A('a text=About href=/corporate/about');
|
|
138
|
+
* ```
|
|
139
|
+
*/
|
|
140
|
+
interceptLinks(): void;
|
|
141
|
+
}
|
|
120
142
|
/**
|
|
121
|
-
*
|
|
122
|
-
*
|
|
123
|
-
*
|
|
124
|
-
* This allows you to use regular HTML anchor tags for navigation without needing to
|
|
125
|
-
* manually attach click handlers to each link.
|
|
126
|
-
*
|
|
127
|
-
* @example
|
|
128
|
-
* ```js
|
|
129
|
-
* // In your root component:
|
|
130
|
-
* route.interceptLinks();
|
|
143
|
+
* Initialise routing for an Aberdeen instance and return the router API, bound to that
|
|
144
|
+
* instance's window. In the browser, use the default instance: `init(A)`. For server-side
|
|
145
|
+
* rendering, pass the instance provided by `aberdeen/server`'s render callback.
|
|
131
146
|
*
|
|
132
|
-
*
|
|
133
|
-
* A('a text=About href=/corporate/about');
|
|
134
|
-
* ```
|
|
147
|
+
* @param A An Aberdeen instance (the default export of `aberdeen`, or one from `init`).
|
|
135
148
|
*/
|
|
136
|
-
export declare function
|
|
149
|
+
export declare function init(A: any): RouteApi;
|
|
137
150
|
export {};
|