Skip to content
This repository has been archived by the owner on Nov 20, 2018. It is now read-only.

Commit

Permalink
fix(uploader.basic.api.js): early initial files onStatusChange
Browse files Browse the repository at this point in the history
onStatusChange is called for initial/canned files before internal state for the file is completely updated. This change introduces an update that makes it easy for internal users of the upload-data service to defer the status change broadcast until all processing and state updates are complete.
fixes #1802
  • Loading branch information
Ray Nicholus authored and Ray Nicholus committed Apr 1, 2017
1 parent 2c86cbb commit a6fe1b1
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 13 deletions.
2 changes: 2 additions & 0 deletions client/js/upload-data.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ qq.UploadData = function(uploaderProxy) {
* - status: Initial `qq.status` for this file. Omit for `qq.status.SUBMITTING`.
* - batchId: ID of the batch this file belongs to
* - proxyGroupId: ID of the proxy group associated with this file
* - onBeforeStatusChange(fileId): callback that is executed before the status change is broadcast
*
* @returns {number} Internal ID for this file.
*/
Expand Down Expand Up @@ -104,6 +105,7 @@ qq.UploadData = function(uploaderProxy) {
}
byStatus[status].push(id);

spec.onBeforeStatusChange && spec.onBeforeStatusChange(id);
uploaderProxy.onStatusChange(id, null, status);

return id;
Expand Down
27 changes: 14 additions & 13 deletions client/js/uploader.basic.api.js
Original file line number Diff line number Diff line change
Expand Up @@ -442,24 +442,25 @@
qq.basePrivateApi = {
// Updates internal state with a file record (not backed by a live file). Returns the assigned ID.
_addCannedFile: function(sessionData) {
var id = this._uploadData.addFile({
var self = this;

return this._uploadData.addFile({
uuid: sessionData.uuid,
name: sessionData.name,
size: sessionData.size,
status: qq.status.UPLOAD_SUCCESSFUL
});

sessionData.deleteFileEndpoint && this.setDeleteFileEndpoint(sessionData.deleteFileEndpoint, id);
sessionData.deleteFileParams && this.setDeleteFileParams(sessionData.deleteFileParams, id);

if (sessionData.thumbnailUrl) {
this._thumbnailUrls[id] = sessionData.thumbnailUrl;
}
status: qq.status.UPLOAD_SUCCESSFUL,
onBeforeStatusChange: function(id) {
sessionData.deleteFileEndpoint && self.setDeleteFileEndpoint(sessionData.deleteFileEndpoint, id);
sessionData.deleteFileParams && self.setDeleteFileParams(sessionData.deleteFileParams, id);

this._netUploaded++;
this._netUploadedOrQueued++;
if (sessionData.thumbnailUrl) {
self._thumbnailUrls[id] = sessionData.thumbnailUrl;
}

return id;
self._netUploaded++;
self._netUploadedOrQueued++;
}
});
},

_annotateWithButtonId: function(file, associatedInput) {
Expand Down

0 comments on commit a6fe1b1

Please sign in to comment.