refactor: establish standalone application boundary

This commit is contained in:
leefer
2026-08-03 21:42:25 +08:00
parent cc5fb8d73e
commit e1e76cd51e
324 changed files with 63090 additions and 44743 deletions
+16
View File
@@ -2,6 +2,7 @@
"use strict";
const definitions = new Map();
const featureBindings = new Map();
let sealed = false;
function register(feature, viewIds, lifecycle = {}) {
@@ -9,6 +10,13 @@
if (!feature || !Array.isArray(viewIds) || !viewIds.length) {
throw new Error("Page modules require a feature and at least one view ID");
}
if (typeof lifecycle.bind === "function") {
const existing = featureBindings.get(feature);
if (existing && existing !== lifecycle.bind) {
throw new Error(`Duplicate feature binding owner: ${feature}`);
}
featureBindings.set(feature, lifecycle.bind);
}
viewIds.forEach((viewId) => {
if (definitions.has(viewId)) throw new Error(`Duplicate page module: ${viewId}`);
definitions.set(viewId, Object.freeze({
@@ -26,6 +34,13 @@
const actions = Object.freeze({ ...(options.actions || {}) });
const missing = pages.all.filter((page) => !definitions.has(page.id)).map((page) => page.id);
if (missing.length) throw new Error(`Missing page modules: ${missing.join(", ")}`);
let eventsBound = false;
function bind() {
if (eventsBound) return;
eventsBound = true;
featureBindings.forEach((handler) => handler());
}
function run(actionNames, context) {
actionNames.forEach((actionName) => {
@@ -51,6 +66,7 @@
return Object.freeze({
afterMount,
beforeMount,
bind,
get: (viewId) => definitions.get(viewId) || null,
has: (viewId) => definitions.has(viewId),
});