update: unsubscribe subscriptions
This commit is contained in:
@ -14,10 +14,7 @@ export const HublReactivity = {
|
||||
callback: function () {
|
||||
this.subscribe();
|
||||
}
|
||||
},
|
||||
refreshData: {
|
||||
type: String,
|
||||
},
|
||||
}
|
||||
},
|
||||
async fetchData(value) {
|
||||
this.resourceId = null;
|
||||
@ -30,11 +27,26 @@ export const HublReactivity = {
|
||||
}
|
||||
this.subscribe();
|
||||
},
|
||||
unsubscribe(resourceId, targetSrc) {
|
||||
const resourcesSub = store.subscriptionVirtualContainersIndex.get(resourceId);
|
||||
const targetSub = store.subscriptionVirtualContainersIndex.get(targetSrc);
|
||||
const newResourceSub = resourcesSub.filter(r => r !== targetSrc);
|
||||
const newTargetSub = targetSub.filter(r => r !== resourceId);
|
||||
store.subscriptionVirtualContainersIndex.set(resourceId, newResourceSub);
|
||||
store.subscriptionVirtualContainersIndex.set(targetSrc, newTargetSub);
|
||||
},
|
||||
detached() {
|
||||
this.unsubscribe(this.resourceId, this.targetSrc)
|
||||
},
|
||||
subscribe() {
|
||||
if (this.refreshData === '') { // clears cache and re-fetch data
|
||||
if (this.oldResourceId && this.oldTargetSrc && (this.oldResourceId !== this.resourceId || this.oldTargetSrc !== this.targetSrc)) {
|
||||
this.unsubscribe(this.oldResourceId, this.oldTargetSrc);
|
||||
}
|
||||
if (this.resourceId && this.targetSrc) {
|
||||
store.subscribeVirtualContainerTo(this.resourceId, this.targetSrc);
|
||||
} else { // notifies components
|
||||
store.subscribeResourceTo(this.resourceId, this.targetSrc);
|
||||
store.subscribeVirtualContainerTo(this.targetSrc, this.resourceId);
|
||||
this.oldResourceId = this.resourceId;
|
||||
this.oldTargetSrc = this.targetSrc;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user