MCPcopy
hub / github.com/tdewolff/minify / createOrUpdateImage

Function createOrUpdateImage

_benchmarks/sample_echarts.js:8308–8336  ·  view source on GitHub ↗
(newImageOrSrc, image, hostEl, onload, cbPayload)

Source from the content-addressed store, hash-verified

8306 }
8307 }
8308 function createOrUpdateImage(newImageOrSrc, image, hostEl, onload, cbPayload) {
8309 if (!newImageOrSrc) {
8310 return image;
8311 }
8312 else if (typeof newImageOrSrc === 'string') {
8313 if ((image && image.__zrImageSrc === newImageOrSrc) || !hostEl) {
8314 return image;
8315 }
8316 var cachedImgObj = globalImageCache.get(newImageOrSrc);
8317 var pendingWrap = { hostEl: hostEl, cb: onload, cbPayload: cbPayload };
8318 if (cachedImgObj) {
8319 image = cachedImgObj.image;
8320 !isImageReady(image) && cachedImgObj.pending.push(pendingWrap);
8321 }
8322 else {
8323 image = new Image();
8324 image.onload = image.onerror = imageOnLoad;
8325 globalImageCache.put(newImageOrSrc, image.__cachedImgObj = {
8326 image: image,
8327 pending: [pendingWrap]
8328 });
8329 image.src = image.__zrImageSrc = newImageOrSrc;
8330 }
8331 return image;
8332 }
8333 else {
8334 return newImageOrSrc;
8335 }
8336 }
8337 function imageOnLoad() {
8338 var cachedImgObj = this.__cachedImgObj;
8339 this.onload = this.onerror = this.__cachedImgObj = null;

Callers 3

createCanvasPatternFunction · 0.85
brushImageFunction · 0.85
sample_echarts.jsFile · 0.85

Calls 1

isImageReadyFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…