How to use the rxjs/operators.switchMap function in rxjs

To help you get started, we’ve selected a few rxjs examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github ReactiveX / rxjs / docs_app / src / app / layout / doc-viewer / doc-viewer.component.ts View on Github external
protected render(doc: DocumentContents): Observable {
    let addTitleAndToc: () => void;

    this.setNoIndex(doc.id === FILE_NOT_FOUND_ID || doc.id === FETCHING_ERROR_ID);

    return this.void$.pipe(
        // Security: `doc.contents` is always authored by the documentation team
        //           and is considered to be safe.
        tap(() => this.nextViewContainer.innerHTML = doc.contents || ''),
        tap(() => addTitleAndToc = this.prepareTitleAndToc(this.nextViewContainer, doc.id)),
        switchMap(() => this.elementsLoader.loadContainedCustomElements(this.nextViewContainer)),
        tap(() => this.docReady.emit()),
        switchMap(() => this.swapViews(addTitleAndToc)),
        tap(() => this.docRendered.emit()),
        catchError(err => {
          const errorMessage = (err instanceof Error) ? err.stack : err;
          this.logger.error(new Error(`[DocViewer] Error preparing document '${doc.id}': ${errorMessage}`));
          this.nextViewContainer.innerHTML = '';
          this.setNoIndex(true);
          return this.void$;
        }),
    );
  }
