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

TypeScript operators.debounceTime函数代码示例

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

本文整理汇总了TypeScript中rxjs/operators.debounceTime函数的典型用法代码示例。如果您正苦于以下问题:TypeScript debounceTime函数的具体用法?TypeScript debounceTime怎么用?TypeScript debounceTime使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了debounceTime函数的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的TypeScript代码示例。

示例1: ngOnInit

  ngOnInit() {
    this.form = this.fb.group({
      honoraries: this.initHonoraries()
    });

    this.form.valueChanges.pipe(
      debounceTime(500),
      distinctUntilChanged()
    ).subscribe((changes: {
      honoraries: {
        honoraryDate: any;
        honoraryArticle: string;
      }[];
    }) => {
      changes.honoraries.forEach((honorary: {
        honoraryDate: any;
        honoraryArticle: string;
      }) => {
        if (honorary.honoraryArticle && honorary.honoraryDate) {
          const idx = changes.honoraries.indexOf(honorary);
          this.members[idx].honoraryArticle = honorary.honoraryArticle;
          this.members[idx].honoraryDate = honorary.honoraryDate;
          this.memberService.updateMember(this.members[idx]).then(
            () => this.alertService.showSnackBar('success', 'general.applications.updateMessage'),
            (error: any) => this.alertService.showSnackBar('error', error.message));
        }
      });
    });
  }
开发者ID:Meistercoach83,项目名称:sfw,代码行数:29,代码来源:club-honorary-table.component.ts


示例2: it

  it('works', async () => {
    const overrides = { watch: true, poll: 10000 };
    const intervals: number[] = [];
    let startTime: number | undefined;

    const run = await architect.scheduleTarget(target, overrides);
    await run.output.pipe(
      // Debounce 1s, otherwise changes are too close together and polling doesn't work.
      debounceTime(1000),
      tap((buildEvent) => {
        expect(buildEvent.success).toBe(true);
        if (startTime != undefined) {
          intervals.push(Date.now() - startTime - 1000);
        }
        startTime = Date.now();
        host.appendToFile('src/main.ts', 'console.log(1);');
      }),
      take(4),
    ).toPromise();

    intervals.sort();
    const median = intervals[Math.trunc(intervals.length / 2)];
    expect(median).toBeGreaterThan(3000);
    expect(median).toBeLessThan(12000);
  });
开发者ID:angular,项目名称:angular-cli,代码行数:25,代码来源:poll_spec_large.ts


示例3: it

  it('rebuilds after errors in AOT', (done) => {
    // Save the original contents of `./src/app/app.component.ts`.
    const origContent = virtualFs.fileBufferToString(
      host.scopedSync().read(normalize('src/app/app.component.ts')));
    // Add a major static analysis error on a non-main file to the initial build.
    host.replaceInFile('./src/app/app.component.ts', `'app-root'`, `(() => 'app-root')()`);

    const overrides = { watch: true, aot: true };
    const logger = new TestLogger('rebuild-aot-errors');
    const staticAnalysisError = 'Function expressions are not supported in decorators';
    const syntaxError = 'Declaration or statement expected.';
    let buildNumber = 0;

    runTargetSpec(host, browserTargetSpec, overrides, DefaultTimeout * 3, logger).pipe(
      debounceTime(1000),
      tap((buildEvent) => {
        buildNumber += 1;
        switch (buildNumber) {
          case 1:
            // The first build should error out with a static analysis error.
            expect(buildEvent.success).toBe(false);
            expect(logger.includes(staticAnalysisError)).toBe(true);
            logger.clear();
            // Fix the static analysis error.
            host.writeMultipleFiles({ 'src/app/app.component.ts': origContent });
            break;

          case 2:
            expect(buildEvent.success).toBe(true);
            // Add an syntax error to a non-main file.
            host.appendToFile('src/app/app.component.ts', `]]]`);
            break;

          case 3:
            // The third build should have TS syntax error.
            expect(buildEvent.success).toBe(false);
            expect(logger.includes(syntaxError)).toBe(true);
            logger.clear();
            // Fix the syntax error, but add the static analysis error again.
            host.writeMultipleFiles({
              'src/app/app.component.ts': origContent.replace(`'app-root'`, `(() => 'app-root')()`),
            });
            break;

          case 4:
            expect(buildEvent.success).toBe(false);
            // Restore the file to a error-less state.
            host.writeMultipleFiles({ 'src/app/app.component.ts': origContent });
            break;

          case 5:
            // The fifth build should have everything fixed..
            expect(buildEvent.success).toBe(true);
            expect(logger.includes(staticAnalysisError)).toBe(true);
            break;
        }
      }),
      take(5),
    ).toPromise().then(done, done.fail);
  });
开发者ID:DevIntent,项目名称:angular-cli,代码行数:60,代码来源:rebuild_spec_large.ts


示例4: constructor

  constructor(private state: StateService){
    this.searchInput = new FormControl('');

    this.searchInput.valueChanges
      .pipe(debounceTime(300))
      .subscribe(searchValue => this.state.searchCriteria = searchValue);
  }
开发者ID:yfain,项目名称:observables,代码行数:7,代码来源:search.component.ts


