All files / core/src/loaders fillNearbyFrames.ts

91.66% Statements 11/12
100% Branches 6/6
100% Functions 1/1
91.66% Lines 11/12

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33          2430x   1188x     1242x 3654x 3654x 3654x 3654x 1839x   1815x               1815x 1815x            
import type { ImageLoadListener } from '../types';
import cache from '../cache/cache';
 
/** Actually fills the nearby frames from the given frame */
export function fillNearbyFrames(listener: ImageLoadListener, request, image) {
  if (!request?.nearbyRequests?.length) {
    // Not filling nearby images with a copy of this
    return;
  }
 
  for (const nearbyItem of request.nearbyRequests) {
    try {
      const { itemId: targetId, imageQualityStatus } = nearbyItem;
      const currentStatus = cache.getImageQuality(targetId);
      if (currentStatus !== undefined && currentStatus >= imageQualityStatus) {
        continue;
      }
      const nearbyImage = {
        ...image,
        imageId: targetId,
        imageQualityStatus,
      };
 
      // This will deliver the partial image as something that can be
      // immediate rendered, but won't replace any future fetches.
      cache.setPartialImage(targetId, nearbyImage);
      listener.successCallback(targetId, nearbyImage);
    } catch (e) {
      console.warn("Couldn't fill nearby item ", nearbyItem.itemId, e);
    }
  }
}