当前位置: 首页>>代码示例>>TypeScript>>正文


TypeScript operators.debounceTime函数代码示例

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