MCPcopy Create free account
hub / github.com/caseywebdev/react-list / getSpaceBefore

Method getSpaceBefore

src/react-list.js:393–416  ·  view source on GitHub ↗
(index, cache = {})

Source from the content-addressed store, hash-verified

391 }
392
393 getSpaceBefore(index, cache = {}) {
394 if (cache[index] != null) return cache[index];
395
396 // Try the static itemSize.
397 const { itemSize, itemsPerRow } = this.state;
398 if (itemSize) {
399 return (cache[index] = Math.floor(index / itemsPerRow) * itemSize);
400 }
401
402 // Find the closest space to index there is a cached value for.
403 let from = index;
404 while (from > 0 && cache[--from] == null);
405
406 // Finally, accumulate sizes of items from - index.
407 let space = cache[from] || 0;
408 for (let i = from; i < index; ++i) {
409 cache[i] = space;
410 const itemSize = this.getSizeOfItem(i);
411 if (itemSize == null) break;
412 space += itemSize;
413 }
414
415 return (cache[index] = space);
416 }
417
418 cacheSizes() {
419 const { cache } = this;

Callers 7

getStartAndEndMethod · 0.95
scrollToMethod · 0.95
scrollAroundMethod · 0.95
getVisibleRangeMethod · 0.95
renderMethod · 0.95
react-list.jsFile · 0.80
index.jsFile · 0.80

Calls 1

getSizeOfItemMethod · 0.95

Tested by

no test coverage detected