refactor: establish standalone application boundary
This commit is contained in:
@@ -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),
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user