From 9ef43867c629d9ad6bb0d95b241c169c9f0781a4 Mon Sep 17 00:00:00 2001 From: levizwannah Date: Tue, 25 Jul 2023 12:32:43 +0300 Subject: [PATCH 1/2] added deep object comparison for state change and async state render call behavoir --- OpenScript.js | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/OpenScript.js b/OpenScript.js index 82a377e..8136692 100644 --- a/OpenScript.js +++ b/OpenScript.js @@ -1744,7 +1744,7 @@ var OpenScript = { * @param {...any} args * @returns */ - fire(...args) { + async fire(...args) { for(let [k, component] of this.listeners){ component.wrap(...args, this.signature); @@ -1798,8 +1798,15 @@ var OpenScript = { set(target, prop, value) { if(prop === "value") { + let current = target.value; + let nVal = value; - if(target.value === value) return true; + if(typeof current === "object"){ + current = JSON.stringify(current); + nVal = JSON.stringify(nVal); + } + + if(current === nVal) return true; Reflect.set(...arguments); From 92e59f4aab0f8c625595dd38f301356d12e63b48 Mon Sep 17 00:00:00 2001 From: levizwannah Date: Thu, 27 Jul 2023 09:43:16 +0300 Subject: [PATCH 2/2] remove memory leak on component unmount --- OpenScript.js | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/OpenScript.js b/OpenScript.js index 8136692..d825138 100644 --- a/OpenScript.js +++ b/OpenScript.js @@ -739,6 +739,12 @@ var OpenScript = { */ listening = {}; + /** + * All the states that this component is listening to + * @type {object} + */ + states = {}; + /** * List of components that this component is listening * to. @@ -775,12 +781,6 @@ var OpenScript = { */ visible = true; - /** - * Keeps track of why the - * component is made visible or hidden - */ - visibleBy = 'parent'; - /** * Anonymous component ID */ @@ -1044,6 +1044,11 @@ var OpenScript = { } } + for(let id in this.states){ + this.states[id]?.off(this); + delete this.states[id]; + } + return true; } @@ -1293,6 +1298,7 @@ var OpenScript = { if(args[i] instanceof OpenScript.State) { args[i].listener(this); + this.states[args[i].id] = args[i]; final.states.push(args[i]); } } @@ -2302,7 +2308,7 @@ var OpenScript = { * @returns */ func = (component, method, ...args) => { - return `h.compMap.get('${component.name}')['${method}'](${this._escape(args)})`; + return `component('${component.name}')['${method}'](${this._escape(args)})`; } /**