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


TypeScript operators.take函數代碼示例

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


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

示例1: it

  it('file replacements work with forked type checker on watch mode', async () => {
    host.writeMultipleFiles({
      'src/file-replaced.ts': 'export var obj = { one: 1, two: 2 };',
      'src/file.ts': `export var obj = { one: 1 };`,
      'src/main.ts': `
        import { obj } from './file';
        console.log(obj.two);
      `,
    });

    const overrides = {
      fileReplacements: [{
        replace: normalize('/src/file.ts'),
        with: normalize('/src/file-replaced.ts'),
      }],
      watch: true,
    };

    const unexpectedError = `Property 'two' does not exist on type '{ one: number; }'`;
    const expectedError = `Property 'prop' does not exist on type '{}'`;
    const logger = new TestLogger('rebuild-type-errors');

    // Race between a timeout and the expected log entry.
    const stop$ = race<null | string>(
      of(null).pipe(delay(45000 * 2 / 3)),
      logger.pipe(
        filter(entry => entry.message.includes(expectedError)),
        map(entry => entry.message),
        take(1),
      ),
    );

    let errorAdded = false;
    const run = await architect.scheduleTarget(target, overrides, { logger });
    run.output.pipe(
      tap((buildEvent) => expect(buildEvent.success).toBe(true, 'build should succeed')),
      tap(() => {
        // Introduce a known type error to detect in the logger filter.
        if (!errorAdded) {
          host.appendToFile('src/main.ts', 'console.log({}.prop);');
          errorAdded = true;
        }
      }),
      takeUntil(stop$),
    ).subscribe();

    const res = await stop$.toPromise();
    expect(res).not.toBe(null, 'Test timed out.');
    expect(res).not.toContain(unexpectedError);
    await run.stop();
  });
開發者ID:angular,項目名稱:angular-cli,代碼行數:51,代碼來源:replacements_spec_large.ts

示例2: it

 it ('Minimal (implied defaults)', () => {
   const newSetting: UserSettingState = UserSettingUtil.updateUserSettingState(userSettingState, mutable => {
     mutable.boardCode = 'TEST&=123';
   });
   userSettingSubject.next(newSetting);
   urlObservable
     .pipe(
       take(1)
     )
     .subscribe(s => {
       const parsedState = userSettingStateFromQueryString(s);
       expect(parsedState).toEqual(newSetting);
   })
 });
開發者ID:rsvoboda,項目名稱:overbaard-redux,代碼行數:14,代碼來源:board-query-params.service.spec.ts

示例3: resolve

 resolve(route: ActivatedRouteSnapshot, state: RouterStateSnapshot): Observable<Hero> {
     let id = +route.paramMap.get('id')
     return this.heroService.getHero(id).pipe(
         take(1),
         map(hero => {
             if (hero) {
                 return hero;
             } else {
                 this.router.navigate(['heroes']);
                 return null;
             }
         })
     )
 }
開發者ID:chenji336,項目名稱:angular-study,代碼行數:14,代碼來源:hero-detail-resolver.service.ts

示例4: it

    it('should update streaming translations on language change', (done: Function) => {
        translations = {"TEST": "This is a test"};
        translate.use('en');

        translate.stream('TEST').pipe(take(3), toArray()).subscribe((res: string[]) => {
            const expected = ['This is a test', 'Dit is een test', 'This is a test'];
            expect(res).toEqual(expected);
            done();
        });

        translate.setTranslation('nl', {"TEST": "Dit is een test"});
        translate.use('nl');
        translate.use('en');
    });
開發者ID:jupereira0920,項目名稱:core,代碼行數:14,代碼來源:translate.service.spec.ts

示例5: it

 it(`handles function selection on a base path that doesn't exist yet`, () => {
   const nonExistentSubStore = ngRedux.configureSubStore(
     ['sure', 'whatever'],
     (state: any, action: any) => ({ ...state, value: action.newValue })
   );
   nonExistentSubStore
     .select(s => (s ? s.value : s))
     .pipe(take(2), toArray())
     .subscribe(v => expect(v).toEqual([undefined, 'now I exist']));
   nonExistentSubStore.dispatch<AnyAction>({
     type: 'nvm',
     newValue: 'now I exist',
   });
 });
開發者ID:GopinathKaliappan,項目名稱:store,代碼行數:14,代碼來源:sub-store.spec.ts

示例6: test

test('Receive correct message type', t => {
  const service = new MqttService(t.context.mqtt);

  const observer = service.observe('/test/hallo2').pipe(take(1));

  observer.subscribe(value => {
    t.is(value.topic, 'test/hallo2');
    t.is(value.val, 'world');
    t.is(value.retain, false);
  });

  t.context.mqtt.publish('test/hallo2', 'world', { retain: false, qos: 0 });
  return observer;
});
開發者ID:ha4us,項目名稱:ha4us.old,代碼行數:14,代碼來源:mqtt.service.spec.ts

示例7: mergeMap

 mergeMap((aObject: Ha4usObject) => {
   return this.$states.observe(aObject.topic).pipe(
     timeoutWith(100, of({})),
     take(1),
     map((state: Ha4usMessage) => {
       delete state.topic
       delete state.match
       return {
         object: aObject,
         state: state,
       }
     })
   )
 }),
開發者ID:ha4us,項目名稱:ha4us.old,代碼行數:14,代碼來源:stateful-objects.service.ts

示例8: resolve

 resolve(route: ActivatedRouteSnapshot, state: RouterStateSnapshot): Observable<Prestation> {
   const id = route.paramMap.get('id');
   return this.prestationService.getPrestation(id).pipe(
     take(1),
     tap((data) => {
       if (data) {
         return data;
       } else {
         this.router.navigate(['prestations/chart']);
         return null;
       }
     })
   );
 }
開發者ID:ChristopheGueroult,項目名稱:crm-init-bordeaux,代碼行數:14,代碼來源:resolver-prestation.service.ts

示例9: getFilters

 /**
  * Get Filters
  *
  * @returns {Observable<any>}
  */
 getFilters(): any
 {
     return this._store.pipe(
         select(getFiltersLoaded),
         tap(loaded => {
             if ( !loaded )
             {
                 this._store.dispatch(new fromStore.GetFilters([]));
             }
         }),
         filter(loaded => loaded),
         take(1)
     );
 }
開發者ID:karthik12ui,項目名稱:fuse-angular-full,代碼行數:19,代碼來源:resolve.guard.ts

示例10: onSubmit

    onSubmit() {
        const fullPath = `${this.rootFolder}/${this.form.get("folderName").value}`;

        this.dataGateway.createLocalFolder(fullPath).pipe(
            take(1)
        ).subscribeTracked(this, () => {
            this.localFileRepository.reloadPath(this.rootFolder);
            this.modal.close();
        }, err => {
            this.form.setErrors({
                creationFailure: err.message
            })
        });
    }
開發者ID:hmenager,項目名稱:composer,代碼行數:14,代碼來源:create-local-folder-modal.component.ts


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