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.
Files changed (139) hide show
  1. package/dist/src/aberdeen.d.ts +928 -944
  2. package/dist/src/aberdeen.js +1693 -1705
  3. package/dist/src/aberdeen.js.map +3 -3
  4. package/dist/src/index.d.ts +12 -0
  5. package/dist/src/index.js +11 -0
  6. package/dist/src/index.js.map +10 -0
  7. package/dist/src/prediction.d.ts +7 -4
  8. package/dist/src/prediction.js +18 -23
  9. package/dist/src/prediction.js.map +3 -3
  10. package/dist/src/route.d.ts +114 -101
  11. package/dist/src/route.js +246 -253
  12. package/dist/src/route.js.map +3 -3
  13. package/dist/src/server-dom.d.ts +158 -0
  14. package/dist/src/server-dom.js +458 -0
  15. package/dist/src/server-dom.js.map +10 -0
  16. package/dist/src/server.d.ts +55 -0
  17. package/dist/src/server.js +25 -0
  18. package/dist/src/server.js.map +10 -0
  19. package/dist/src/transitions.js +7 -4
  20. package/dist/src/transitions.js.map +3 -3
  21. package/dist/tests/environment.d.ts +24 -0
  22. package/dist/tests/{fakedom.js → environment.js} +239 -288
  23. package/dist/tests/environment.js.map +11 -0
  24. package/dist/tests/helpers.d.ts +15 -3
  25. package/dist/tests/helpers.js +277 -306
  26. package/dist/tests/helpers.js.map +6 -5
  27. package/dist-docs/Tutorial/index.html +30 -30
  28. package/dist-docs/aberdeen/Aberdeen/index.html +350 -0
  29. package/dist-docs/aberdeen/InitOptions/index.html +4 -0
  30. package/dist-docs/aberdeen/KeyToString/index.html +2 -0
  31. package/dist-docs/aberdeen/PromiseProxy/index.html +6 -6
  32. package/dist-docs/aberdeen/SortKeyType/index.html +2 -0
  33. package/dist-docs/aberdeen/TargetType/index.html +2 -0
  34. package/dist-docs/aberdeen/ValueRef/index.html +2 -0
  35. package/dist-docs/aberdeen/WindowLike/index.html +5 -0
  36. package/dist-docs/aberdeen/{clone → createA}/index.html +10 -5
  37. package/dist-docs/aberdeen/index.html +13 -54
  38. package/dist-docs/assets/aberdeen/aberdeen.d.ts +928 -944
  39. package/dist-docs/assets/aberdeen/aberdeen.js +1693 -1705
  40. package/dist-docs/assets/aberdeen/aberdeen.js.map +3 -3
  41. package/dist-docs/assets/aberdeen/index.d.ts +12 -0
  42. package/dist-docs/assets/aberdeen/index.js +11 -0
  43. package/dist-docs/assets/aberdeen/index.js.map +10 -0
  44. package/dist-docs/assets/aberdeen/prediction.d.ts +7 -4
  45. package/dist-docs/assets/aberdeen/prediction.js +18 -23
  46. package/dist-docs/assets/aberdeen/prediction.js.map +3 -3
  47. package/dist-docs/assets/aberdeen/route.d.ts +114 -101
  48. package/dist-docs/assets/aberdeen/route.js +246 -253
  49. package/dist-docs/assets/aberdeen/route.js.map +3 -3
  50. package/dist-docs/assets/aberdeen/server-dom.d.ts +158 -0
  51. package/dist-docs/assets/aberdeen/server-dom.js +458 -0
  52. package/dist-docs/assets/aberdeen/server-dom.js.map +10 -0
  53. package/dist-docs/assets/aberdeen/server.d.ts +55 -0
  54. package/dist-docs/assets/aberdeen/server.js +25 -0
  55. package/dist-docs/assets/aberdeen/server.js.map +10 -0
  56. package/dist-docs/assets/aberdeen/transitions.js +7 -4
  57. package/dist-docs/assets/aberdeen/transitions.js.map +3 -3
  58. package/dist-docs/assets/navigation.js +1 -1
  59. package/dist-docs/assets/search.js +1 -1
  60. package/dist-docs/dispatcher/Dispatcher/index.html +5 -6
  61. package/dist-docs/dispatcher/MATCH_FAILED/index.html +2 -2
  62. package/dist-docs/dispatcher/MATCH_REST/index.html +2 -2
  63. package/dist-docs/dispatcher/index.html +2 -2
  64. package/dist-docs/hierarchy.html +1 -1
  65. package/dist-docs/index-1/index.html +2 -0
  66. package/dist-docs/index.html +2 -2
  67. package/dist-docs/media/CHANGELOG.md +10 -1
  68. package/dist-docs/modules.html +1 -1
  69. package/dist-docs/prediction/applyCanon/index.html +4 -3
  70. package/dist-docs/prediction/applyPrediction/index.html +4 -3
  71. package/dist-docs/prediction/index.html +2 -2
  72. package/dist-docs/route/RouteApi/index.html +60 -0
  73. package/dist-docs/route/{Route → RouteState}/index.html +9 -9
  74. package/dist-docs/route/createRoute/index.html +5 -0
  75. package/dist-docs/route/index.html +6 -15
  76. package/dist-docs/server/RenderToStringOptions/index.html +6 -0
  77. package/dist-docs/server/RenderToStringResult/index.html +6 -0
  78. package/dist-docs/server/index.html +4 -0
  79. package/dist-docs/server/renderToString/index.html +6 -0
  80. package/dist-docs/sitemap.xml +52 -156
  81. package/dist-docs/transitions/grow/index.html +2 -2
  82. package/dist-docs/transitions/index.html +2 -2
  83. package/dist-docs/transitions/shrink/index.html +2 -2
  84. package/package.json +17 -7
  85. package/skill/SKILL.md +28 -28
  86. package/skill/aberdeen.md +471 -3448
  87. package/skill/dispatcher.md +6 -16
  88. package/skill/prediction.md +17 -5
  89. package/skill/route.md +155 -137
  90. package/skill/transitions.md +3 -3
  91. package/src/aberdeen.ts +1224 -741
  92. package/src/index.ts +13 -0
  93. package/src/prediction.ts +25 -24
  94. package/src/route.ts +419 -393
  95. package/src/server-dom.ts +508 -0
  96. package/src/server.ts +74 -0
  97. package/src/transitions.ts +9 -3
  98. package/dist/tests/fakedom.d.ts +0 -9
  99. package/dist/tests/fakedom.js.map +0 -10
  100. package/dist-docs/aberdeen/A/index.html +0 -115
  101. package/dist-docs/aberdeen/CUSTOM_DUMP/index.html +0 -7
  102. package/dist-docs/aberdeen/NO_COPY/index.html +0 -2
  103. package/dist-docs/aberdeen/OPAQUE/index.html +0 -12
  104. package/dist-docs/aberdeen/clean/index.html +0 -11
  105. package/dist-docs/aberdeen/copy/index.html +0 -22
  106. package/dist-docs/aberdeen/count/index.html +0 -7
  107. package/dist-docs/aberdeen/cssVars/index.html +0 -11
  108. package/dist-docs/aberdeen/darkMode/index.html +0 -9
  109. package/dist-docs/aberdeen/default/index.html +0 -341
  110. package/dist-docs/aberdeen/derive/index.html +0 -18
  111. package/dist-docs/aberdeen/disableCreateDestroy/index.html +0 -6
  112. package/dist-docs/aberdeen/dump/index.html +0 -11
  113. package/dist-docs/aberdeen/insertCss/index.html +0 -30
  114. package/dist-docs/aberdeen/insertGlobalCss/index.html +0 -19
  115. package/dist-docs/aberdeen/invertString/index.html +0 -13
  116. package/dist-docs/aberdeen/isEmpty/index.html +0 -12
  117. package/dist-docs/aberdeen/map/index.html +0 -26
  118. package/dist-docs/aberdeen/merge/index.html +0 -11
  119. package/dist-docs/aberdeen/mount/index.html +0 -17
  120. package/dist-docs/aberdeen/multiMap/index.html +0 -28
  121. package/dist-docs/aberdeen/onEach/index.html +0 -19
  122. package/dist-docs/aberdeen/partition/index.html +0 -36
  123. package/dist-docs/aberdeen/peek/index.html +0 -40
  124. package/dist-docs/aberdeen/proxy/index.html +0 -35
  125. package/dist-docs/aberdeen/ref/index.html +0 -13
  126. package/dist-docs/aberdeen/runQueue/index.html +0 -13
  127. package/dist-docs/aberdeen/setErrorHandler/index.html +0 -16
  128. package/dist-docs/aberdeen/setSpacingCssVars/index.html +0 -8
  129. package/dist-docs/aberdeen/unmountAll/index.html +0 -5
  130. package/dist-docs/aberdeen/unproxy/index.html +0 -11
  131. package/dist-docs/route/back/index.html +0 -4
  132. package/dist-docs/route/current/index.html +0 -2
  133. package/dist-docs/route/go/index.html +0 -14
  134. package/dist-docs/route/interceptLinks/index.html +0 -8
  135. package/dist-docs/route/matchCurrent/index.html +0 -10
  136. package/dist-docs/route/persistScroll/index.html +0 -6
  137. package/dist-docs/route/push/index.html +0 -6
  138. package/dist-docs/route/setLog/index.html +0 -3
  139. 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
- import {
2
- defaultEmitHandler,
3
- withEmitHandler,
4
- EMPTY,
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<TargetType, Map<any, [any, any]>>;
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: TargetType,
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
  }