Add broker statistics
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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 () {
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
import 'mocha'
|
||||
import './TreeNode.findNode'
|
||||
|
||||
import { Tree, TreeNodeFactory } from '../'
|
||||
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
import 'mocha'
|
||||
import './TreeNode.findNode'
|
||||
|
||||
import { TreeNodeFactory } from '../'
|
||||
import { expect } from 'chai'
|
||||
|
||||
@@ -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
|
||||
}
|
||||
@@ -1,4 +1,3 @@
|
||||
import './TreeNode.findNode'
|
||||
import 'mocha'
|
||||
|
||||
import { TreeNodeFactory } from '../'
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
import 'mocha'
|
||||
import './TreeNode.findNode'
|
||||
|
||||
import { TreeNodeFactory } from '../'
|
||||
import { expect } from 'chai'
|
||||
|
||||
Reference in New Issue
Block a user