Skip to content

Commit 5018daa

Browse files
committed
added handling for instance link state change
1 parent 5f6ca5a commit 5018daa

File tree

3 files changed

+14
-8
lines changed

3 files changed

+14
-8
lines changed

client/src/app/api/api/socket.service.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ import {
2626
RegistryEvent
2727
} from '../../model/models/socketMessage';
2828
import {ComponentTypeEnum, Instance, objIsInstance} from '../../model/models/instance';
29-
import {InstanceLink, objIsLink, InstanceLinkPayload} from '../../model/models/instanceLink';
29+
import {objIsLink, InstanceLinkPayload} from '../../model/models/instanceLink';
3030

3131

3232
interface ObserverMap {

client/src/app/model/model.service.ts

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -80,13 +80,16 @@ export class ModelService {
8080
this.storeService.removeFromState(removedInstance);
8181
});
8282
// TODO: after interface changes in ir we will receive a tuple of instances which are now linked
83-
this.socketService.subscribeForEvent<InstanceLinkPayload>(EventTypeEnum.LinkAddedEvent).subscribe((data) => {
83+
this.socketService.subscribeForEvent<InstanceLinkPayload>(EventTypeEnum.LinkAddedEvent).subscribe((data: InstanceLinkPayload) => {
8484
console.log('received link added', data);
85+
this.storeService.changeInstancesState([data.instanceFrom, data.instanceTo]);
8586
});
8687

87-
this.socketService.subscribeForEvent<InstanceLinkPayload>(EventTypeEnum.LinkStateChangedEvent).subscribe((data) => {
88-
console.log('received link state changed', data);
89-
});
88+
this.socketService.subscribeForEvent<InstanceLinkPayload>(EventTypeEnum.LinkStateChangedEvent).
89+
subscribe((data: InstanceLinkPayload) => {
90+
console.log('received link state changed', data);
91+
this.storeService.changeInstancesState([data.instanceFrom, data.instanceTo]);
92+
});
9093
}
9194

9295
/**

client/src/app/model/store.service.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -139,10 +139,13 @@ export class StoreService {
139139
* Updates the given @param instance in the state.
140140
* The update is performed by overwriting the previously stored instance.
141141
*/
142-
public changeInstanceState(instance: Instance) {
143-
const newState = StoreService.addNewInstanceToState(this.stateUpdateSubject.value.state, instance);
142+
public changeInstancesState(instances: Array<Instance>) {
143+
let newState: State;
144+
for (const instance of instances) {
145+
newState = StoreService.addNewInstanceToState(this.stateUpdateSubject.value.state, instance);
146+
}
144147
// maybe calculate diff before
145-
this.stateUpdateSubject.next({state: newState, change: {type: Actions.CHANGE, elements: [instance]}});
148+
this.stateUpdateSubject.next({state: newState, change: {type: Actions.CHANGE, elements: instances}});
146149
}
147150

148151
/**

0 commit comments

Comments
 (0)