@tamagui/react-native-web-lite
Version:
React Native for Web
44 lines (43 loc) • 1.56 kB
JavaScript
import { invariant } from "@tamagui/react-native-web-internals";
class ChildListCollection {
_cellKeyToChildren = /* @__PURE__ */ new Map();
_childrenToCellKey = /* @__PURE__ */ new Map();
add(list, cellKey) {
invariant(
!this._childrenToCellKey.has(list),
"Trying to add already present child list"
);
const cellLists = this._cellKeyToChildren.get(cellKey) ?? /* @__PURE__ */ new Set();
cellLists.add(list), this._cellKeyToChildren.set(cellKey, cellLists), this._childrenToCellKey.set(list, cellKey);
}
remove(list) {
const cellKey = this._childrenToCellKey.get(list);
invariant(cellKey != null, "Trying to remove non-present child list"), this._childrenToCellKey.delete(list);
const cellLists = this._cellKeyToChildren.get(cellKey);
invariant(cellLists, "_cellKeyToChildren should contain cellKey"), cellLists.delete(list), cellLists.size === 0 && this._cellKeyToChildren.delete(cellKey);
}
forEach(fn) {
for (const listSet of this._cellKeyToChildren.values())
for (const list of listSet)
fn(list);
}
forEachInCell(cellKey, fn) {
const listSet = this._cellKeyToChildren.get(cellKey) ?? [];
for (const list of listSet)
fn(list);
}
anyInCell(cellKey, fn) {
const listSet = this._cellKeyToChildren.get(cellKey) ?? [];
for (const list of listSet)
if (fn(list))
return !0;
return !1;
}
size() {
return this._childrenToCellKey.size;
}
}
export {
ChildListCollection as default
};
//# sourceMappingURL=ChildListCollection.js.map