-
+
{
collapsed={false}
settings={this.props.settings}
lastUpdate={tree.lastUpdate}
+ actions={this.props.actions}
selectTopicAction={this.props.actions.selectTopic}
/>
diff --git a/app/src/model/TopicViewModel.ts b/app/src/model/TopicViewModel.ts
index f3a8da5..3c7ef54 100644
--- a/app/src/model/TopicViewModel.ts
+++ b/app/src/model/TopicViewModel.ts
@@ -4,8 +4,8 @@ import { EventDispatcher } from '../../../events'
export class TopicViewModel implements Destroyable {
private selected: boolean
private expanded: boolean
- public selectionChange = new EventDispatcher
()
- public expandedChange = new EventDispatcher()
+ public selectionChange = new EventDispatcher()
+ public expandedChange = new EventDispatcher()
public constructor() {
this.selected = false
diff --git a/app/src/reducers/Global.ts b/app/src/reducers/Global.ts
index 3c2ef6e..c61808b 100644
--- a/app/src/reducers/Global.ts
+++ b/app/src/reducers/Global.ts
@@ -44,7 +44,6 @@ export const globalState: Reducer, GlobalAction> =
action
): GlobalState => {
trackEvent(action.type)
- console.log(action.type)
switch (action.type) {
case ActionTypes.showUpdateNotification:
diff --git a/backend/src/DataSource/DataSourceState.ts b/backend/src/DataSource/DataSourceState.ts
index abffb36..d69bfd6 100644
--- a/backend/src/DataSource/DataSourceState.ts
+++ b/backend/src/DataSource/DataSourceState.ts
@@ -7,7 +7,7 @@ export interface DataSourceState {
}
export class DataSourceStateMachine {
- public onUpdate = new EventDispatcher()
+ public onUpdate = new EventDispatcher()
private state: DataSourceState = {
error: undefined,
connected: false,
diff --git a/backend/src/Model/Tree.ts b/backend/src/Model/Tree.ts
index 09232fc..ca8514f 100644
--- a/backend/src/Model/Tree.ts
+++ b/backend/src/Model/Tree.ts
@@ -12,7 +12,7 @@ export class Tree extends TreeNode {
public isTree = true
private cachedHash = `${Math.random()}`
private unmergedMessages: ChangeBuffer = new ChangeBuffer()
- public didReceive = new EventDispatcher>()
+ public didReceive = new EventDispatcher()
constructor() {
super(undefined, undefined)
diff --git a/backend/src/Model/TreeNode.ts b/backend/src/Model/TreeNode.ts
index 458cc36..c2b6c11 100644
--- a/backend/src/Model/TreeNode.ts
+++ b/backend/src/Model/TreeNode.ts
@@ -13,9 +13,10 @@ export class TreeNode {
public collapsed = false
public messages: number = 0
public lastUpdate: number = Date.now()
- public onMerge = new EventDispatcher>()
- public onEdgesChange = new EventDispatcher>()
- public onMessage = new EventDispatcher>()
+ public onMerge = new EventDispatcher()
+ public onEdgesChange = new EventDispatcher()
+ public onMessage = new EventDispatcher()
+ public onDestroy = new EventDispatcher>()
public isTree = false
private cachedPath?: string
@@ -65,7 +66,11 @@ export class TreeNode {
if (!previous || !this.sourceEdge) {
return
}
+ this.lastUpdate = Date.now()
previous.removeEdge(this.sourceEdge)
+ if (!this.isTree) {
+ this.destroy()
+ }
}
private findChild(edges: Array): TreeNode | undefined {
@@ -101,6 +106,9 @@ export class TreeNode {
}
public destroy() {
+ this.onDestroy.dispatch(this)
+ this.onDestroy.removeAllListeners()
+
for (const edge of this.edgeArray) {
edge.target.destroy()
}
@@ -158,6 +166,8 @@ export class TreeNode {
this.edgeArray.push(edge)
edge.source = this
+ edge.target && edge.target.removeFromTreeIfEmpty()
+
if (emitUpdate) {
this.onEdgesChange.dispatch()
}
@@ -175,8 +185,12 @@ export class TreeNode {
public removeEdge(edge: Edge) {
delete this.edges[edge.name]
this.edgeArray = Object.values(this.edges)
- this.onMerge.dispatch()
+ this.removeFromTreeIfEmpty()
+ this.onMerge.dispatch()
+ }
+
+ public removeFromTreeIfEmpty() {
if (this.isTopicEmptyLeaf()) {
this.removeFromParent()
}
@@ -189,10 +203,7 @@ export class TreeNode {
this.mqttMessage = node.mqttMessage
}
- if (this.isTopicEmptyLeaf()) {
- this.removeFromParent()
- }
-
+ this.removeFromTreeIfEmpty()
this.mergeEdges(node)
this.onMerge.dispatch()
}
diff --git a/backend/src/Model/spec/EventDispatcher.spec.ts b/backend/src/Model/spec/EventDispatcher.spec.ts
index 153e774..1276bae 100644
--- a/backend/src/Model/spec/EventDispatcher.spec.ts
+++ b/backend/src/Model/spec/EventDispatcher.spec.ts
@@ -4,7 +4,7 @@ import 'mocha'
describe('EventDispatcher', async () => {
it('should dispatch', async function() {
- const dispatcher = new EventDispatcher()
+ const dispatcher = new EventDispatcher()
this.timeout(300)
setTimeout(() => dispatcher.dispatch('hello'), 5)
@@ -18,7 +18,7 @@ describe('EventDispatcher', async () => {
})
it('should unsubscribe', async function() {
- const dispatcher = new EventDispatcher()
+ const dispatcher = new EventDispatcher()
this.timeout(300)
let callbackCounter = 0
const callback = (msg: any) => {
diff --git a/backend/src/index.ts b/backend/src/index.ts
index 0f73129..48a0b2c 100644
--- a/backend/src/index.ts
+++ b/backend/src/index.ts
@@ -45,7 +45,6 @@ export class ConnectionManager {
if (buffer.length > 20000) {
buffer = buffer.slice(0, 20000)
}
-
backendEvents.emit(messageEvent, {
topic,
payload: Base64Message.fromBuffer(buffer),
diff --git a/events/EventDispatcher.ts b/events/EventDispatcher.ts
index 2cabbf3..a3152b0 100644
--- a/events/EventDispatcher.ts
+++ b/events/EventDispatcher.ts
@@ -5,7 +5,7 @@ interface CallbackStore {
callback: any
}
-export class EventDispatcher {
+export class EventDispatcher {
private emitter = new EventEmitter()
private callbacks: Array = []
diff --git a/src/MenuTemplate.ts b/src/MenuTemplate.ts
index 38ddb4b..5faa41f 100644
--- a/src/MenuTemplate.ts
+++ b/src/MenuTemplate.ts
@@ -10,7 +10,7 @@ const applicationMenu: MenuItemConstructorOptions = {
click: () => {
openAboutWindow({
icon_path: path.join(__dirname, '..', '..', 'icon.png'),
- license: 'AGPL-3.0',
+ license: 'CC-BY-ND-4.0',
homepage: 'https://thomasnordquist.github.io/MQTT-Explorer/',
bug_report_url: 'https://github.com/thomasnordquist/MQTT-Explorer/issues',
description: 'Author: Thomas Nordquist',