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


TypeScript operators.startWith函數代碼示例

本文整理匯總了TypeScript中rxjs/operators.startWith函數的典型用法代碼示例。如果您正苦於以下問題:TypeScript startWith函數的具體用法?TypeScript startWith怎麽用?TypeScript startWith使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。


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

示例1: initialize

 public initialize() {
   return {
     view: {
       base: this.intent.test().pipe(
         scan((acc, next: any) => acc + 1, 1),
         share(),
         startWith(1),
       ),
       test: this.intent.test().pipe(
         scan((acc, next: any) => acc + 1, 1),
         share(),
         startWith(1),
       ),
       test2: this.subject.pipe(
         map(({ type, payload, states }) => {
           switch (type) {
             case 'subject-test':
               return payload + states.test2;
             default:
               return payload;
           }
         }),
         startWith(1),
       ),
     },
   };
 }
開發者ID:brn,項目名稱:react-mvi,代碼行數:27,代碼來源:factory.spec.ts

示例2: it

  it('should convert observable obeject to ordinal object', done => {
    const aValue = new Subject();
    const bValue = new Subject();
    const BUFFER_COUNT = 4;

    const values = createObject(
      aValue.pipe(startWith('')),
      bValue.pipe(startWith('')),
    );

    subscription.add(
      combineTemplate(values)
        .pipe(bufferCount(BUFFER_COUNT))
        .subscribe(v => {
          /*tslint:disable:no-magic-numbers*/
          expect(v[0]).to.be.deep.eq(createObject('', ''));
          expect(v[1]).to.be.deep.eq(createObject('200', ''));
          expect(v[2]).to.be.deep.eq(createObject('200', '300'));
          expect(v[3]).to.be.deep.eq(createObject('OK', '300'));
          /*tslint:enable:no-magic-numbers*/
          done();
        }),
    );

    aValue.next('200');
    bValue.next('300');
    aValue.next('OK');
  });
開發者ID:brn,項目名稱:react-mvi,代碼行數:28,代碼來源:combine-template.spec.ts

示例3: getRecentApps

 /**
  * Creates an observable list of recently opened apps
  * @param {number} max
  * @returns {Observable<any[]>}
  */
 getRecentApps(max = 20): Observable<RecentAppTab[]> {
     return combineLatest(
         this.localRepository.getRecentApps().pipe(
             startWith([])
         ),
         this.platformRepository.getRecentApps().pipe(
             map(apps => apps || []),
             startWith([])
         ), (localApps, platformApps) => [...localApps, ...platformApps].sort((a, b) => b.time - a.time).slice(0, max)
     );
 }
開發者ID:hmenager,項目名稱:composer,代碼行數:16,代碼來源:new-file-tab.service.ts

示例4: sampleObservable

export function sampleObservable(obs: Observable<any>, scheduler?: any) {
  return obs.pipe(
    sampleTime(100, scheduler),
    share(),
    startWith('')
  );
}
開發者ID:tjoskar,項目名稱:ng2-lazyload-image,代碼行數:7,代碼來源:scroll-listener.ts

示例5: isErrorLike

 cascade =>
     isErrorLike(cascade.final)
         ? [cascade.final]
         : queryConfiguredExtensions({ queryGraphQL }, cascade).pipe(
               catchError(error => [asError(error) as ErrorLike]),
               startWith(LOADING)
           )
開發者ID:JoYiRis,項目名稱:sourcegraph,代碼行數:7,代碼來源:helpers.ts

示例6: app

 return Object.keys(apps).reduce((states, key) => {
   const app = apps[key];
   const nextState = app(subject, initialState[key]);
   if (nextState.view) {
     if (!isObservable(nextState.view)) {
       throw new Error(`Application view of ${key} must be Observable.`);
     }
     nextState.view = nextState.view.pipe(startWith(initialState[key]));
     if (!states.view) {
       states.view = {};
     }
     if (!isDefined(states.view[key])) {
       states.view[key] = nextState.view;
     } else {
       states.view[key] = merge(states.view[key], nextState.view);
     }
   }
   for (const key in nextState) {
     if (key !== 'view') {
       if (!nextState[key] || !(nextState[key] instanceof Observable)) {
         throw new Error(`Property ${key} must be Observable.`);
       }
       if (states[key]) {
         states[key] = merge(states[key], nextState[key]);
       } else {
         states[key] = nextState[key];
       }
     }
   }
   return states;
 }, states);
開發者ID:brn,項目名稱:react-mvi,代碼行數:31,代碼來源:factory.ts

示例7: addLoadingCount

  function addLoadingCount(count$: Observable<number>) {
    count$
      .pipe(
        distinctUntilChanged(),

        tap(count => {
          if (count < 0) {
            throw new Error(
              'Observables passed to loadingCount.add() must only emit positive numbers'
            );
          }
        }),

        // use takeUntil() so that we can finish each stream on stop() the same way we do when they complete,
        // by removing the previous count from the total
        takeUntil(stop$),
        endWith(0),
        startWith(0),
        pairwise(),
        map(([prev, next]) => next - prev)
      )
      .subscribe({
        next: delta => {
          loadingCount$.next(loadingCount$.getValue() + delta);
        },
        error: error => {
          if (fatalErrors) {
            fatalErrors.add(error);
          }
        },
      });
  }
開發者ID:elastic,項目名稱:kibana,代碼行數:32,代碼來源:http_setup.ts

示例8: ngOnInit

    ngOnInit () {
        this.playlist$ = this._route.paramMap.pipe(
            map(paramMap => ({ playlistId: paramMap.get('id'), playlistOwnerId: paramMap.get('user') })),
            switchMap(params =>
                this._spotifyService.getPlaylist(params.playlistOwnerId, params.playlistId)
            ),
            map(playlist => ({
                isLoading: false,
                result: playlist
            })),
            startWith({
                isLoading: true,
                result: null
            }),
            shareReplay()
        );

        this.tracks$ = this.playlist$.pipe(
            filter(o => !o.isLoading && !!o.result),
            map(o => o.result.Tracks)
        );

        this.playlistUrl$ = this.playlist$.pipe(
            filter(o => !o.isLoading && !!o.result),
            map(o => o.result),
            map(playlist => playlist.ImageUrls.length ? playlist.ImageUrls[0] : '')
        );
    }
開發者ID:Lightw3ight,項目名稱:PlayMeExtension,代碼行數:28,代碼來源:playlist.component.ts

示例9: canExecuteFromNgForm

export function canExecuteFromNgForm(form: AbstractControl | AbstractControlDirective): Observable<boolean> {
	return form.statusChanges!.pipe(
		startWith(form.valid),
		map(() => !!form.valid),
		distinctUntilChanged(),
	);
}
開發者ID:sketch7,項目名稱:ssv-ng2-command,代碼行數:7,代碼來源:command.util.ts

示例10: app

 function app(sources: any): any {
   return {
     other: sources.other.pipe(
       take(1),
       startWith('a')
     ),
   };
 }
開發者ID:,項目名稱:,代碼行數:8,代碼來源:


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