rxjs/operators#delayWhen TypeScript Examples

The following examples show how to use rxjs/operators#delayWhen. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: app.component.ts    From ngrx-issue-tracker with MIT License 6 votes vote down vote up
constructor(private store: Store) {
    this.stats$ = this.store.select(fromIssue.selectStats);
    this.navigationLoading$ = this.store
      .select(fromNavigation.selectLoading)
      .pipe(
        // delay spinner deactivation, so we can see the spinner for a bit
        delayWhen((loading) => interval(loading ? 0 : 500))
      );
  }
Example #2
Source File: watch.ts    From codedoc with MIT License 5 votes vote down vote up
export function watch(
  root: string,
  config: CodedocConfig,
  notifier?: Observable<void>,
) {
  const watchbase = join(root, config.src.base, '/');
  const filechange$ = new Subject<string>();
  const request$ = new Subject<string[] | 'all' | 'queued'>();
  const build$ = new BehaviorSubject<boolean>(false);

  _watch(watchbase, {
    recursive: true,
    filter: (f: string) => (
      config.src.pick.test(f) && !config.src.drop.test(f) ||
      config.src.toc === f.substr(watchbase.length)
    ),
  }, (event, filename) => {
    if (event === 'update')
      filechange$.next(filename.substr(watchbase.length))
  });

  filechange$.pipe(
    tap(filename => {
      if (notifier)
        console.log(chalk`{blue # Changes in {magenta ${join(config.src.base, filename)}} queueing ...}`);
      request$.next('queued');
    }),
    buffer(
      filechange$.pipe(
        debounceTime(500), 
        delayWhen(() => !build$.value ? of(true) : build$.pipe(filter(_ => !_)))
      )
    ),
    filter(chanegs => chanegs.length > 0)
  ).subscribe(changedFiles => {
    if (notifier) {
      build$.next(true);
      console.log(chalk`{gray # Rebuilding due to changes ...}`);
    }
    changedFiles = changedFiles.filter((file, index) => changedFiles.indexOf(file) === index);
    if (changedFiles.includes(config.src.toc)) {
      request$.next('all');
    } else {
      request$.next(changedFiles);
    }

    notifier?.subscribe(() => build$.next(false));
  });

  return request$;
}
Example #3
Source File: artichoke.ts    From closer-sdk.js with MIT License 5 votes vote down vote up
// tslint:disable-next-line: no-any
  private delayReconnect(observable: Observable<any>): Observable<void> {
    return observable.pipe(delayWhen(() => timer(this.getReconnectDelay())));
  }