MCPcopy
hub / github.com/bvaughn/react-virtualized / createCallbackMemoizer

Function createCallbackMemoizer

source/utils/createCallbackMemoizer.js:4–32  ·  view source on GitHub ↗
(requireAllKeys = true)

Source from the content-addressed store, hash-verified

2 * Helper utility that updates the specified callback whenever any of the specified indices have changed.
3 */
4export default function createCallbackMemoizer(requireAllKeys = true) {
5 let cachedIndices = {};
6
7 return ({callback, indices}) => {
8 const keys = Object.keys(indices);
9 const allInitialized =
10 !requireAllKeys ||
11 keys.every(key => {
12 const value = indices[key];
13 return Array.isArray(value) ? value.length > 0 : value >= 0;
14 });
15 const indexChanged =
16 keys.length !== Object.keys(cachedIndices).length ||
17 keys.some(key => {
18 const cachedValue = cachedIndices[key];
19 const value = indices[key];
20
21 return Array.isArray(value)
22 ? cachedValue.join(',') !== value.join(',')
23 : cachedValue !== value;
24 });
25
26 cachedIndices = indices;
27
28 if (allInitialized && indexChanged) {
29 callback(indices);
30 }
31 };
32}

Callers 5

Grid.jsFile · 0.85
CollectionView.jsFile · 0.85
constructorMethod · 0.85

Calls 1

callbackFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…