github sbb-design-systems / sbb-angular / projects / sbb-esta / angular-public / dropdown / src / dropdown-trigger.directive.ts View on Github external
private _subscribeToClosingActions(): Subscription {
    const firstStable = this._zone.onStable.asObservable().pipe(first());
    const optionChanges = this.dropdown.options.changes.pipe(
      tap(() => this._positionStrategy.reapplyLastPosition()),
      // Defer emitting to the stream until the next tick, because changing
      // bindings in here will cause "changed after checked" errors.
      delay(0)
    );

    // When the zone is stable initially, and when the option list changes...
    return (
      merge(firstStable, optionChanges)
        .pipe(
          // create a new stream of panelClosingActions, replacing any previous streams
          // that were created, and flatten it so our stream only emits closing events...
          switchMap(() => {
            this._resetActiveItem();
            this.dropdown.setVisibility();

            if (this.panelOpen) {
              // tslint:disable-next-line:no-non-null-assertion
              this._overlayRef!.updatePosition();
            }

            return this.panelClosingActions;
          }),
          // when the first closing event occurs...
          first()
        )
        // set the value, close the panel, and complete.
        .subscribe(event => this._setValueAndClose(event))
    );
github RackHD / on-web-ui / src / app / canvas-graph / canvas-graph.component.ts View on Github external
callback: innerCreate,
        parentMenu: preMenu,
        allow_html: true
      }, ref_window);

      let taskFilter = new Subject();

      function inputTerm(term: string) {
        taskFilter.next(term);
      }

      bindInput();
      let filterTrigger = taskFilter.pipe(
        debounceTime(1000),
        distinctUntilChanged(),
        switchMap((term: string) => {
          reGenerateMenu(term);
          return 'whatever';
        })
      );
      filterTrigger.subscribe();

      //helpers
      function reGenerateMenu(term: string) {
        // close old task list menu and add a new one;
        taskMenu.close(undefined, true);
        let values = [];
        values.push({content: filterInputHtml});
        let filteredTaskNames = _.filter(self.taskInjectableNames, (type) => {
          return _.toLower(type).includes(_.toLower(term));
        });
        for (let injectableName of filteredTaskNames.slice(0, 9)) {
github SuperblocksHQ / ethereum-studio / src / epics / login / refreshAuth.epic.ts View on Github external
switchMap(() => userService.credentialsExist()
                .pipe(
                    switchMap(() => authService.refreshAuth()
                        .pipe(
                            switchMap((token) => of(authActions.refreshAuthSuccess(token))),
                            catchError((error) => [authActions.refreshAuthFail(error.message)])
                        )
                    )
                )
            )
github Ninja-Squad / globe42 / frontend / src / app / users / users.component.ts View on Github external
delete(user: UserModel) {
    this.confirmService.confirm({message: `Voulez-vous vraiment supprimer l\'utilisateur ${user.login}\u00A0?`}).pipe(
      switchMap(() => this.userService.delete(user.id)),
      switchMap(() => this.userService.list())
    ).subscribe(users => this.users = sortBy(users, u => u.login));
  }
github crafted / crafted / projects / github-dashboard / src / app / repository / store / label / label.effects.ts View on Github external
export class LabelEffects {
  @Effect()
  load = this.actions.pipe(
      ofType(LabelActionTypes.LOAD), switchMap(action => {
        return this.repositoryDatabase.getValues(action.payload.repository)
            .labels.pipe(take(1), map(labels => new LoadLabelsComplete({labels})));
      }));

  /**
   * After the items are loaded from the local database, request updates from GitHub periodically
   * if the user is authenticated.
   */
  @Effect({dispatch: false})
  update = this.actions.pipe(
      ofType(LabelActionTypes.LOAD),
      switchMap(() => this.store.select(selectIsAuthenticated).pipe(take(1))),
      tap(isAuthenticated => {
        if (isAuthenticated) {
          this.updater.update('labels');
        }
      }));

  @Effect({dispatch: false})
  persistGithubUpdatesToLocalDb = this.actions.pipe(
      ofType(LabelActionTypes.UPDATE_FROM_GITHUB),
      withLatestFrom(this.store.select(selectRepositoryName)), tap(([action, repository]) => {
        this.repositoryDatabase.update(repository, 'labels', action.payload.labels);
      }));

  @Effect({dispatch: false})
  persistRemoveAllToLocalDb = this.actions.pipe(
      ofType(LabelActionTypes.REMOVE_ALL),
github Ninja-Squad / globe42 / frontend / src / app / password-change / password-change.component.ts View on Github external
changePassword() {
    this.passwordChangeFailed = false;

    if (this.passwordChangeForm.invalid) {
      return;
    }

    this.currentUserService.checkPassword(this.passwordChangeForm.value.oldPassword).pipe(
      switchMap(() => this.currentUserService.changePassword(this.passwordChangeForm.value.newPassword))
    ).subscribe(
      () => this.router.navigate(['/']),
      () => this.passwordChangeFailed = true
    );
  }
}
github project-flogo / flogo-web / src / client / flogo / flow / debug-panel / debug-panel.component.ts View on Github external
run() {
    this.activity$
      .pipe(
        take(1),
        switchMap(task => this.testRunner.runFromTask({ taskId: task.id, inputs: task.input }))
      ).subscribe();
  }
github SuperblocksHQ / ethereum-studio / src / epics / login / refreshAuth.epic.ts View on Github external
switchMap((authToken: ITokenExpiration) => timer(authToken.nextRefresh * 1000, authToken.refreshInterval * 1000)
        .pipe(
            takeWhile(() => state$.value.auth.isAuthenticated),
            switchMap(() => userService.credentialsExist()
                .pipe(
                    switchMap(() => authService.refreshAuth()
                        .pipe(
                            switchMap((token) => of(authActions.refreshAuthSuccess(token))),
                            catchError((error) => [authActions.refreshAuthFail(error.message)])
                        )
                    )
                )
            )
        )
    ),
github Lumeer / web-ui / src / app / core / home.component.ts View on Github external
private getOrganizations(): Observable {
    return this.store$.select(selectOrganizationsLoaded).pipe(
      tap(loaded => {
        if (!loaded) {
          this.store$.dispatch(new OrganizationsAction.Get());
        }
      }),
      filter(loaded => loaded),
      switchMap(() => this.store$.select(selectAllOrganizations))
    );
  }