(index, cache = {})
| 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; |
no test coverage detected