@async/framework 0.4.0 → 0.6.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 +32 -0
- package/README.md +124 -7
- package/examples/cache/index.html +1 -1
- package/examples/components/index.html +1 -1
- package/examples/components/main.js +2 -2
- package/examples/counter/index.html +1 -1
- package/examples/partials/index.html +1 -1
- package/examples/product/index.html +1 -1
- package/examples/product/main.js +2 -2
- package/examples/router/index.html +1 -1
- package/examples/server-call/index.html +1 -1
- package/examples/ssr/index.html +1 -1
- package/examples/streaming/index.html +1 -1
- package/framework.d.ts +569 -0
- package/framework.js +325 -101
- package/framework.min.js +3648 -0
- package/framework.ts +3 -0
- package/framework.umd.js +4158 -0
- package/framework.umd.min.js +3671 -0
- package/package.json +34 -5
- package/src/app.js +2 -2
- package/src/async-signal.js +12 -1
- package/src/cache.js +5 -0
- package/src/component.js +80 -16
- package/src/handlers.js +12 -4
- package/src/index.js +1 -1
- package/src/loader.js +93 -9
- package/src/partials.js +5 -0
- package/src/registry-store.js +4 -0
- package/src/router.js +11 -2
- package/src/server.js +26 -6
- package/src/signals.js +16 -3
package/src/server.js
CHANGED
|
@@ -28,6 +28,11 @@ export function createServerRegistry(initialMap = {}, options = {}) {
|
|
|
28
28
|
return registry;
|
|
29
29
|
},
|
|
30
30
|
|
|
31
|
+
unregister(id) {
|
|
32
|
+
assertServerId(id);
|
|
33
|
+
return entries.delete(id);
|
|
34
|
+
},
|
|
35
|
+
|
|
31
36
|
resolve(id) {
|
|
32
37
|
assertServerId(id);
|
|
33
38
|
return entries.get(id);
|
|
@@ -43,7 +48,7 @@ export function createServerRegistry(initialMap = {}, options = {}) {
|
|
|
43
48
|
let runContext;
|
|
44
49
|
const server = createServerNamespace((childId, childArgs, childContext = {}) => {
|
|
45
50
|
return registry.run(childId, childArgs, { ...runContext, ...childContext });
|
|
46
|
-
});
|
|
51
|
+
}, {}, () => runContext);
|
|
47
52
|
|
|
48
53
|
const mergedContext = {
|
|
49
54
|
...defaults,
|
|
@@ -76,7 +81,7 @@ export function createServerRegistry(initialMap = {}, options = {}) {
|
|
|
76
81
|
}, registryStore, type);
|
|
77
82
|
|
|
78
83
|
registry.registerMany(initialMap);
|
|
79
|
-
return createServerNamespace((id, args, context) => registry.run(id, args, context), registry);
|
|
84
|
+
return createServerNamespace((id, args, context) => registry.run(id, args, context), registry, () => defaults);
|
|
80
85
|
}
|
|
81
86
|
|
|
82
87
|
export function createServerProxy({
|
|
@@ -127,7 +132,7 @@ export function createServerProxy({
|
|
|
127
132
|
_setContext(context = {}) {
|
|
128
133
|
Object.assign(defaults, context);
|
|
129
134
|
}
|
|
130
|
-
});
|
|
135
|
+
}, () => defaults);
|
|
131
136
|
}
|
|
132
137
|
|
|
133
138
|
export function resolveServerCommandArguments(args, context = {}) {
|
|
@@ -205,7 +210,7 @@ export function defaultInput(context = {}) {
|
|
|
205
210
|
};
|
|
206
211
|
}
|
|
207
212
|
|
|
208
|
-
function createServerNamespace(run, root = {}) {
|
|
213
|
+
function createServerNamespace(run, root = {}, contextProvider = () => ({})) {
|
|
209
214
|
const cache = new Map();
|
|
210
215
|
|
|
211
216
|
function namespace(parts) {
|
|
@@ -214,11 +219,14 @@ function createServerNamespace(run, root = {}) {
|
|
|
214
219
|
return cache.get(cacheKey);
|
|
215
220
|
}
|
|
216
221
|
|
|
217
|
-
const callable = (...args) => {
|
|
222
|
+
const callable = async (...args) => {
|
|
218
223
|
if (parts.length === 0) {
|
|
219
224
|
throw new Error("Server namespace is not directly callable.");
|
|
220
225
|
}
|
|
221
|
-
|
|
226
|
+
const context = contextProvider() ?? {};
|
|
227
|
+
const result = await run(parts.join("."), args, context);
|
|
228
|
+
await applyServerResult(result, context);
|
|
229
|
+
return unwrapServerResult(result);
|
|
222
230
|
};
|
|
223
231
|
|
|
224
232
|
const proxy = new Proxy(callable, {
|
|
@@ -229,6 +237,18 @@ function createServerNamespace(run, root = {}) {
|
|
|
229
237
|
if (prop in _target) {
|
|
230
238
|
return _target[prop];
|
|
231
239
|
}
|
|
240
|
+
if (parts.length === 0 && prop === "_withContext") {
|
|
241
|
+
return (context = {}) => createServerNamespace(run, root, () => ({
|
|
242
|
+
...(contextProvider() ?? {}),
|
|
243
|
+
...context
|
|
244
|
+
}));
|
|
245
|
+
}
|
|
246
|
+
if (parts.length === 0 && prop === "run" && typeof root.run === "function") {
|
|
247
|
+
return (id, args = [], context = {}) => root.run(id, args, {
|
|
248
|
+
...(contextProvider() ?? {}),
|
|
249
|
+
...context
|
|
250
|
+
});
|
|
251
|
+
}
|
|
232
252
|
if (parts.length === 0 && Object.hasOwn(root, prop)) {
|
|
233
253
|
return root[prop];
|
|
234
254
|
}
|
package/src/signals.js
CHANGED
|
@@ -121,7 +121,7 @@ export function createSignalRegistry(initialMap = {}, options = {}) {
|
|
|
121
121
|
const registryStore = options.registry ?? createRegistryStore();
|
|
122
122
|
const type = options.type ?? "signal";
|
|
123
123
|
const entries = registryStore._map(type);
|
|
124
|
-
const registryCleanups = new
|
|
124
|
+
const registryCleanups = new Map();
|
|
125
125
|
const runtimeContext = {};
|
|
126
126
|
const boundEntries = new Set();
|
|
127
127
|
|
|
@@ -144,6 +144,19 @@ export function createSignalRegistry(initialMap = {}, options = {}) {
|
|
|
144
144
|
return registry;
|
|
145
145
|
},
|
|
146
146
|
|
|
147
|
+
unregister(id) {
|
|
148
|
+
assertId(id);
|
|
149
|
+
if (!entries.has(id)) {
|
|
150
|
+
return false;
|
|
151
|
+
}
|
|
152
|
+
registryCleanups.get(id)?.();
|
|
153
|
+
registryCleanups.delete(id);
|
|
154
|
+
entries.get(id)?._dispose?.();
|
|
155
|
+
entries.delete(id);
|
|
156
|
+
boundEntries.delete(id);
|
|
157
|
+
return true;
|
|
158
|
+
},
|
|
159
|
+
|
|
147
160
|
ensure(id, initial) {
|
|
148
161
|
assertId(id);
|
|
149
162
|
if (!entries.has(id)) {
|
|
@@ -256,7 +269,7 @@ export function createSignalRegistry(initialMap = {}, options = {}) {
|
|
|
256
269
|
},
|
|
257
270
|
|
|
258
271
|
destroy() {
|
|
259
|
-
for (const cleanup of registryCleanups) {
|
|
272
|
+
for (const cleanup of registryCleanups.values()) {
|
|
260
273
|
cleanup();
|
|
261
274
|
}
|
|
262
275
|
registryCleanups.clear();
|
|
@@ -313,7 +326,7 @@ export function createSignalRegistry(initialMap = {}, options = {}) {
|
|
|
313
326
|
boundEntries.add(id);
|
|
314
327
|
const cleanup = entry._bindRegistry(registry, id);
|
|
315
328
|
if (typeof cleanup === "function") {
|
|
316
|
-
registryCleanups.
|
|
329
|
+
registryCleanups.set(id, cleanup);
|
|
317
330
|
}
|
|
318
331
|
}
|
|
319
332
|
}
|