當前位置: 首頁>>代碼示例>>TypeScript>>正文


TypeScript BehaviorSubject.pipe方法代碼示例

本文整理匯總了TypeScript中rxjs.BehaviorSubject.pipe方法的典型用法代碼示例。如果您正苦於以下問題:TypeScript BehaviorSubject.pipe方法的具體用法?TypeScript BehaviorSubject.pipe怎麽用?TypeScript BehaviorSubject.pipe使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在rxjs.BehaviorSubject的用法示例。


在下文中一共展示了BehaviorSubject.pipe方法的10個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。

示例1: getMovies

 getMovies(start: BehaviorSubject<string>): Observable<any[]> {
   return start.pipe(
     switchMap(startText => {
       const endText = startText + '\uf8ff';
       return this.db
         .list('/movies', ref =>
           ref
             .orderByChild('Title')
             .limitToFirst(10)
             .startAt(startText)
             .endAt(endText)
         )
         .snapshotChanges()
         .pipe(
           debounceTime(200),
           distinctUntilChanged(),
           map(changes => {
             return changes.map(c => {
               return { key: c.payload.key, ...c.payload.val() };
             });
           })
         );
     })
   );
 }
開發者ID:audiBookning,項目名稱:autocomplete-search-angularfirebase2-5-plus,代碼行數:25,代碼來源:movies.service.ts

示例2: it

 it('should handle dynamic queries that return empty sets', async (done) => {
   const ITEMS = 10;
   let count = 0;
   let firstIndex = 0;
   let pricefilter$ = new BehaviorSubject<number|null>(null);
   const randomCollectionName = randomName(afs.firestore);
   const ref = afs.firestore.collection(`${randomCollectionName}`);
   let names = await createRandomStocks(afs.firestore, ref, ITEMS);
   const sub = pricefilter$.pipe(switchMap(price => {
     return afs.collection(randomCollectionName, ref => price ? ref.where('price', '==', price) : ref).valueChanges()
   })).subscribe(data => {
     count = count + 1;
     // the first time should all be 'added'
     if(count === 1) {
       expect(data.length).toEqual(ITEMS);
       pricefilter$.next(-1);
     }
     // on the second round, we should have filtered out everything
     if(count === 2) {
       expect(data.length).toEqual(0);
       sub.unsubscribe();
       deleteThemAll(names, ref).then(done).catch(done.fail);
     }
   });
 });
開發者ID:Tetsumote,項目名稱:angularfire2,代碼行數:25,代碼來源:collection.spec.ts

示例3: constructor

    constructor(
		private http: HttpClient,
		private api: APIService,
	) {
        this.tokenSubject = new BehaviorSubject(localStorage.getItem("token"));

        this.tokenSubject.pipe(
            filter(token => token != localStorage.getItem("token"))
        ).subscribe(token => {
            if (token == "") {
                localStorage.removeItem("token");
            } else {
                localStorage.setItem("token", token);
				localStorage.setItem("token_age", new Date().toString())
            }
        });

		if (!localStorage.getItem("token_age") && localStorage.getItem("token")) {
			localStorage.setItem("token_age", new Date().toString());
		}

		// Renew the token once every 5 days
		this.tokenSubject.pipe(
            switchMap(t => t == "" ? never() : timer(0, 3600000)),
            map(v => new Date(localStorage.getItem("token_age"))),
            filter(date => new Date().getTime() - date.getTime() > 432000000),
            switchMap(
                v => {
                    console.log("Renewing user token");
                    return this.api.rawPost("user/token").pipe(
                        map(r => r.headers.get("Authorization")),
                        filter(token => token != ""),
                        catchError(err => {
                            console.log("Error generating new user token: ", err);
                            return never();
                        }),
                    );
                }
            ),
        ).subscribe(token => this.tokenSubject.next(token));
    }
開發者ID:urandom,項目名稱:readeef,代碼行數:41,代碼來源:auth.ts

示例4:

	// I return the given top-level state key as a stream (will always emit the current
	// key value as the first item in the stream).
	public select<K extends keyof StateType>( key: K ) : Observable<StateType[K]> {

		var selectStream = this.stateSubject.pipe(
			map(
				( state: StateType ) => {

					return( state[ key ] );

				}
			),
			distinctUntilChanged()
		);

		return( selectStream );

	}
開發者ID:bennadel,項目名稱:JavaScript-Demos,代碼行數:18,代碼來源:simple.store.ts

