@async/framework 0.2.2 → 0.3.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/CHANGELOG.md +13 -0
- package/README.md +153 -24
- package/examples/cache/index.html +3 -3
- package/examples/components/main.js +2 -2
- package/examples/counter/index.html +2 -2
- package/examples/partials/index.html +2 -2
- package/examples/product/index.html +9 -9
- package/examples/router/index.html +2 -2
- package/examples/router/main.js +2 -2
- package/examples/server-call/index.html +2 -2
- package/examples/ssr/index.html +1 -1
- package/examples/ssr/main.js +2 -2
- package/examples/streaming/index.html +2 -2
- package/examples/streaming/main.js +2 -2
- package/package.json +9 -2
- package/src/app.js +73 -53
- package/src/attributes.js +50 -0
- package/src/cache.js +31 -16
- package/src/component.js +11 -4
- package/src/handlers.js +24 -5
- package/src/index.js +2 -0
- package/src/loader.js +71 -45
- package/src/partials.js +11 -4
- package/src/registry-store.js +257 -0
- package/src/router.js +42 -3
- package/src/server.js +12 -4
- package/src/signals.js +32 -10
package/src/signals.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { asyncSignal as createAsyncSignal, isAsyncSignal } from "./async-signal.js";
|
|
2
|
+
import { attachRegistryInspection, createRegistryStore } from "./registry-store.js";
|
|
2
3
|
|
|
3
4
|
const signalKind = Symbol.for("@async/framework.signal");
|
|
4
5
|
const computedKind = Symbol.for("@async/framework.computed");
|
|
@@ -116,12 +117,15 @@ export function effect(fn) {
|
|
|
116
117
|
};
|
|
117
118
|
}
|
|
118
119
|
|
|
119
|
-
export function createSignalRegistry(initialMap = {}) {
|
|
120
|
-
const
|
|
120
|
+
export function createSignalRegistry(initialMap = {}, options = {}) {
|
|
121
|
+
const registryStore = options.registry ?? createRegistryStore();
|
|
122
|
+
const type = options.type ?? "signal";
|
|
123
|
+
const entries = registryStore._map(type);
|
|
121
124
|
const registryCleanups = new Set();
|
|
122
125
|
const runtimeContext = {};
|
|
126
|
+
const boundEntries = new Set();
|
|
123
127
|
|
|
124
|
-
const registry = {
|
|
128
|
+
const registry = attachRegistryInspection({
|
|
125
129
|
register(id, signalLike) {
|
|
126
130
|
assertId(id);
|
|
127
131
|
if (entries.has(id)) {
|
|
@@ -129,12 +133,7 @@ export function createSignalRegistry(initialMap = {}) {
|
|
|
129
133
|
}
|
|
130
134
|
const entry = normalizeSignal(signalLike);
|
|
131
135
|
entries.set(id, entry);
|
|
132
|
-
|
|
133
|
-
const cleanup = entry._bindRegistry(registry, id);
|
|
134
|
-
if (typeof cleanup === "function") {
|
|
135
|
-
registryCleanups.add(cleanup);
|
|
136
|
-
}
|
|
137
|
-
}
|
|
136
|
+
bindEntry(id, entry);
|
|
138
137
|
return registry.ref(id);
|
|
139
138
|
},
|
|
140
139
|
|
|
@@ -289,11 +288,34 @@ export function createSignalRegistry(initialMap = {}) {
|
|
|
289
288
|
|
|
290
289
|
_context() {
|
|
291
290
|
return runtimeContext;
|
|
291
|
+
},
|
|
292
|
+
|
|
293
|
+
_adoptMany(map = {}) {
|
|
294
|
+
for (const id of Object.keys(map ?? {})) {
|
|
295
|
+
if (entries.has(id)) {
|
|
296
|
+
bindEntry(id, entries.get(id));
|
|
297
|
+
}
|
|
298
|
+
}
|
|
299
|
+
return registry;
|
|
292
300
|
}
|
|
293
|
-
};
|
|
301
|
+
}, registryStore, type);
|
|
294
302
|
|
|
303
|
+
for (const [id, entry] of entries) {
|
|
304
|
+
bindEntry(id, entry);
|
|
305
|
+
}
|
|
295
306
|
registry.registerMany(initialMap);
|
|
296
307
|
return registry;
|
|
308
|
+
|
|
309
|
+
function bindEntry(id, entry) {
|
|
310
|
+
if (boundEntries.has(id) || typeof entry?._bindRegistry !== "function") {
|
|
311
|
+
return;
|
|
312
|
+
}
|
|
313
|
+
boundEntries.add(id);
|
|
314
|
+
const cleanup = entry._bindRegistry(registry, id);
|
|
315
|
+
if (typeof cleanup === "function") {
|
|
316
|
+
registryCleanups.add(cleanup);
|
|
317
|
+
}
|
|
318
|
+
}
|
|
297
319
|
}
|
|
298
320
|
|
|
299
321
|
function normalizeSignal(signalLike) {
|