Skip to content

Commit 92e59f4

Browse files
committed
remove memory leak on component unmount
1 parent 9ef4386 commit 92e59f4

File tree

1 file changed

+13
-7
lines changed

1 file changed

+13
-7
lines changed

OpenScript.js

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -739,6 +739,12 @@ var OpenScript = {
739739
*/
740740
listening = {};
741741

742+
/**
743+
* All the states that this component is listening to
744+
* @type {object<OpenScript.State>}
745+
*/
746+
states = {};
747+
742748
/**
743749
* List of components that this component is listening
744750
* to.
@@ -775,12 +781,6 @@ var OpenScript = {
775781
*/
776782
visible = true;
777783

778-
/**
779-
* Keeps track of why the
780-
* component is made visible or hidden
781-
*/
782-
visibleBy = 'parent';
783-
784784
/**
785785
* Anonymous component ID
786786
*/
@@ -1044,6 +1044,11 @@ var OpenScript = {
10441044
}
10451045
}
10461046

1047+
for(let id in this.states){
1048+
this.states[id]?.off(this);
1049+
delete this.states[id];
1050+
}
1051+
10471052
return true;
10481053
}
10491054

@@ -1293,6 +1298,7 @@ var OpenScript = {
12931298

12941299
if(args[i] instanceof OpenScript.State) {
12951300
args[i].listener(this);
1301+
this.states[args[i].id] = args[i];
12961302
final.states.push(args[i]);
12971303
}
12981304
}
@@ -2302,7 +2308,7 @@ var OpenScript = {
23022308
* @returns
23032309
*/
23042310
func = (component, method, ...args) => {
2305-
return `h.compMap.get('${component.name}')['${method}'](${this._escape(args)})`;
2311+
return `component('${component.name}')['${method}'](${this._escape(args)})`;
23062312
}
23072313

23082314
/**

0 commit comments

Comments
 (0)