-
Notifications
You must be signed in to change notification settings - Fork 24.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Remove dependence on VirtualizedList
listKey
prop
Summary: Following up on the previous diff to remove the only usage of `listKey` for persistent association, we can remove the need for a manual `listKey`, and instead rely on per-instance association via refs. A followup change will remove the existing usages. Changelog: [General][Removed] - Remove VirtualizedList `listKey` prop Reviewed By: p-sun Differential Revision: D39466677 fbshipit-source-id: 6b49f45c987fff9836918ba833fbb16f24414ff8
- Loading branch information
1 parent
c5217f1
commit 010da67
Showing
6 changed files
with
129 additions
and
324 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
/** | ||
* Copyright (c) Meta Platforms, Inc. and affiliates. | ||
* | ||
* This source code is licensed under the MIT license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
* | ||
* @flow strict | ||
* @format | ||
*/ | ||
|
||
import invariant from 'invariant'; | ||
|
||
export default class ChildListCollection<TList> { | ||
_cellKeyToChildren: Map<string, Set<TList>> = new Map(); | ||
_childrenToCellKey: Map<TList, string> = new Map(); | ||
|
||
add(list: TList, cellKey: string): void { | ||
invariant( | ||
!this._childrenToCellKey.has(list), | ||
'Trying to add already present child list', | ||
); | ||
|
||
const cellLists = this._cellKeyToChildren.get(cellKey) ?? new Set(); | ||
cellLists.add(list); | ||
this._cellKeyToChildren.set(cellKey, cellLists); | ||
|
||
this._childrenToCellKey.set(list, cellKey); | ||
} | ||
|
||
remove(list: TList): void { | ||
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); | ||
|
||
if (cellLists.size === 0) { | ||
this._cellKeyToChildren.delete(cellKey); | ||
} | ||
} | ||
|
||
forEach(fn: TList => void): void { | ||
for (const listSet of this._cellKeyToChildren.values()) { | ||
for (const list of listSet) { | ||
fn(list); | ||
} | ||
} | ||
} | ||
|
||
forEachInCell(cellKey: string, fn: TList => void): void { | ||
const listSet = this._cellKeyToChildren.get(cellKey) ?? []; | ||
for (const list of listSet) { | ||
fn(list); | ||
} | ||
} | ||
|
||
anyInCell(cellKey: string, fn: TList => boolean): boolean { | ||
const listSet = this._cellKeyToChildren.get(cellKey) ?? []; | ||
for (const list of listSet) { | ||
if (fn(list)) { | ||
return true; | ||
} | ||
} | ||
return false; | ||
} | ||
|
||
size(): number { | ||
return this._childrenToCellKey.size; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.