/
githubmirror
/
gutenberg
Обзор
Документация
Войти
/
githubmirror
/
gutenberg
Код
Запросы
0
Пакеты
0
Релизы
0
Аналитика
Безопасность
trunk
packages/core-data/src/locks/engine.js
40 строк
1 KB
Marco Ciampini
ESLint: Replace strict config with bulk suppressions (#81248)
07 авг 2026, 14:34
Не верифицирован
07 авг 2026, 14:34
7f43eaf
Код
Авторство
О чём код?
import reducer from './reducer'; import { isLockAvailable, getPendingLockRequests } from './selectors'; export default function createLocks() { let state = reducer( undefined, { type: '@@INIT' } ); function processPendingLockRequests() { for ( const request of getPendingLockRequests( state ) ) { const { store, path, exclusive, notifyAcquired } = request; if ( isLockAvailable( state, store, path, { exclusive } ) ) { const lock = { store, path, exclusive }; state = reducer( state, { type: 'GRANT_LOCK_REQUEST', lock, request, } ); notifyAcquired( lock ); } } } function acquire( store, path, exclusive ) { return new Promise( ( resolve ) => { state = reducer( state, { type: 'ENQUEUE_LOCK_REQUEST', request: { store, path, exclusive, notifyAcquired: resolve }, } ); processPendingLockRequests(); } ); } function release( lock ) { state = reducer( state, { type: 'RELEASE_LOCK', lock, } ); processPendingLockRequests(); } return { acquire, release }; }