From 1db18defea29ec8e9982b68dcb4cfc6b5addc4e5 Mon Sep 17 00:00:00 2001 From: Esiur Project Date: Sun, 19 Jun 2022 13:29:51 +0300 Subject: [PATCH] scope fix --- src/Core/IUI.js | 8 +++++--- src/Core/IUIElement.js | 7 +++++++ src/Router/Route.js | 2 +- src/iui.js | 2 +- 4 files changed, 14 insertions(+), 5 deletions(-) diff --git a/src/Core/IUI.js b/src/Core/IUI.js index 78e7ea3..48d6b1a 100644 --- a/src/Core/IUI.js +++ b/src/Core/IUI.js @@ -162,6 +162,8 @@ export class IUI { if (scope == null) scope = {}; + else + scope = {...scope}; // get refs before they get overwritten //let refs = scope?.refs; @@ -169,7 +171,8 @@ export class IUI { // some element extended or overwritten the binding arguments if (element.scope != null) IUI.extend(scope, element.scope, true); - else if (element.hasAttribute(":scope")) + + if (element.hasAttribute(":scope")) { let script = element.getAttribute(":scope"); let code = `try {\r\n context.value = ${script}; \r\n}\r\n catch(ex) { context.error = ex; }` @@ -281,8 +284,7 @@ export class IUI { let rt = func.apply(el.parentElement, scopeValues); - console.log("rt", rt); - + // Apply the returned object to the parent element. if (typeof (rt) === "object") { for (var k in rt) el.parentElement[k] = rt[k]; diff --git a/src/Core/IUIElement.js b/src/Core/IUIElement.js index 9980131..c0f1d3a 100644 --- a/src/Core/IUIElement.js +++ b/src/Core/IUIElement.js @@ -43,6 +43,7 @@ export default class IUIElement extends HTMLElement { await IUI.render(this, this._data); } + _getParentData() { var p = this.parentElement; do { @@ -58,8 +59,14 @@ export default class IUIElement extends HTMLElement { this._emit("data", {data: value}); await IUI.render(this, value); + // notify updated callback + await this.updated(); } + + async updated() { + // to be implemented by the user. + } get data() { return this._data; diff --git a/src/Router/Route.js b/src/Router/Route.js index 14d27dd..ef9ccb0 100644 --- a/src/Router/Route.js +++ b/src/Router/Route.js @@ -22,7 +22,7 @@ export default IUI.module( } get scope() { - return { route: this, view: this }; + return { route: this, view: this, refs: this.refs }; } _updateLinks() { diff --git a/src/iui.js b/src/iui.js index dabcc32..ebf1a57 100644 --- a/src/iui.js +++ b/src/iui.js @@ -62,5 +62,5 @@ window.addEventListener("load", async function () { }); window.iui = iui; - +window.IUI = IUI; window.Modifiable = Modifiable;