({
isRowLoaded,
minimumBatchSize,
rowCount,
startIndex,
stopIndex,
})
| 172 | * Returns all of the ranges within a larger range that contain unloaded rows. |
| 173 | */ |
| 174 | export function scanForUnloadedRanges({ |
| 175 | isRowLoaded, |
| 176 | minimumBatchSize, |
| 177 | rowCount, |
| 178 | startIndex, |
| 179 | stopIndex, |
| 180 | }) { |
| 181 | const unloadedRanges = []; |
| 182 | |
| 183 | let rangeStartIndex = null; |
| 184 | let rangeStopIndex = null; |
| 185 | |
| 186 | for (let index = startIndex; index <= stopIndex; index++) { |
| 187 | let loaded = isRowLoaded({index}); |
| 188 | |
| 189 | if (!loaded) { |
| 190 | rangeStopIndex = index; |
| 191 | if (rangeStartIndex === null) { |
| 192 | rangeStartIndex = index; |
| 193 | } |
| 194 | } else if (rangeStopIndex !== null) { |
| 195 | unloadedRanges.push({ |
| 196 | startIndex: rangeStartIndex, |
| 197 | stopIndex: rangeStopIndex, |
| 198 | }); |
| 199 | |
| 200 | rangeStartIndex = rangeStopIndex = null; |
| 201 | } |
| 202 | } |
| 203 | |
| 204 | // If :rangeStopIndex is not null it means we haven't ran out of unloaded rows. |
| 205 | // Scan forward to try filling our :minimumBatchSize. |
| 206 | if (rangeStopIndex !== null) { |
| 207 | const potentialStopIndex = Math.min( |
| 208 | Math.max(rangeStopIndex, rangeStartIndex + minimumBatchSize - 1), |
| 209 | rowCount - 1, |
| 210 | ); |
| 211 | |
| 212 | for (let index = rangeStopIndex + 1; index <= potentialStopIndex; index++) { |
| 213 | if (!isRowLoaded({index})) { |
| 214 | rangeStopIndex = index; |
| 215 | } else { |
| 216 | break; |
| 217 | } |
| 218 | } |
| 219 | |
| 220 | unloadedRanges.push({ |
| 221 | startIndex: rangeStartIndex, |
| 222 | stopIndex: rangeStopIndex, |
| 223 | }); |
| 224 | } |
| 225 | |
| 226 | // Check to see if our first range ended prematurely. |
| 227 | // In this case we should scan backwards to try filling our :minimumBatchSize. |
| 228 | if (unloadedRanges.length) { |
| 229 | const firstUnloadedRange = unloadedRanges[0]; |
| 230 | |
| 231 | while ( |
no test coverage detected
searching dependent graphs…