Update code formatting
This commit is contained in:
@@ -26,7 +26,7 @@ export class RingBuffer<T extends Lengthwise> {
|
||||
if (remainingSize < 0) {
|
||||
this.freeSomeSpace(Math.abs(remainingSize))
|
||||
}
|
||||
while ((this.end - this.start) >= this.maxItems) {
|
||||
while (this.end - this.start >= this.maxItems) {
|
||||
this.dropFirst()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,11 +1,6 @@
|
||||
import { ChangeBuffer } from './ChangeBuffer'
|
||||
import { Destroyable } from './Destroyable'
|
||||
import {
|
||||
EventBusInterface,
|
||||
EventDispatcher,
|
||||
makeConnectionMessageEvent,
|
||||
MqttMessage
|
||||
} from '../../../events'
|
||||
import { EventBusInterface, EventDispatcher, makeConnectionMessageEvent, MqttMessage } from '../../../events'
|
||||
import { TreeNode } from './'
|
||||
import { TreeNodeFactory } from './TreeNodeFactory'
|
||||
|
||||
@@ -35,7 +30,11 @@ export class Tree<ViewModel extends Destroyable> extends TreeNode<ViewModel> {
|
||||
this.didReceive.removeAllListeners()
|
||||
}
|
||||
|
||||
public updateWithConnection(emitter: EventBusInterface, connectionId: string, nodeFilter?: (node: TreeNode<ViewModel>) => boolean) {
|
||||
public updateWithConnection(
|
||||
emitter: EventBusInterface,
|
||||
connectionId: string,
|
||||
nodeFilter?: (node: TreeNode<ViewModel>) => boolean
|
||||
) {
|
||||
this.updateSource = emitter
|
||||
this.connectionId = connectionId
|
||||
this.nodeFilter = nodeFilter
|
||||
@@ -49,7 +48,7 @@ export class Tree<ViewModel extends Destroyable> extends TreeNode<ViewModel> {
|
||||
}
|
||||
|
||||
public applyUnmergedChanges() {
|
||||
this.unmergedMessages.popAll().forEach((msg) => {
|
||||
this.unmergedMessages.popAll().forEach(msg => {
|
||||
const edges = msg.topic.split('/')
|
||||
const node = TreeNodeFactory.fromEdgesAndValue<ViewModel>(edges, msg.payload)
|
||||
node.mqttMessage = msg
|
||||
|
||||
@@ -8,7 +8,7 @@ export class TreeNode<ViewModel extends Destroyable> {
|
||||
public mqttMessage?: MqttMessage
|
||||
public messageHistory: MessageHistory = new RingBuffer<Message>(20000, 100)
|
||||
public viewModel?: ViewModel
|
||||
public edges: {[s: string]: Edge<ViewModel>} = {}
|
||||
public edges: { [s: string]: Edge<ViewModel> } = {}
|
||||
public edgeArray: Array<Edge<ViewModel>> = []
|
||||
public collapsed = false
|
||||
public messages: number = 0
|
||||
@@ -52,7 +52,7 @@ export class TreeNode<ViewModel extends Destroyable> {
|
||||
}
|
||||
|
||||
private isTopicEmptyLeaf() {
|
||||
const hasNoMessage = (!this.message || !this.message.value || this.message.value.length === 0)
|
||||
const hasNoMessage = !this.message || !this.message.value || this.message.value.length === 0
|
||||
return hasNoMessage && this.isLeaf()
|
||||
}
|
||||
|
||||
@@ -135,7 +135,7 @@ export class TreeNode<ViewModel extends Destroyable> {
|
||||
}
|
||||
|
||||
public hash(): string {
|
||||
return `N${(this.sourceEdge ? this.sourceEdge.hash() : '')}`
|
||||
return `N${this.sourceEdge ? this.sourceEdge.hash() : ''}`
|
||||
}
|
||||
|
||||
public firstNode(): TreeNode<ViewModel> {
|
||||
@@ -145,7 +145,7 @@ export class TreeNode<ViewModel extends Destroyable> {
|
||||
public path(): string {
|
||||
if (!this.cachedPath) {
|
||||
return this.branch()
|
||||
.map(node => (node.sourceEdge && node.sourceEdge.name))
|
||||
.map(node => node.sourceEdge && node.sourceEdge.name)
|
||||
.filter(name => name !== undefined)
|
||||
.join('/')
|
||||
}
|
||||
@@ -199,9 +199,8 @@ export class TreeNode<ViewModel extends Destroyable> {
|
||||
|
||||
public leafMessageCount(): number {
|
||||
if (this.cachedLeafMessageCount === undefined) {
|
||||
this.cachedLeafMessageCount = this.edgeArray
|
||||
.map(edge => edge.target.leafMessageCount())
|
||||
.reduce((a, b) => a + b, 0) + this.messages
|
||||
this.cachedLeafMessageCount =
|
||||
this.edgeArray.map(edge => edge.target.leafMessageCount()).reduce((a, b) => a + b, 0) + this.messages
|
||||
}
|
||||
|
||||
return this.cachedLeafMessageCount as number
|
||||
|
||||
@@ -4,7 +4,10 @@ import { Edge, Tree, TreeNode } from './'
|
||||
|
||||
export abstract class TreeNodeFactory {
|
||||
private static messageCounter = 0
|
||||
public static insertNodeAtPosition<ViewModel extends Destroyable>(edgeNames: Array<string>, node: TreeNode<ViewModel>) {
|
||||
public static insertNodeAtPosition<ViewModel extends Destroyable>(
|
||||
edgeNames: Array<string>,
|
||||
node: TreeNode<ViewModel>
|
||||
) {
|
||||
let currentNode: TreeNode<ViewModel> = new Tree()
|
||||
let edge
|
||||
for (const edgeName of edgeNames) {
|
||||
@@ -17,7 +20,10 @@ export abstract class TreeNodeFactory {
|
||||
node.sourceEdge!.target = node
|
||||
}
|
||||
|
||||
public static fromEdgesAndValue<ViewModel extends Destroyable>(edgeNames: Array<string>, value?: Base64Message | null): TreeNode<ViewModel> {
|
||||
public static fromEdgesAndValue<ViewModel extends Destroyable>(
|
||||
edgeNames: Array<string>,
|
||||
value?: Base64Message | null
|
||||
): TreeNode<ViewModel> {
|
||||
const node = new TreeNode<ViewModel>()
|
||||
node.setMessage({
|
||||
value: value || undefined,
|
||||
|
||||
@@ -42,7 +42,7 @@ describe('Edge', () => {
|
||||
const topics2 = 'foo/foo/baz'.split('/')
|
||||
const bazEdge2 = TreeNodeFactory.fromEdgesAndValue(topics2, undefined).sourceEdge
|
||||
|
||||
if (!bazEdge1 || !bazEdge2) {
|
||||
if (!bazEdge1 || !bazEdge2) {
|
||||
throw Error('should not happen')
|
||||
}
|
||||
|
||||
|
||||
@@ -8,8 +8,8 @@ describe('EventDispatcher', async () => {
|
||||
this.timeout(300)
|
||||
|
||||
setTimeout(() => dispatcher.dispatch('hello'), 5)
|
||||
const response = await new Promise((resolve) => {
|
||||
dispatcher.subscribe((msg) => {
|
||||
const response = await new Promise(resolve => {
|
||||
dispatcher.subscribe(msg => {
|
||||
resolve(msg)
|
||||
})
|
||||
})
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
import 'mocha'
|
||||
|
||||
import { TreeNodeFactory } from '../'
|
||||
import { TreeNodeFactory } from '../'
|
||||
import { expect } from 'chai'
|
||||
import { Base64Message } from '../Base64Message';
|
||||
import { Base64Message } from '../Base64Message'
|
||||
|
||||
describe('TreeNode', () => {
|
||||
const number3 = Base64Message.fromString("3")
|
||||
const number5 = Base64Message.fromString("5")
|
||||
const number3 = Base64Message.fromString('3')
|
||||
const number5 = Base64Message.fromString('5')
|
||||
it('firstNode should retrieve first node', () => {
|
||||
const topics = 'foo/bar'.split('/')
|
||||
const leaf = TreeNodeFactory.fromEdgesAndValue(topics, undefined)
|
||||
|
||||
@@ -2,7 +2,7 @@ import 'mocha'
|
||||
|
||||
import { TreeNodeFactory } from '../'
|
||||
import { expect } from 'chai'
|
||||
import { Base64Message } from '../Base64Message';
|
||||
import { Base64Message } from '../Base64Message'
|
||||
|
||||
describe('TreeNodeFactory', () => {
|
||||
it('root node must not have a sourceEdge', () => {
|
||||
@@ -45,7 +45,7 @@ describe('TreeNodeFactory', () => {
|
||||
expect(node.sourceEdge.name).to.eq('baz')
|
||||
|
||||
const barNode = node.sourceEdge.source
|
||||
if (!barNode || !barNode.sourceEdge) {
|
||||
if (!barNode || !barNode.sourceEdge) {
|
||||
expect.fail('should not fail')
|
||||
return
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user