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


TypeScript ReplaySubject.debounceTime方法代碼示例

本文整理匯總了TypeScript中rxjs/Rx.ReplaySubject.debounceTime方法的典型用法代碼示例。如果您正苦於以下問題:TypeScript ReplaySubject.debounceTime方法的具體用法?TypeScript ReplaySubject.debounceTime怎麽用?TypeScript ReplaySubject.debounceTime使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在rxjs/Rx.ReplaySubject的用法示例。


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

示例1: run


//.........這裏部分代碼省略.........
    });


    // validate documents
    let lastValidated = '';
    let lastDurationSelector: Rx.Subject<number> | undefined;
    const disposeValidationStream = validationRequestStream
        .do(doc => log(`A Validate ${doc.uri}:${doc.version}`))
        .filter(shouldValidateDocument)
        .do(doc => log(`B Validate ${doc.uri}:${doc.version}`))
        .debounce(doc => {
            if (doc.uri !== lastValidated && lastDurationSelector) {
                lastDurationSelector.next(0);
            }
            lastDurationSelector = new Rx.Subject<number>();
            Rx.Observable.timer(activeSettings.spellCheckDelayMs || defaultDebounce).subscribe(lastDurationSelector);
            return lastDurationSelector;
        })
        .do(doc => log(`Validate: ${doc.uri}`))
        .do(() => lastDurationSelector = undefined)
        .subscribe(validateTextDocument);

    // Clear the diagnostics for documents we do not want to validate
    const disposableSkipValidationStream = validationRequestStream
        .filter(doc => !shouldValidateDocument(doc))
        .do(doc => log(`Skip Validate: ${doc.uri}`))
        .subscribe(doc => {
            connection.sendDiagnostics({ uri: doc.uri, diagnostics: [] });
        });

    const disposableTriggerUpdateConfigStream = triggerUpdateConfig
        .do(() => log('Trigger Update Config'))
        .do(() => activeSettingsNeedUpdating = true)
        .debounceTime(100)
        .subscribe(() => {
            updateActiveSettings();
        });

    const disposableTriggerValidateAll = triggerValidateAll
        .debounceTime(250)
        .subscribe(() => {
            log('Validate all documents');
            documents.all().forEach(doc => validationRequestStream.next(doc));
        });

    validationFinishedStream.next({ uri: 'start', version: 0 });

    function shouldValidateDocument(textDocument: TextDocument): boolean {
        const { uri, languageId } = textDocument;
        return !!getActiveSettings().enabled && isLanguageEnabled(languageId)
            && !isUriExcluded(uri);
    }

    function isLanguageEnabled(languageId: string) {
        const { enabledLanguageIds = []} = getActiveSettings();
        return enabledLanguageIds.indexOf(languageId) >= 0;
    }

    function isUriExcluded(uri: string) {
        return fnFileExclusionTest(uri);
    }

    function getBaseSettings() {
        return {...CSpell.mergeSettings(defaultSettings, getActiveSettings()), enabledLanguageIds: getActiveSettings().enabledLanguageIds};
    }
開發者ID:AlekSi,項目名稱:vscode-spell-checker,代碼行數:66,代碼來源:server.ts


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