@1771technologies/lytenyte-pro
Version:
Blazingly fast headless React data grid with 100s of features.
25 lines (24 loc) • 970 B
JavaScript
import { ROOT_LEAF_PREFIX } from "./+constants.async-tree.js";
const invalidItemKeyDupes = "Invalid set action items, the same 'key' appears more than once";
const invalidItemPathsDupes = "Invalid set action items, the same 'path' appears more than once";
export function checkSetActionItemKeysAreUnique(p) {
const seenKeys = new Set();
const seenPaths = new Set();
if (!p.items?.length)
return true;
for (let i = p.items.length - 1; i >= 0; i--) {
const item = p.items[i];
if (seenKeys.has(item.relIndex)) {
console.error(invalidItemKeyDupes, p);
return false;
}
const pathId = item.kind === "leaf" ? `${p.path.at(-1) ?? ROOT_LEAF_PREFIX}#${item.relIndex}` : item.path;
if (seenPaths.has(pathId)) {
console.error(invalidItemPathsDupes, p);
return false;
}
seenPaths.add(pathId);
seenKeys.add(item.relIndex);
}
return true;
}