本文整理匯總了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));
}
});
});
}
示例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);
});
示例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);
});
示例4: constructor
constructor(private state: StateService){
this.searchInput = new FormControl('');
this.searchInput.valueChanges
.pipe(debounceTime(300))
.subscribe(searchValue => this.state.searchCriteria = searchValue);
}
示例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();
});
示例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();
});
});
示例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));
});
}
示例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))
);
}
}
});
示例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);
});