UNPKG

@tamagui/react-native-web-lite

Version:
77 lines 2.75 kB
var __defProp = Object.defineProperty; var __getOwnPropDesc = Object.getOwnPropertyDescriptor; var __getOwnPropNames = Object.getOwnPropertyNames; var __hasOwnProp = Object.prototype.hasOwnProperty; var __export = (target, all) => { for (var name in all) __defProp(target, name, { get: all[name], enumerable: true }); }; var __copyProps = (to, from, except, desc) => { if (from && typeof from === "object" || typeof from === "function") { for (let key of __getOwnPropNames(from)) if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable }); } return to; }; var __toCommonJS = mod => __copyProps(__defProp({}, "__esModule", { value: true }), mod); var ChildListCollection_exports = {}; __export(ChildListCollection_exports, { ChildListCollection: () => ChildListCollection, default: () => ChildListCollection_default }); module.exports = __toCommonJS(ChildListCollection_exports); var import_react_native_web_internals = require("@tamagui/react-native-web-internals"); class ChildListCollection { _cellKeyToChildren = /* @__PURE__ */new Map(); _childrenToCellKey = /* @__PURE__ */new Map(); add(list, cellKey) { (0, import_react_native_web_internals.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); (0, import_react_native_web_internals.invariant)(cellKey != null, "Trying to remove non-present child list"); this._childrenToCellKey.delete(list); const cellLists = this._cellKeyToChildren.get(cellKey); (0, import_react_native_web_internals.invariant)(cellLists, "_cellKeyToChildren should contain cellKey"); cellLists.delete(list); if (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 true; } } return false; } size() { return this._childrenToCellKey.size; } } var ChildListCollection_default = ChildListCollection;