Skip to content

Commit

Permalink
Migrate from Deferred to Promises, rework the imageCache (thanks @die…
Browse files Browse the repository at this point in the history
  • Loading branch information
swederik committed Nov 17, 2017
1 parent 4425ae0 commit 16051ab
Show file tree
Hide file tree
Showing 16 changed files with 250 additions and 201 deletions.
103 changes: 56 additions & 47 deletions dist/cornerstone.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/cornerstone.js.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/cornerstone.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/cornerstone.min.js.map

Large diffs are not rendered by default.

9 changes: 6 additions & 3 deletions example/exampleImageIdLoader.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 6 additions & 3 deletions example/exampleImageIdLoaderCt.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 4 additions & 7 deletions example/imageCache/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -161,13 +161,10 @@ <h1>
sizeInBytes : width * height * 4
};


// Create a deferred object, resolve it with the image object we just created and return the
// deferred to cornerstone. Cornerstone will get the image object by calling then() on the
// deferred
var deferred = $.Deferred();
deferred.resolve(image);
return deferred;
return {
promise: new Promise((resolve) => resolve(image)),
cancelFn: undefined
}
}

cornerstone.registerImageLoader('colorImageLoader', loadImage);
Expand Down
10 changes: 4 additions & 6 deletions example/imageloader/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -85,12 +85,10 @@ <h1>
sizeInBytes: width * height * 2
};

// Create a deferred object, resolve it with the image object we just created and return the
// deferred to cornerstone. Cornerstone will get the image object by calling then() on the
// deferred
var deferred = $.Deferred();
deferred.resolve(image);
return deferred;
return {
promise: new Promise((resolve) => resolve(image)),
cancelFn: undefined
}
}

cornerstone.registerImageLoader('myImageLoader', loadImage);
Expand Down
6 changes: 2 additions & 4 deletions example/layers/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -121,9 +121,7 @@ <h1>
// This method will wait for all images to be loaded (`loadImages`)
// before adding the layers
function loadLayers() {
loadImages().then(function() {
var images = Array.prototype.slice.call(arguments);

loadImages().then(function(images) {
images.forEach(function(image, index) {
var layer = layers[index];
var layerId = cornerstone.addLayer(element, image, layer.options);
Expand Down Expand Up @@ -154,7 +152,7 @@ <h1>
promises.push(loadPromise);
});

return $.when.apply($, promises);
return Promise.all(promises);
}

// Select the right layer in the dropdown
Expand Down
10 changes: 4 additions & 6 deletions example/modalityAndVIOLut/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -112,12 +112,10 @@ <h1>
sizeInBytes: width * height * 2
};

// Create a deferred object, resolve it with the image object we just created and return the
// deferred to cornerstone. Cornerstone will get the image object by calling then() on the
// deferred
var deferred = $.Deferred();
deferred.resolve(image);
return deferred;
return {
promise: new Promise((resolve) => resolve(image)),
cancelFn: undefined
};
}

cornerstone.registerImageLoader('myImageLoader', loadImage);
Expand Down
15 changes: 9 additions & 6 deletions example/nonSquarePixels/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -110,12 +110,15 @@ <h1>
sizeInBytes: width * height * 2
};

// Create a deferred object, resolve it with the image object we just created and return the
// deferred to cornerstone. Cornerstone will get the image object by calling then() on the
// deferred
var deferred = $.Deferred();
deferred.resolve(image);
return deferred;
// Create a Promise, resolve it with the image object we just created and return the
// Promise to cornerstone. Cornerstone will get the image object by calling then() on the
// Promise. An optional function can be provided to allow the image loader to cancel a request.
return {
promise: new Promise((resolve) => {
resolve(image);
}),
cancelFn: undefined
};
}

cornerstone.registerImageLoader('myImageLoader', loadImage);
Expand Down

0 comments on commit 16051ab

Please sign in to comment.