aberdeen 1.17.1 → 2.0.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/dist/src/aberdeen.d.ts +928 -944
- package/dist/src/aberdeen.js +1693 -1705
- 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 +114 -101
- package/dist/src/route.js +246 -253
- 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 -1705
- 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 +114 -101
- package/dist-docs/assets/aberdeen/route.js +246 -253
- 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 +10 -1
- 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/RouteApi/index.html +60 -0
- package/dist-docs/route/{Route → RouteState}/index.html +9 -9
- package/dist-docs/route/createRoute/index.html +5 -0
- package/dist-docs/route/index.html +6 -15
- 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 +52 -156
- 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 +155 -137
- package/skill/transitions.md +3 -3
- package/src/aberdeen.ts +1224 -741
- package/src/index.ts +13 -0
- package/src/prediction.ts +25 -24
- package/src/route.ts +419 -393
- 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/src/index.ts
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
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
|
+
import { createA } from "./aberdeen.js";
|
|
12
|
+
|
|
13
|
+
export default createA(typeof window !== "undefined" ? (window as any) : undefined);
|
package/src/prediction.ts
CHANGED
|
@@ -1,21 +1,18 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
MAP_SIZE_SYMBOL,
|
|
6
|
-
} from "./aberdeen.js";
|
|
7
|
-
import type { TargetType } from "./aberdeen.js";
|
|
1
|
+
// This module operates on a specific Aberdeen instance, which is passed as the first argument
|
|
2
|
+
// (`A`) to its public functions. `A` provides the emit handlers and the EMPTY/MAP_SIZE_SYMBOL
|
|
3
|
+
// markers it needs.
|
|
4
|
+
type Aberdeen = any;
|
|
8
5
|
|
|
9
6
|
/**
|
|
10
7
|
* Represents a set of changes that can be applied to proxied objects.
|
|
11
8
|
* This is an opaque type - its internal structure is not part of the public API.
|
|
12
9
|
* @private
|
|
13
10
|
*/
|
|
14
|
-
export type Patch = Map<
|
|
11
|
+
export type Patch = Map<any, Map<any, [any, any]>>;
|
|
15
12
|
|
|
16
|
-
function recordPatch(func: () => void): Patch {
|
|
13
|
+
function recordPatch(A: Aberdeen, func: () => void): Patch {
|
|
17
14
|
const recordingPatch = new Map();
|
|
18
|
-
withEmitHandler((target, index, newData, oldData) => {
|
|
15
|
+
A.withEmitHandler((target: any, index: any, newData: any, oldData: any) => {
|
|
19
16
|
addToPatch(recordingPatch, target, index, newData, oldData);
|
|
20
17
|
}, func);
|
|
21
18
|
return recordingPatch;
|
|
@@ -23,7 +20,7 @@ function recordPatch(func: () => void): Patch {
|
|
|
23
20
|
|
|
24
21
|
function addToPatch(
|
|
25
22
|
patch: Patch,
|
|
26
|
-
collection:
|
|
23
|
+
collection: any,
|
|
27
24
|
index: any,
|
|
28
25
|
newData: any,
|
|
29
26
|
oldData: any,
|
|
@@ -39,10 +36,10 @@ function addToPatch(
|
|
|
39
36
|
else collectionMap.set(index, [newData, oldData0]);
|
|
40
37
|
}
|
|
41
38
|
|
|
42
|
-
function emitPatch(patch: Patch) {
|
|
39
|
+
function emitPatch(A: Aberdeen, patch: Patch) {
|
|
43
40
|
for (const [collection, collectionMap] of patch) {
|
|
44
41
|
for (const [index, [newData, oldData]] of collectionMap) {
|
|
45
|
-
defaultEmitHandler(collection, index, newData, oldData);
|
|
42
|
+
A.defaultEmitHandler(collection, index, newData, oldData);
|
|
46
43
|
}
|
|
47
44
|
}
|
|
48
45
|
}
|
|
@@ -61,11 +58,12 @@ function mergePatch(target: Patch, source: Patch, reverse = false) {
|
|
|
61
58
|
}
|
|
62
59
|
}
|
|
63
60
|
|
|
64
|
-
function silentlyApplyPatch(patch: Patch, force = false): boolean {
|
|
61
|
+
function silentlyApplyPatch(A: Aberdeen, patch: Patch, force = false): boolean {
|
|
62
|
+
const EMPTY = A.EMPTY;
|
|
65
63
|
for (const [collection, collectionMap] of patch) {
|
|
66
64
|
for (const [index, [newData, oldData]] of collectionMap) {
|
|
67
65
|
// MAP_SIZE_SYMBOL is synthetic - size is derived from add/delete operations
|
|
68
|
-
if (index === MAP_SIZE_SYMBOL) continue;
|
|
66
|
+
if (index === A.MAP_SIZE_SYMBOL) continue;
|
|
69
67
|
const actualData =
|
|
70
68
|
collection instanceof Map
|
|
71
69
|
? collection.has(index)
|
|
@@ -76,7 +74,7 @@ function silentlyApplyPatch(patch: Patch, force = false): boolean {
|
|
|
76
74
|
: EMPTY;
|
|
77
75
|
if (actualData !== oldData) {
|
|
78
76
|
if (force)
|
|
79
|
-
setTimeout(() => {
|
|
77
|
+
(A.window?.setTimeout ?? setTimeout)(() => {
|
|
80
78
|
throw new Error(
|
|
81
79
|
`Applying invalid patch: data ${String(actualData)} is unequal to expected old data ${String(oldData)} for index ${String(index)}`,
|
|
82
80
|
);
|
|
@@ -87,7 +85,7 @@ function silentlyApplyPatch(patch: Patch, force = false): boolean {
|
|
|
87
85
|
}
|
|
88
86
|
for (const [collection, collectionMap] of patch) {
|
|
89
87
|
for (const [index, [newData, oldData]] of collectionMap) {
|
|
90
|
-
if (index === MAP_SIZE_SYMBOL) continue;
|
|
88
|
+
if (index === A.MAP_SIZE_SYMBOL) continue;
|
|
91
89
|
if (collection instanceof Map) {
|
|
92
90
|
if (newData === EMPTY) collection.delete(index);
|
|
93
91
|
else collection.set(index, newData);
|
|
@@ -106,15 +104,16 @@ const appliedPredictions: Array<Patch> = [];
|
|
|
106
104
|
* Run the provided function, while treating all changes to Observables as predictions,
|
|
107
105
|
* meaning they will be reverted when changes come back from the server (or some other
|
|
108
106
|
* async source).
|
|
107
|
+
* @param A The Aberdeen instance (the default export of `aberdeen`, or one from `init`).
|
|
109
108
|
* @param predictFunc The function to run. It will generally modify some Observables
|
|
110
109
|
* to immediately reflect state (as closely as possible) that we expect the server
|
|
111
110
|
* to communicate back to us later on.
|
|
112
111
|
* @returns A `Patch` object. Don't modify it. This is only meant to be passed to `applyCanon`.
|
|
113
112
|
*/
|
|
114
|
-
export function applyPrediction(predictFunc: () => void): Patch {
|
|
115
|
-
const patch = recordPatch(predictFunc);
|
|
113
|
+
export function applyPrediction(A: Aberdeen, predictFunc: () => void): Patch {
|
|
114
|
+
const patch = recordPatch(A, predictFunc);
|
|
116
115
|
appliedPredictions.push(patch);
|
|
117
|
-
emitPatch(patch);
|
|
116
|
+
emitPatch(A, patch);
|
|
118
117
|
return patch;
|
|
119
118
|
}
|
|
120
119
|
|
|
@@ -127,6 +126,7 @@ export function applyPrediction(predictFunc: () => void): Patch {
|
|
|
127
126
|
*
|
|
128
127
|
* All of this is done such that redraws are only triggered if the overall effect is an
|
|
129
128
|
* actual change to an `Observable`.
|
|
129
|
+
* @param A The Aberdeen instance (the default export of `aberdeen`, or one from `init`).
|
|
130
130
|
* @param canonFunc The function to run without any predictions applied. This will typically
|
|
131
131
|
* make authoritative changes to the data, based on a server response.
|
|
132
132
|
* @param dropPredictions An optional list of predictions (as returned by `applyPrediction`)
|
|
@@ -134,22 +134,23 @@ export function applyPrediction(predictFunc: () => void): Patch {
|
|
|
134
134
|
* you'd want to drop the prediction that was done for that request.
|
|
135
135
|
*/
|
|
136
136
|
export function applyCanon(
|
|
137
|
+
A: Aberdeen,
|
|
137
138
|
canonFunc?: () => void,
|
|
138
139
|
dropPredictions: Array<Patch> = [],
|
|
139
140
|
) {
|
|
140
141
|
const resultPatch = new Map();
|
|
141
142
|
for (const prediction of appliedPredictions)
|
|
142
143
|
mergePatch(resultPatch, prediction, true);
|
|
143
|
-
silentlyApplyPatch(resultPatch, true);
|
|
144
|
+
silentlyApplyPatch(A, resultPatch, true);
|
|
144
145
|
|
|
145
146
|
for (const prediction of dropPredictions) {
|
|
146
147
|
const pos = appliedPredictions.indexOf(prediction);
|
|
147
148
|
if (pos >= 0) appliedPredictions.splice(pos, 1);
|
|
148
149
|
}
|
|
149
|
-
if (canonFunc) mergePatch(resultPatch, recordPatch(canonFunc));
|
|
150
|
+
if (canonFunc) mergePatch(resultPatch, recordPatch(A, canonFunc));
|
|
150
151
|
|
|
151
152
|
for (let idx = 0; idx < appliedPredictions.length; idx++) {
|
|
152
|
-
if (silentlyApplyPatch(appliedPredictions[idx])) {
|
|
153
|
+
if (silentlyApplyPatch(A, appliedPredictions[idx])) {
|
|
153
154
|
mergePatch(resultPatch, appliedPredictions[idx]);
|
|
154
155
|
} else {
|
|
155
156
|
appliedPredictions.splice(idx, 1);
|
|
@@ -157,5 +158,5 @@ export function applyCanon(
|
|
|
157
158
|
}
|
|
158
159
|
}
|
|
159
160
|
|
|
160
|
-
emitPatch(resultPatch);
|
|
161
|
+
emitPatch(A, resultPatch);
|
|
161
162
|
}
|