From c4b0fc91629e6ea5fe6ff3e8d50e1f6bc6119e93 Mon Sep 17 00:00:00 2001 From: chris Date: Thu, 20 Feb 2025 00:11:23 +0100 Subject: [PATCH] FEAT,MINOR: (Re- ?) Introduced component subscription --- src/component.js | 5 +++++ src/context.js | 26 ++++++++++++++++++++++++++ 2 files changed, 31 insertions(+) diff --git a/src/component.js b/src/component.js index be5aa95..ee9db59 100644 --- a/src/component.js +++ b/src/component.js @@ -596,6 +596,11 @@ class Component extends StyleAndScriptStoringComponent { this._wenity.html = this._element; + for (let i = 0; i < this._toRegister.length; i++) { + const group = this._toRegister[i]; + Page.subscribeComponentToGroup(group, this._compName) + } + return this._wenity; } diff --git a/src/context.js b/src/context.js index 773c0b6..a4b0e94 100644 --- a/src/context.js +++ b/src/context.js @@ -21,10 +21,29 @@ class PageBuilder extends ScriptAndStyleContext { super(); this.#autoRegisteredComponents = []; this.#registeredComponents = []; + this._groups = new Map(); + } useCssCalc() { this._useCssCalc = true; } + + /** + * + * @param {*|Array<*>} groups + * @param {*} component + */ + subscribeComponentToGroup(groups, component) { + if (groups instanceof Array && !(groups instanceof String)) { + for (let i = 0; i < groups.length; i++) { + this.subscribeComponentToGroup(groups[i], component); + } + } else { + if (!this._groups.has(groups)) { + this._groups.set(groups, []); + } + this._groups.get(groups).push(component); + } } autoRegisterComponent() { @@ -159,6 +178,13 @@ class PageBuilder extends ScriptAndStyleContext { head.insertAdjacentElement("beforeend", meta); } + generate() { + super.generate(); + compelgroups = this._groups; + } + + + }