let get = (cmd: Command): Observable => { let page: Observable = Repo.get(options(cmd)) let found: Observable = from(page) .filter(byStatus(200)) .pluck('response') .map(toPage) let error: Observable = from(page) .filter(not(byStatus(200))) .map(toError) return concat.apply(found, [error]) }
export function initNativeHandlers(contentRef: ContentRef, store: *) { const state$ = from(store).pipe(share()); return createTitleFeed(contentRef, state$).subscribe( setTitleFromAttributes, err => console.error(err) ); }
switchMap(tests => { return from(tests).pipe( map(({ message }) => message), filter(overEvery(isString, Boolean)), map(updateConsole), concat(of(updateTests(tests))) ); }),
it("handles both the legacy and current arguments for ofMessageType", () => { from([ { header: { msg_type: "a" } }, { header: { msg_type: "d" } }, { header: { msg_type: "b" } }, { header: { msg_type: "a" } }, { header: { msg_type: "d" } } ]) .pipe( ofMessageType(["a", "d"]), tap(val => { expect(val.header.msg_type === "a" || val.header.msg_type === "d"); }), pluck("header", "msg_type"), count() ) .toPromise() .then(val => { expect(val).toEqual(4); }); from([ { header: { msg_type: "a" } }, { header: { msg_type: "d" } }, { header: { msg_type: "b" } }, { header: { msg_type: "a" } }, { header: { msg_type: "d" } } ]) .pipe( // Note the lack of array brackets on the arguments ofMessageType("a", "d"), tap(val => { expect(val.header.msg_type === "a" || val.header.msg_type === "d"); }), pluck("header", "msg_type"), count() ) .toPromise() .then(val => { expect(val).toEqual(4); }); });
return andObservables(map.call(from(canActivateChildGuards), function (d) { var obs = map.call(from(d.guards), function (c) { var guard = _this.getToken(c, c.node); if (guard.canActivateChild) { return wrapIntoObservable(guard.canActivateChild(future, _this.future)); } else { return wrapIntoObservable(guard(future, _this.future)); } }); return andObservables(obs); }));
var runningChecks$ = map.call(checks$, function (s) { if (s instanceof CanActivate) { return andObservables(from([_this.runCanActivateChild(s.path), _this.runCanActivate(s.route)])); } else if (s instanceof CanDeactivate) { // workaround https://github.com/Microsoft/TypeScript/issues/7271 var s2 = s; return _this.runCanDeactivate(s2.component, s2.route); } else { throw new Error('Cannot be reached'); } });
function runGuards(injector, route) { var canLoad = route.canLoad; if (!canLoad || canLoad.length === 0) return of(true); var obs = map.call(from(canLoad), function (c) { var guard = injector.get(c); if (guard.canLoad) { return wrapIntoObservable(guard.canLoad(route)); } else { return wrapIntoObservable(guard(route)); } }); return andObservables(obs); }
PreActivation.prototype.resolveData = function () { var _this = this; if (this.checks.length === 0) return of(null); var checks$ = from(this.checks); var runningChecks$ = mergeMap.call(checks$, function (s) { if (s instanceof CanActivate) { return _this.runResolve(s.route); } else { return of(null); } }); return reduce.call(runningChecks$, function (_, __) { return _; }); };
PreActivation.prototype.runCanActivate = function (future) { var _this = this; var canActivate = future._routeConfig ? future._routeConfig.canActivate : null; if (!canActivate || canActivate.length === 0) return of(true); var obs = map.call(from(canActivate), function (c) { var guard = _this.getToken(c, future); if (guard.canActivate) { return wrapIntoObservable(guard.canActivate(future, _this.future)); } else { return wrapIntoObservable(guard(future, _this.future)); } }); return andObservables(obs); };
it("filters messages that have the same parent", () => from([ { parent_header: { msg_id: "100" } }, { parent_header: { msg_id: "100" } }, { parent_header: { msg_id: "200" } }, { parent_header: { msg_id: "300" } }, { parent_header: { msg_id: "100" } } ]) .pipe( childOf({ header: { msg_id: "100" } }), count() ) .toPromise() .then(val => { expect(val).toEqual(3); }));
PreActivation.prototype.runCanDeactivate = function (component, curr) { var _this = this; var canDeactivate = curr && curr._routeConfig ? curr._routeConfig.canDeactivate : null; if (!canDeactivate || canDeactivate.length === 0) return of(true); var canDeactivate$ = map.call(from(canDeactivate), function (c) { var guard = _this.getToken(c, curr); if (guard.canDeactivate) { return wrapIntoObservable(guard.canDeactivate(component, curr, _this.curr)); } else { return wrapIntoObservable(guard(component, curr, _this.curr)); } }); var merged$ = mergeAll.call(canDeactivate$); return every.call(merged$, function (result) { return result === true; }); };
it("throws an error in msg_type is not present", done => from([ { header: { msg_type_invalid: "a" } }, { header: { msg_type_invalid: "d" } }, { header: {} }, { header: { msg_type: "a" } } ]) .pipe(ofMessageType(["a", "d"])) .subscribe( () => { throw new Error("Subscription was unexpectedly fulfilled."); }, error => { expect(error).not.toBe(null); done(); } ));
it.skip("throws an error if msg_id is not present", done => from([ { parent_header: { msg_id_bad: "100" } }, { parent_header: { msg_id_test: "100" } }, { parent_header: { msg_id_invalid: "200" } }, { parent_header: { msg_id_invalid: "300" } } ]) .pipe(childOf({ header: { msg_id: "100" } })) .subscribe( () => { throw new Error("Subscription was unexpectedly fulfilled."); }, error => { expect(error).not.toBe(null); done(); } ));
RouterPreloader.prototype.processRoutes = function (injector, routes) { var /** @type {?} */ res = []; for (var _i = 0, routes_1 = routes; _i < routes_1.length; _i++) { var c = routes_1[_i]; // we already have the config loaded, just recurce if (c.loadChildren && !c.canLoad && ((c))._loadedConfig) { var /** @type {?} */ childConfig = ((c))._loadedConfig; res.push(this.processRoutes(childConfig.injector, childConfig.routes)); } else if (c.loadChildren && !c.canLoad) { res.push(this.preloadConfig(injector, c)); } else if (c.children) { res.push(this.processRoutes(injector, c.children)); } } return mergeAll.call(from(res)); };
mergeMap(message => { const actionsArray = [ actions.addKernelMessage({ serverId, kernelName, message }) ]; switch (message.header.msg_type) { case "status": actionsArray.push( actions.setKernelStatus({ serverId, kernelName, status: message.content.execution_state }) ); break; case "kernel_info_reply": actionsArray.push( actions.setActiveKernelLanguageInfo({ serverId, kernelName, languageInfo: message.content.language_info }) ); break; case "display_data": case "execute_result": case "stream": case "error": actionsArray.push( actions.addKernelOutput({ serverId, kernelName, output: { ...message.content, output_type: message.header.msg_type } }) ); break; default: break; } return from(actionsArray); })
PreActivation.prototype.runCanActivateChild = function (path) { var _this = this; var future = path[path.length - 1]; var canActivateChildGuards = path.slice(0, path.length - 1) .reverse() .map(function (p) { return _this.extractCanActivateChild(p); }) .filter(function (_) { return _ !== null; }); return andObservables(map.call(from(canActivateChildGuards), function (d) { var obs = map.call(from(d.guards), function (c) { var guard = _this.getToken(c, c.node); if (guard.canActivateChild) { return wrapIntoObservable(guard.canActivateChild(future, _this.future)); } else { return wrapIntoObservable(guard(future, _this.future)); } }); return andObservables(obs); })); };
PreActivation.prototype.checkGuards = function () { var _this = this; if (this.checks.length === 0) return of(true); var checks$ = from(this.checks); var runningChecks$ = map.call(checks$, function (s) { if (s instanceof CanActivate) { return andObservables(from([_this.runCanActivateChild(s.path), _this.runCanActivate(s.route)])); } else if (s instanceof CanDeactivate) { // workaround https://github.com/Microsoft/TypeScript/issues/7271 var s2 = s; return _this.runCanDeactivate(s2.component, s2.route); } else { throw new Error('Cannot be reached'); } }); var mergedChecks$ = mergeAll.call(runningChecks$); return every.call(mergedChecks$, function (result) { return result === true; }); };
it("filters messages of type requested", () => { from([ { header: { msg_type: "a" } }, { header: { msg_type: "d" } }, { header: { msg_type: "b" } }, { header: { msg_type: "a" } }, { header: { msg_type: "d" } } ]) .pipe( ofMessageType(["a", "d"]), tap(val => { expect(val.header.msg_type === "a" || val.header.msg_type === "d"); }), pluck("header", "msg_type"), count() ) .toPromise() .then(val => { expect(val).toEqual(4); }); });
return new Observable(function (txnObserver) { var recordSchema = _this._schema.stores[storeName]; var mapper = _this._mapRecord(recordSchema); var txn = db.transaction([storeName], IDB_TXN_READWRITE); var objectStore = txn.objectStore(storeName); var onTxnError = function (err) { return txnObserver.error(err); }; var onTxnComplete = function () { return txnObserver.complete(); }; txn.addEventListener(IDB_COMPLETE, onTxnComplete); txn.addEventListener(IDB_ERROR, onTxnError); var makeRequest = function (record) { return new Observable(function (reqObserver) { var req; if (recordSchema.primaryKey) { req = objectStore[actionType](record); } else { var $key = record['$key']; var $record = Object.assign({}, record); delete $record.key; req = objectStore[actionType]($record, $key); } req.addEventListener(IDB_SUCCESS, function () { var $key = req.result; reqObserver.next(mapper({ $key: $key, record: record })); }); req.addEventListener(IDB_ERROR, function (err) { reqObserver.error(err); }); }); }; var requestSubscriber = mergeMap.call(from(records), makeRequest) .subscribe(txnObserver); return function () { requestSubscriber.unsubscribe(); txn.removeEventListener(IDB_COMPLETE, onTxnComplete); txn.removeEventListener(IDB_ERROR, onTxnError); }; });
test("handles update_display_data messages", done => { const messages = [ // Should be processed { header: { msg_type: "update_display_data" }, content: { data: { "text/html": "<marquee>wee</marquee>" }, transient: { display_id: "1234" } } }, { header: { msg_type: "display_data" }, content: { data: { "text/html": "<marquee>wee</marquee>" }, transient: { display_id: "5555" } } }, // Should not be processed { header: { msg_type: "ignored" }, content: { data: { "text/html": "<marquee>wee</marquee>" } } }, { header: { msg_type: "update_display_data" }, content: { data: { "text/plain": "i am text" }, transient: { display_id: "here" } } } ]; const channels = from(messages); const action$ = ActionsObservable.of({ type: actionTypes.LAUNCH_KERNEL_SUCCESSFUL, payload: { kernel: { channels } } }); const epic = updateDisplayEpic(action$); const responseActions = []; epic.subscribe( action => responseActions.push(action), err => { throw err; }, () => { expect(responseActions).toEqual([ actions.updateDisplay({ content: { data: { "text/html": "<marquee>wee</marquee>" }, transient: { display_id: "1234" } } }), actions.updateDisplay({ content: { data: { "text/plain": "i am text" }, transient: { display_id: "here" } } }) ]); done(); } ); });