Cleanup references to instance when disconnecting!
This commit is contained in:
14
store.js
14
store.js
@@ -37,6 +37,20 @@ export const Store = function(superClass) {
|
||||
this._writeKey(key, value);
|
||||
}
|
||||
|
||||
disconnectedCallback() {
|
||||
super.disconnectedCallback();
|
||||
|
||||
// Clean up all references to this instance.
|
||||
instancesPerKey.forEach((instances, key) => {
|
||||
const remainingInstances = instances.filter(entry => entry.instance !== this);
|
||||
if (remainingInstances.length === 0) {
|
||||
instancesPerKey.delete(key);
|
||||
} else {
|
||||
instancesPerKey.set(key, remainingInstances);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
_addInstance(instance, key, targetProperty) {
|
||||
if (instancesPerKey.has(key) === false) {
|
||||
instancesPerKey.set(key, [ { instance, targetProperty } ]);
|
||||
|
||||
Reference in New Issue
Block a user