import {state, StateStream} from "lstream/index"; export class LazyStreams { index = new Map>(); proto: (id: string) => T; constructor(proto?: (id: string) => T) { this.proto = proto || ((id: string) => null); } get(id: string) { let state$: StateStream = this.index[id]; if (state$ == null) { state$ = state(this.proto(id)); this.index[id] = state$; } return state$; } }