Skip to content

Commit

Permalink
Check generateData result before sending onload
Browse files Browse the repository at this point in the history
  • Loading branch information
ivmartel committed Jan 14, 2025
1 parent 10f527e commit a928b41
Showing 1 changed file with 32 additions and 19 deletions.
51 changes: 32 additions & 19 deletions src/image/dicomBufferToView.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,13 +84,14 @@ export class DicomBufferToView {
*
* @param {number} index The data index.
* @param {string} origin The data origin.
* @returns {boolean} True if the generation went ok.
*/
#generateData(index, origin) {
const dataElements = this.#dicomParserStore[index].getDicomElements();
const factory = this.#factories[index];
// exit if no factory
if (typeof factory === 'undefined') {
return;
return false;
}
// create data
try {
Expand All @@ -117,7 +118,32 @@ export class DicomBufferToView {
this.onloadend({
source: origin
});
// false for error
return false;
}

// all good
return true;
}

/**
* Generate a single data object.
*
* @param {number} index The data index.
* @param {string} origin The data origin.
*/
#generateSingleData(index, origin) {
// generate image
if (this.#generateData(index, origin)) {
// send load event
this.onload({
source: origin
});
}
// allways send loadend
this.onloadend({
source: origin
});
}

/**
Expand All @@ -127,23 +153,16 @@ export class DicomBufferToView {
* @param {string} origin The data origin.
*/
#generateImageUncompressed(index, origin) {
// send progress
// send 100% progress
this.onprogress({
lengthComputable: true,
loaded: 100,
total: 100,
index: index,
source: origin
});
// generate image
this.#generateData(index, origin);
// send load events
this.onload({
source: origin
});
this.onloadend({
source: origin
});
// generate single data
this.#generateSingleData(index, origin);
}

/**
Expand Down Expand Up @@ -291,14 +310,8 @@ export class DicomBufferToView {
* @param {string} origin The data origin.
*/
#handleNonImageData(index, origin) {
this.#generateData(index, origin);
// send load events
this.onload({
source: origin
});
this.onloadend({
source: origin
});
// generate single data
this.#generateSingleData(index, origin);
}

/**
Expand Down

0 comments on commit a928b41

Please sign in to comment.