/
githubmirror
/
gutenberg
Обзор
Документация
Войти
/
githubmirror
/
gutenberg
Код
Запросы
0
Пакеты
0
Релизы
0
Аналитика
Безопасность
trunk
packages/sync/src/providers/index.ts
59 строк
2 KB
Marco Ciampini
ESLint: Replace strict config with bulk suppressions (#81248)
07 авг 2026, 14:34
Не верифицирован
07 авг 2026, 14:34
7f43eaf
Код
Авторство
О чём код?
import { applyFilters } from '@wordpress/hooks'; import { createHttpPollingProvider } from './http-polling/http-polling-provider'; import type { ProviderCreator } from '../types'; let providerCreators: ProviderCreator[] | null = null; /** * Returns the defeault provider creators. HTTP polling is the current default * provider. * * @return {ProviderCreator[]} Creator functions for Yjs providers. */ export function getDefaultProviderCreators(): ProviderCreator[] { return [ createHttpPollingProvider() ]; } /** * Type guard to ensure filter return values are functions. * * @param {unknown} creator * @return {boolean} Whether the argument is a function */ function isProviderCreator( creator: unknown ): creator is ProviderCreator { return 'function' === typeof creator; } /** * Get the current Yjs provider creators, allowing plugins to filter the array. * * @return {ProviderCreator[]} Creator functions for Yjs providers. */ export function getProviderCreators(): ProviderCreator[] { if ( providerCreators ) { return providerCreators; } // Check if real-time collaboration is enabled via WordPress setting. if ( ! window._wpCollaborationEnabled ) { return []; } /** * Filter the available provider creators. */ const filteredProviderCreators: unknown = applyFilters( 'sync.providers', getDefaultProviderCreators() ); // If the returned value is not an array, ignore and set to empty array. if ( ! Array.isArray( filteredProviderCreators ) ) { providerCreators = []; return providerCreators; } providerCreators = filteredProviderCreators.filter( isProviderCreator ); return providerCreators; }