@@ -30,6 +30,10 @@ interface HostGraphNode extends CommonGraphNode {
3030 runningPrograms : RunningProgram [ ] ;
3131}
3232
33+ interface SwitchGraphNode extends CommonGraphNode {
34+ type : DeviceType . Switch ;
35+ }
36+
3337// Typescript type guard
3438export function isRouter ( node : GraphNode ) : node is RouterGraphNode {
3539 return node . type === DeviceType . Router ;
@@ -39,9 +43,21 @@ export function isHost(node: GraphNode): node is HostGraphNode {
3943 return node . type === DeviceType . Host ;
4044}
4145
42- export type GraphNode = CommonGraphNode | RouterGraphNode | HostGraphNode ;
46+ export function isSwitch ( node : GraphNode ) : node is SwitchGraphNode {
47+ return node . type === DeviceType . Switch ;
48+ }
49+
50+ export type GraphNode =
51+ | CommonGraphNode
52+ | RouterGraphNode
53+ | HostGraphNode
54+ | SwitchGraphNode ;
4355
44- export type GraphDataNode = CommonDataNode | RouterDataNode | HostDataNode ;
56+ export type GraphDataNode =
57+ | CommonDataNode
58+ | RouterDataNode
59+ | HostDataNode
60+ | SwitchDataNode ;
4561
4662interface CommonDataNode {
4763 id : DeviceId ;
@@ -63,6 +79,10 @@ interface HostDataNode extends CommonDataNode {
6379 runningPrograms : RunningProgram [ ] ;
6480}
6581
82+ interface SwitchDataNode extends CommonDataNode {
83+ type : DeviceType . Switch ;
84+ }
85+
6686export type GraphData = GraphDataNode [ ] ;
6787
6888export interface NewDevice {
@@ -129,6 +149,8 @@ export class DataGraph {
129149 graphData . push ( { ...graphNode , routingTable : info . routingTable } ) ;
130150 } else if ( isHost ( info ) ) {
131151 graphData . push ( { ...graphNode , runningPrograms : info . runningPrograms } ) ;
152+ } else if ( isSwitch ( info ) ) {
153+ graphData . push ( { ...graphNode } ) ;
132154 }
133155 } ) ;
134156 return graphData ;
0 commit comments