|
|
@@ -15,13 +15,13 @@ import {PrimitiveValue} from "./types";
|
|
|
|
|
|
// This interface is used to de-couple the graph state (in our case, a data structure interpreted by the d3 library, and by the 'Graph' react component), from GraphState.
|
|
|
export interface GraphStateListener {
|
|
|
- createNode(ns: NodeState);
|
|
|
- createValue(vs: ValueState);
|
|
|
- deleteNode(id: PrimitiveValue);
|
|
|
- deleteValue(value: PrimitiveValue);
|
|
|
- createLinkToNode(sourceId: PrimitiveValue, label: string, targetId: PrimitiveValue);
|
|
|
- createLinkToValue(sourceId: PrimitiveValue, label: string, targetValue: PrimitiveValue);
|
|
|
- deleteLink(sourceId: PrimitiveValue, label: string);
|
|
|
+ createNode(ns: NodeState): void;
|
|
|
+ createValue(vs: ValueState): void;
|
|
|
+ deleteNode(id: PrimitiveValue): void;
|
|
|
+ deleteValue(value: PrimitiveValue): void;
|
|
|
+ createLinkToNode(sourceId: PrimitiveValue, label: string, targetId: PrimitiveValue): void;
|
|
|
+ createLinkToValue(sourceId: PrimitiveValue, label: string, targetValue: PrimitiveValue): void;
|
|
|
+ deleteLink(sourceId: PrimitiveValue, label: string): void;
|
|
|
}
|
|
|
|
|
|
// A 'proxy' GraphStateListener that multicasts graph state operations to a bunch of GraphStateListeners.
|
|
|
@@ -101,10 +101,10 @@ abstract class Common {
|
|
|
abstract asTarget(): NodeCreation | PrimitiveValue;
|
|
|
|
|
|
// will notify 'listener'
|
|
|
- abstract createLinkTo(sourceId: PrimitiveValue, label: string, listener: GraphStateListener);
|
|
|
+ abstract createLinkTo(sourceId: PrimitiveValue, label: string, listener: GraphStateListener): void;
|
|
|
|
|
|
// pure
|
|
|
- abstract getDeltasForSetEdge(registry: DeltaRegistry, label: string, target: NodeCreation | PrimitiveValue): EdgeUpdate[];
|
|
|
+ abstract getDeltaForSetEdge(registry: DeltaRegistry, label: string, target: NodeCreation | PrimitiveValue): EdgeUpdate;
|
|
|
abstract getDeltasForDelete(registry: DeltaRegistry): (EdgeUpdate|NodeDeletion)[];
|
|
|
|
|
|
// idempotent - may create some new deltas but does not execute them
|
|
|
@@ -123,7 +123,7 @@ interface ICommon {
|
|
|
// array of (label, NodeState) pairs
|
|
|
getIncomingEdges(): [string, INodeState][];
|
|
|
|
|
|
- getDeltasForSetEdge(registry: DeltaRegistry, label: string, target: NodeCreation | PrimitiveValue): EdgeUpdate[];
|
|
|
+ getDeltaForSetEdge(registry: DeltaRegistry, label: string, target: NodeCreation | PrimitiveValue): EdgeUpdate;
|
|
|
|
|
|
getDeltasForDelete(registry: DeltaRegistry): (EdgeUpdate|NodeDeletion)[];
|
|
|
|
|
|
@@ -190,13 +190,13 @@ class NodeState extends Common implements INodeState {
|
|
|
}
|
|
|
|
|
|
// Has no side effects - instead returns the deltas that capture the creation or update of the given outgoing edge
|
|
|
- getDeltasForSetEdge(registry: DeltaRegistry, label: string, target: NodeCreation | PrimitiveValue): EdgeUpdate[] {
|
|
|
+ getDeltaForSetEdge(registry: DeltaRegistry, label: string, target: NodeCreation | PrimitiveValue): EdgeUpdate {
|
|
|
const previousEdgeUpdate = this.outgoing.get(label);
|
|
|
if (previousEdgeUpdate === undefined) {
|
|
|
- return [registry.newEdgeUpdate(this.creation.createOutgoingEdge(label), target)];
|
|
|
+ return registry.newEdgeUpdate(this.creation.createOutgoingEdge(label), target);
|
|
|
}
|
|
|
else {
|
|
|
- return [registry.newEdgeUpdate(previousEdgeUpdate.overwrite(), target)];
|
|
|
+ return registry.newEdgeUpdate(previousEdgeUpdate.overwrite(), target);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
@@ -271,7 +271,7 @@ class ValueState extends Common implements IValueState {
|
|
|
this.shown = willShow;
|
|
|
}
|
|
|
|
|
|
- getDeltasForSetEdge(registry: DeltaRegistry, label: string, target: NodeCreation | PrimitiveValue): EdgeUpdate[] {
|
|
|
+ getDeltaForSetEdge(registry: DeltaRegistry, label: string, target: NodeCreation | PrimitiveValue): EdgeUpdate {
|
|
|
// A value cannot be the source of an edge, so we return no deltas.
|
|
|
throw new Error("Assertion failed: A value cannot be the source of an edge.")
|
|
|
}
|