Add broker statistics

This commit is contained in:
Thomas Nordquist
2019-01-22 19:54:36 +01:00
parent a86871b161
commit 37694d38b0
13 changed files with 170 additions and 37 deletions

View File

@@ -148,6 +148,25 @@ export class TreeNode {
return this.cachedChildTopics
}
public findNode (path: String): TreeNode | undefined {
const topics = path.split('/')
return this.findChild(topics)
}
private findChild(edges: string[]): TreeNode | undefined {
if (edges.length === 0) {
return this
}
const nextEdge = this.edges[edges[0]]
if (!nextEdge) {
return undefined
}
return nextEdge.target.findChild(edges.slice(1))
}
private mergeEdges(node: TreeNode) {
const edgeKeys = Object.keys(node.edges)
let edgesDidUpdate = false

View File

@@ -2,7 +2,6 @@ import 'mocha'
import { EventDispatcher } from '../../../../events'
import { expect } from 'chai'
import { doesNotReject } from 'assert'
describe('EventDispatcher', async () => {
it('should dispatch', async function () {

View File

@@ -1,5 +1,4 @@
import 'mocha'
import './TreeNode.findNode'
import { Tree, TreeNodeFactory } from '../'

View File

@@ -1,5 +1,4 @@
import 'mocha'
import './TreeNode.findNode'
import { TreeNodeFactory } from '../'
import { expect } from 'chai'

View File

@@ -1,19 +0,0 @@
import { TreeNode } from '../'
declare module '../' {
interface TreeNode {
findNode(path: String): TreeNode | undefined
}
}
TreeNode.prototype.findNode = function (path: String): TreeNode | undefined {
const topics = path.split('/')
const edge = this.edges[topics[0]]
const remainingTopics = topics.slice(1, topics.length)
if (edge && remainingTopics.length === 0) {
return edge.target
} else if (edge) {
return edge.target.findNode(remainingTopics.join('/'))
}
return undefined
}

View File

@@ -1,4 +1,3 @@
import './TreeNode.findNode'
import 'mocha'
import { TreeNodeFactory } from '../'

View File

@@ -1,5 +1,4 @@
import 'mocha'
import './TreeNode.findNode'
import { TreeNodeFactory } from '../'
import { expect } from 'chai'