示例5: it

  it('type checks on rebuilds', async () => {
    host.writeMultipleFiles({
      'src/funky2.ts': `export const funky2 = (value: string) => value + 'hello';`,
      'src/funky.ts': `export * from './funky2';`,
    });
    host.appendToFile('src/main.ts', `
      import { funky2 } from './funky';
      console.log(funky2('town'));
    `);

    const overrides = { watch: true, forkTypeChecker: false };
    const logger = new TestLogger('rebuild-type-errors');
    const typeError = `is not assignable to parameter of type 'number'`;
    let buildNumber = 0;

    const run = await architect.scheduleTarget(target, overrides, { logger });
    await run.output.pipe(
      debounceTime(1000),
      tap((buildEvent) => {
        buildNumber += 1;
        switch (buildNumber) {
          case 1:
            expect(buildEvent.success).toBe(true);
            // Make an invalid version of the file.
            // Should trigger a rebuild, this time an error is expected.
            host.writeMultipleFiles({
              'src/funky2.ts': `export const funky2 = (value: number) => value + 1;`,
            });
            break;

          case 2:
            // The second build should error out with a type error on the type of an argument.
            expect(buildEvent.success).toBe(false);
            expect(logger.includes(typeError)).toBe(true);
            logger.clear();
            // Change an UNRELATED file and the error should still happen.
            // Should trigger a rebuild, this time an error is also expected.
            host.appendToFile('src/app/app.module.ts', `console.log(1);`);
            break;

          case 3:
            // The third build should have the same error as the first.
            expect(buildEvent.success).toBe(false);
            expect(logger.includes(typeError)).toBe(true);
            logger.clear();
            // Fix the error.
            host.writeMultipleFiles({
              'src/funky2.ts': `export const funky2 = (value: string) => value + 'hello';`,
            });
            break;

          default:
            expect(buildEvent.success).toBe(true);
            break;
        }
      }),
      take(4),
    ).toPromise();
    await run.stop();
  });
开发者ID:angular,项目名称:angular-cli,代码行数:60,代码来源:rebuild_spec_large.ts


示例6: it

 it('works', (done) => {
   const overrides = { watch: true, poll: 1000 };
   let msAvg = 1000;
   let lastTime: number;
   runTargetSpec(host, browserTargetSpec, overrides).pipe(
     // Debounce 1s, otherwise changes are too close together and polling doesn't work.
     debounceTime(1000),
     tap((buildEvent) => expect(buildEvent.success).toBe(true)),
     tap(() => {
       const currTime = Date.now();
       if (lastTime) {
         const ms = Math.floor((currTime - lastTime));
         msAvg = (msAvg + ms) / 2;
       }
       lastTime = currTime;
       host.appendToFile('src/main.ts', 'console.log(1);');
     }),
     take(5),
   ).subscribe(undefined, done.fail, () => {
     // Check if the average is between 1750 and 2750, allowing for a 1000ms variance.
     expect(msAvg).toBeGreaterThan(1750);
     expect(msAvg).toBeLessThan(2750);
     done();
   });
 });
开发者ID:rexebin,项目名称:angular-cli,代码行数:25,代码来源:poll_spec_large.ts


示例7: ngOnInit

    // -----------------------------------------------------------------------------------------------------
    // @ Lifecycle hooks
    // -----------------------------------------------------------------------------------------------------

    /**
     * On init
     */
    ngOnInit(): void
    {
        this.mails$.subscribe(mails => {
            this.mails = mails;
        });

        this.selectedMailIds$
            .subscribe(selectedMailIds => {
                this.selectedMailIds = selectedMailIds;
                this.hasSelectedMails = selectedMailIds.length > 0;
                this.isIndeterminate = (selectedMailIds.length !== this.mails.length && selectedMailIds.length > 0);
                this.refresh();
            });

        this.searchText$.subscribe(searchText => {
            this.searchInput.setValue(searchText);
        });

        this.searchInput.valueChanges.pipe(
            debounceTime(300),
            distinctUntilChanged()
        ).subscribe(searchText => {
            this._store.dispatch(new fromStore.SetSearchText(searchText));
        });
    }
开发者ID:karthik12ui,项目名称:fuse-angular-full,代码行数:32,代码来源:mail.component.ts


示例8: filter

 .subscribe(doc => {
     if (!validationByDoc.has(doc.uri)) {
         const uri = doc.uri;
         if (isUriBlackListed(uri)) {
             validationByDoc.set(doc.uri, validationRequestStream.pipe(
                 filter(doc => uri === doc.uri),
                 take(1),
                 tap(doc => log('Ignoring:', doc.uri)),
                 ).subscribe()
             );
         } else {
             validationByDoc.set(doc.uri, validationRequestStream.pipe(
                 filter(doc => uri === doc.uri),
                 tap(doc => log('Request Validate:', doc.uri)),
                 debounceTime(50),
                 tap(doc => log('Request Validate 2:', doc.uri)),
                 flatMap(async doc => ({ doc, settings: await getActiveSettings(doc) }) as DocSettingPair),
                 debounce(dsp => timer(dsp.settings.spellCheckDelayMs || defaultDebounce)
                     .pipe(filter(() => !isValidationBusy))
                 ),
                 flatMap(validateTextDocument),
                 ).subscribe(diag => connection.sendDiagnostics(diag))
             );
         }
     }
 });
开发者ID:Jason-Rev,项目名称:vscode-spell-checker,代码行数:26,代码来源:server.ts


示例9: it

  it('should complete when source does not emit', () => {
    const e1 =   hot('-----|');
    const e1subs =   '^    !';
    const expected = '-----|';

    expectObservable(e1.pipe(debounceTime(10, rxTestScheduler))).toBe(expected);
    expectSubscriptions(e1.subscriptions).toBe(e1subs);
  });
开发者ID:DallanQ,项目名称:rxjs,代码行数:8,代码来源:debounceTime-spec.ts



注:本文中的rxjs/operators.debounceTime函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
TypeScript operators.defaultIfEmpty函数代码示例发布时间:2022-05-25
下一篇:
TypeScript operators.debounce函数代码示例发布时间: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