diff --git a/OpenScript.js b/OpenScript.js index 82a377e..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]); } } @@ -1744,7 +1750,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 +1804,15 @@ var OpenScript = { set(target, prop, value) { if(prop === "value") { + let current = target.value; + let nVal = value; + + if(typeof current === "object"){ + current = JSON.stringify(current); + nVal = JSON.stringify(nVal); + } - if(target.value === value) return true; + if(current === nVal) return true; Reflect.set(...arguments); @@ -2295,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)})`; } /**