• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

TypeScript operators.take函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了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;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
TypeScript operators.takeLast函数代码示例发布时间:2022-05-25
下一篇:
TypeScript operators.switchMapTo函数代码示例发布时间:2022-05-25
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap