@wordpress/core-data
Version:
Access to and manipulation of core WordPress entities.
48 lines (43 loc) • 1.15 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.getPendingLockRequests = getPendingLockRequests;
exports.isLockAvailable = isLockAvailable;
var _utils = require("./utils");
/**
* Internal dependencies
*/
function getPendingLockRequests(state) {
return state.requests;
}
function isLockAvailable(state, store, path, {
exclusive
}) {
const storePath = [store, ...path];
const locks = state.tree;
// Validate all parents and the node itself
for (const node of (0, _utils.iteratePath)(locks, storePath)) {
if ((0, _utils.hasConflictingLock)({
exclusive
}, node.locks)) {
return false;
}
}
// iteratePath terminates early if path is unreachable, let's
// re-fetch the node and check it exists in the tree.
const node = (0, _utils.getNode)(locks, storePath);
if (!node) {
return true;
}
// Validate all nested nodes
for (const descendant of (0, _utils.iterateDescendants)(node)) {
if ((0, _utils.hasConflictingLock)({
exclusive
}, descendant.locks)) {
return false;
}
}
return true;
}
//# sourceMappingURL=selectors.js.map