示例5: filter

function getUiMetadata$(): Observable<UIMetadata> {
  if (uiMetadata$ !== null) {
    return uiMetadata$;
  }

  const actionsCompleteError$ = action$.pipe(
    filter(
      uiAction =>
        uiAction.action === UIActions.Completed ||
        uiAction.action === UIActions.Error
    )
  );

  const metadata$ = merge(pollingTimer$, actionsCompleteError$).pipe(
    switchMap(() => queryUIServiceForMetadata()),
    publishReplay(1),
    refCount()
  );
  uiMetadata$ = metadata$;

  return metadata$;
}
開發者ID:dcos,項目名稱:dcos-ui,代碼行數:22,代碼來源:streams.ts

示例6: test

test('stops services if consequent logger upgrade fails', async () => {
  const onShutdown = new BehaviorSubject<string | null>(null);
  const mockOnShutdown = jest.fn(() => {
    onShutdown.next('completed');
    onShutdown.complete();
  });

  const mockLoggingConfig$ = new BehaviorSubject({ someValue: 'foo' });
  mockConfigService.atPath.mockReturnValue(mockLoggingConfig$);

  const root = new Root(config$, env, mockOnShutdown);
  await root.start();

  expect(mockOnShutdown).not.toHaveBeenCalled();
  expect(mockLoggingService.stop).not.toHaveBeenCalled();
  expect(mockServer.stop).not.toHaveBeenCalled();

  const loggingUpgradeError = new Error('logging config consequent upgrade failed');
  mockLoggingService.upgrade.mockImplementation(() => {
    throw loggingUpgradeError;
  });
  mockLoggingConfig$.next({ someValue: 'bar' });

  // Wait for shutdown to be called.
  await onShutdown
    .pipe(
      filter(e => e !== null),
      first()
    )
    .toPromise();

  expect(mockOnShutdown).toHaveBeenCalledTimes(1);
  expect(mockOnShutdown).toHaveBeenCalledWith(loggingUpgradeError);
  expect(mockLoggingService.stop).toHaveBeenCalledTimes(1);
  expect(mockServer.stop).toHaveBeenCalledTimes(1);

  expect(mockConsoleError.mock.calls).toMatchSnapshot();
});
開發者ID:rashidkpc,項目名稱:kibana,代碼行數:38,代碼來源:index.test.ts

示例7: it

 it('should handle dynamic queries that return empty sets', done => {
   const ITEMS = 10;
   let count = 0;
   let firstIndex = 0;
   let namefilter$ = new BehaviorSubject<number|null>(null);
   const aref = createRef(rando());
   aref.set(batch);
   namefilter$.pipe(switchMap(name => {
     const filteredRef = name ? aref.child('name').equalTo(name) : aref
     return snapshotChanges(filteredRef);
   }),take(2)).subscribe(data => {
     count = count + 1;
     // the first time should all be 'added'
     if(count === 1) {
       expect(Object.keys(data).length).toEqual(3);
       namefilter$.next(-1);
     }
     // on the second round, we should have filtered out everything
     if(count === 2) {
       expect(Object.keys(data).length).toEqual(0);
     }
   }).add(done);
 });
開發者ID:Tetsumote,項目名稱:angularfire2,代碼行數:23,代碼來源:snapshot-changes.spec.ts

示例8:

 function getLoadingCount$() {
   return loadingCount$.pipe(distinctUntilChanged());
 }
開發者ID:elastic,項目名稱:kibana,代碼行數:3,代碼來源:http_setup.ts

示例9: subscribe

 public subscribe(next: () => void): sourcegraph.Unsubscribable {
     // Do not emit until the configuration is available.
     return this.data.pipe(filter(data => data !== null)).subscribe(next)
 }
開發者ID:JoYiRis,項目名稱:sourcegraph,代碼行數:4,代碼來源:configuration.ts

示例10: getState

	// ---
	// PUBLIC METHODS.
	// ---

	// I get the current state as a stream (will always emit the current state value as
	// the first item in the stream).
	public getState(): Observable<StateType> {

		return( this.stateSubject.pipe( distinctUntilChanged() ) );

	}
開發者ID:bennadel,項目名稱:JavaScript-Demos,代碼行數:11,代碼來源:simple.store.ts


注:本文中的rxjs.BehaviorSubject.pipe方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。