Cleanup references to instance when disconnecting!
This commit is contained in:
parent
274eb54990
commit
1bcdb09b54
@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@tp/tp-store",
|
||||
"version": "1.1.1",
|
||||
"version": "1.1.2",
|
||||
"description": "",
|
||||
"main": "tp-store.js",
|
||||
"scripts": {
|
||||
|
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 } ]);
|
||||
|
Loading…
x
Reference in New Issue
Block a user