resolve(route: ActivatedRouteSnapshot, state: RouterStateSnapshot): Observable<ICartaoCredito> { const id = route.params['id'] ? route.params['id'] : null; if (id) { return this.service.find(id).pipe( filter((response: HttpResponse<CartaoCredito>) => response.ok), map((cartaoCredito: HttpResponse<CartaoCredito>) => cartaoCredito.body) ); } return of(new CartaoCredito()); }
async allocate(binderOpts: BinderOptions): Promise<ServerConfig> { let original = this.get(binderOpts); switch (original.type) { case UP: // cache hit with an UP server, check if it's really up const isUp = await this.checkUp(original); if (isUp) { // It is so we can plow forward return original.config; } // Otherwise we need to make a new server break; case NOHOST: // Definitely need to launch break; case PROVISIONING: // Wait for the provisioning server to get up while (original.type !== UP) { await sleep(1000); // NOTE: Could do coordination here by recording timestamps in the PROVISIONING type // At the very least there should come a point we time out at original = this.get(binderOpts); } if (original && original.type === UP) { return original.config; } } const host = await binder(binderOpts) .pipe( tap(x => { // Log binder messages to the console for debuggability console.log("%c BINDER MESSAGE", "color: rgb(87, 154, 202)"); console.log(x); }), filter(msg => msg.phase === "ready"), map(msg => makeHost({ endpoint: msg.url, token: msg.token })) ) .toPromise(); if ( !host.config || !host.config.endpoint || !host.config.token || !host.config.crossDomain ) { throw new Error(`Bad host created: ${JSON.stringify(host, null, 2)}`); } this.set(binderOpts, host); return host.config; }
ngOnInit() { const end$ = this.router.events.pipe( filter(e => e instanceof NavigationEnd || e instanceof NavigationCancel || e instanceof NavigationError) ); this.progress$ = this.router.events.pipe( filter(e => e instanceof NavigationStart), // trigger the emission when a navigation starts switchMap(() => merge( // then emit every 500ms, and when the navigation ends or cancels or errors. This delay must // match the transition duration in the .scss file timer(0, 500).pipe( map(i => 100 - (100 / Math.pow(2, i))), // emit 0 then 50, 75, 87.5, etc. takeWhile(i => i < 99.95), // stop because that just triggers change detection with no visual change anymore takeUntil(end$), // but stop emitting every 500ms when the navigation ends or cancels or errors map(i => ({ value: i })) ), end$.pipe(first(), map(() => null)) // set back to null when the navigation ends or cancels or errors to hide // the progress bar )) ); }
watchForRawEvents(logger: RawEventLogger, topicFilter: string, topicPrefix: string) { this.communicationManager .observeRaw(this.identity, topicFilter) // Note that all published raw messages are dispatched on all raw observables! .pipe(filter(([topic]) => topic.startsWith(topicPrefix))) .subscribe(([topic, payload]) => { logger.count++; // Raw values are emitted as tuples of topic name and Uint8Array/Buffer payload logger.eventData.push([topic, payload.toString()]); }); }
checkStore(panelId: number, boardId: number): Observable<boolean> { return this.store.select(fromStore.getBoardLoaded).pipe( tap(loaded => { if (!loaded || !this.hasBoardInStore(boardId)) { this.store.dispatch(new fromStore.LoadBoard({ panelId, boardId })); } }), filter(loaded => loaded), take(1) ); }
checkStore(): Observable<boolean>{ return this.store.select(fromStore.getPizzasLoaded).pipe( tap(loaded => { if(!loaded){ this.store.dispatch(new fromStore.LoadPizzas()); } }), filter(loaded => loaded), take(1) ) }
/** A helper function to get descendants recursively. */ protected _getDescendants(descendants: T[], dataNode: T): void { descendants.push(dataNode); const childrenNodes = this.getChildren(dataNode); if (Array.isArray(childrenNodes)) { childrenNodes.forEach((child: T) => this._getDescendants(descendants, child)); } else if (childrenNodes instanceof Observable) { childrenNodes.pipe(take(1), filter(Boolean)).subscribe(children => { children.forEach((child: T) => this._getDescendants(descendants, child)); }); } }
private _observeDiscoverIdentity() { this._discoverIdentitySubscription = this.communicationManager.observeDiscover(this.identity) .pipe(filter(event => (event.eventData.isDiscoveringTypes && event.eventData.isCoreTypeCompatible("Component")) || (event.eventData.isDiscoveringObjectId && event.eventData.objectId === this.identity.objectId))) .subscribe(event => event.resolve(ResolveEvent.withObject(this.identity, this.identity))); }
function factory( observable: Observable<SubjectPayload<string, any, any>>, initialState: number, ) { return { view: observable.pipe( filter(args => args.type === 'test'), mapTo(1), ), }; }
checkStore(): Observable<boolean> { return this.store.select(getUserLoaded).pipe( tap(loaded => { if (!loaded) { this.store.dispatch(new LoadUsers()); } }), filter(loaded => loaded), take(1) ); }