Destroy view-models when destroying trees

This commit is contained in:
Thomas Nordquist
2019-05-07 13:18:02 +02:00
parent dfaae34cf5
commit 63f89d628e
7 changed files with 21 additions and 7 deletions

View File

@@ -1,7 +1,8 @@
import { Destroyable } from './Destroyable'
import { Edge, Message, RingBuffer } from './'
import { EventDispatcher, MqttMessage } from '../../../events'
export class TreeNode<ViewModel> {
export class TreeNode<ViewModel extends Destroyable> {
public sourceEdge?: Edge<ViewModel>
public message?: Message
public mqttMessage?: MqttMessage
@@ -103,6 +104,8 @@ export class TreeNode<ViewModel> {
for (const edge of this.edgeArray) {
edge.target.destroy()
}
this.viewModel && this.viewModel.destroy()
this.viewModel = undefined
this.edgeArray = []
this.edges = {}
this.cachedChildTopics = []