From e635b8a106bdfbc87ecc320712d5cd14f5d1a11c Mon Sep 17 00:00:00 2001 From: diego0020 Date: Sat, 20 Oct 2018 20:08:59 -0500 Subject: [PATCH 1/2] on abort reject promise --- src/loadImage.js | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/loadImage.js b/src/loadImage.js index bdc25cd..b98abd6 100644 --- a/src/loadImage.js +++ b/src/loadImage.js @@ -7,7 +7,7 @@ import createImage from './createImage.js'; // let options = { // callback allowing customization of the xhr (e.g. adding custom auth headers, cors, etc) - beforeSend (/* xhr */) {} + beforeSend (/* xhr */) { } }; @@ -51,11 +51,15 @@ export function loadImage (imageId) { }, reject); }; + xhr.onabort = reject; + xhr.send(); }); const cancelFn = () => { - xhr.abort(); + if (xhr.readyState < 4) { + xhr.abort(); + } }; return { From 6bbeffe2fba16e1b64911cb0e0000b47f45f327d Mon Sep 17 00:00:00 2001 From: diego0020 Date: Sat, 20 Oct 2018 20:09:07 -0500 Subject: [PATCH 2/2] add to example --- examples/index.html | 116 +++++++++++++++++++++++++------------------- 1 file changed, 67 insertions(+), 49 deletions(-) diff --git a/examples/index.html b/examples/index.html index fd19f02..234912e 100644 --- a/examples/index.html +++ b/examples/index.html @@ -1,5 +1,6 @@ + @@ -10,77 +11,85 @@ + -
- -