observeEvents() { _log.debug(`Adding model with id ${this._modelId} to router`); this.router.addModel(this._modelId, this); this.addDisposable(() => { _log.debug(`Removing model with id ${this._modelId} from router`); this.router.removeModel(this._modelId); }); this.addDisposable(this.router.observeEventsOn(this._modelId, this)); }
return source.materialize().subscribe(i => { switch (i.kind) { case 'N': if(onNext !== null && onNext !== undefined) { router.runAction(modelId, model => onNext(i.value, model)); } break; case 'E': if(onError === null || onError === undefined) { throw i.error; } else { router.runAction(modelId, model => onError(i.error, model)); } break; case 'C': if(onCompleted !== null && onCompleted !== undefined) { router.runAction(modelId, model => onCompleted(model)); } break; default: throw new Error(`Unknown Notification Type. Type was ${i.kind}`); } });
/** * Runs the given action on the dispatch loop for this model, ensures that any model observer will be notified of the change * @param action */ ensureOnDispatchLoop(action:() => void) { // TODO update when https://github.com/esp/esp-js/issues/86 is implemented this.router.runAction(this.modelId, ()=>{ action(); }); }
this.addDisposable(() => { _log.debug(`Removing model with id ${this._modelId} from router`); this.router.removeModel(this._modelId); });
createTileModel(currencyPair:CurrencyPair) { let spotTileModel = new SpotTileModel(currencyPair, this._router, this._pricingService, this._executionService); spotTileModel.observeEvents(); this._router.publishEvent(spotTileModel.modelId, 'init', {}); return spotTileModel; }