import { GraphNode , IGraphConsumer , IGraphProducer , IGraphReader , IGraphWriter } from "./types" ; import { GraphShape } from "./graphshape" ; export class Graph < T > extends GraphShape implements IGraphProducer < T > , IGraphReader < T > , IGraphWriter < T > { private readonly nodeToValue : T [ ] = [ ] ; public openGraph ( consumer ) { super . openGraph ( consumer ) ; return this ; } public closeGraph ( consumer ) { super . closeGraph ( consumer ) ; } public getNode ( node ) { return this . nodeToValue [ node ] ; } public setNode ( node , value ) { this . nodeToValue [ node ] = value ; this . invalidateNode ( node ) ; } private invalidateNode ( node ) { this . forEachConsumer ( ( consumer ) => ( consumer as IGraphConsumer ) . nodeChanged ( node , this ) ) ; } }