This repository has been archived by the owner on May 29, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 6.7k
#2404 Modal open calls should complete in order #2443
Closed
Closed
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -606,6 +606,11 @@ angular.module('ui.bootstrap.modal', []) | |
return promisesArr; | ||
} | ||
|
||
var promiseChain = null; | ||
$modal.getPromiseChain = function() { | ||
return promiseChain; | ||
}; | ||
|
||
$modal.open = function (modalOptions) { | ||
|
||
var modalResultDeferred = $q.defer(); | ||
|
@@ -637,63 +642,70 @@ angular.module('ui.bootstrap.modal', []) | |
var templateAndResolvePromise = | ||
$q.all([getTemplatePromise(modalOptions)].concat(getResolvePromises(modalOptions.resolve))); | ||
|
||
// Wait for the resolution of the existing promise chain. | ||
// Then switch to our own combined promise dependency (regardless of how the previous modal fared). | ||
// Then add to $modalStack and resolve opened. | ||
// Finally clean up the chain variable if no subsequent modal has overwritten it. | ||
var samePromise; | ||
samePromise = promiseChain = $q.all([promiseChain]) | ||
.then(function() { return templateAndResolvePromise; }, function() { return templateAndResolvePromise; }) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The second callback is forcing a resolve if there is an error? |
||
.then(function resolveSuccess(tplAndVars) { | ||
|
||
var modalScope = (modalOptions.scope || $rootScope).$new(); | ||
modalScope.$close = modalInstance.close; | ||
modalScope.$dismiss = modalInstance.dismiss; | ||
|
||
modalScope.$on('$destroy', function() { | ||
if (!modalScope.$$uibDestructionScheduled) { | ||
modalScope.$dismiss('$uibUnscheduledDestruction'); | ||
} | ||
}); | ||
|
||
templateAndResolvePromise.then(function resolveSuccess(tplAndVars) { | ||
|
||
var modalScope = (modalOptions.scope || $rootScope).$new(); | ||
modalScope.$close = modalInstance.close; | ||
modalScope.$dismiss = modalInstance.dismiss; | ||
|
||
modalScope.$on('$destroy', function() { | ||
if (!modalScope.$$uibDestructionScheduled) { | ||
modalScope.$dismiss('$uibUnscheduledDestruction'); | ||
} | ||
}); | ||
var ctrlInstance, ctrlLocals = {}; | ||
var resolveIter = 1; | ||
|
||
var ctrlInstance, ctrlLocals = {}; | ||
var resolveIter = 1; | ||
//controllers | ||
if (modalOptions.controller) { | ||
ctrlLocals.$scope = modalScope; | ||
ctrlLocals.$modalInstance = modalInstance; | ||
angular.forEach(modalOptions.resolve, function(value, key) { | ||
ctrlLocals[key] = tplAndVars[resolveIter++]; | ||
}); | ||
|
||
//controllers | ||
if (modalOptions.controller) { | ||
ctrlLocals.$scope = modalScope; | ||
ctrlLocals.$modalInstance = modalInstance; | ||
angular.forEach(modalOptions.resolve, function(value, key) { | ||
ctrlLocals[key] = tplAndVars[resolveIter++]; | ||
}); | ||
ctrlInstance = $controller(modalOptions.controller, ctrlLocals); | ||
if (modalOptions.controllerAs) { | ||
if (modalOptions.bindToController) { | ||
angular.extend(ctrlInstance, modalScope); | ||
} | ||
|
||
ctrlInstance = $controller(modalOptions.controller, ctrlLocals); | ||
if (modalOptions.controllerAs) { | ||
if (modalOptions.bindToController) { | ||
angular.extend(ctrlInstance, modalScope); | ||
modalScope[modalOptions.controllerAs] = ctrlInstance; | ||
} | ||
|
||
modalScope[modalOptions.controllerAs] = ctrlInstance; | ||
} | ||
} | ||
|
||
$modalStack.open(modalInstance, { | ||
scope: modalScope, | ||
deferred: modalResultDeferred, | ||
renderDeferred: modalRenderDeferred, | ||
content: tplAndVars[0], | ||
animation: modalOptions.animation, | ||
backdrop: modalOptions.backdrop, | ||
keyboard: modalOptions.keyboard, | ||
backdropClass: modalOptions.backdropClass, | ||
windowClass: modalOptions.windowClass, | ||
windowTemplateUrl: modalOptions.windowTemplateUrl, | ||
size: modalOptions.size, | ||
openedClass: modalOptions.openedClass | ||
}); | ||
$modalStack.open(modalInstance, { | ||
scope: modalScope, | ||
deferred: modalResultDeferred, | ||
renderDeferred: modalRenderDeferred, | ||
content: tplAndVars[0], | ||
animation: modalOptions.animation, | ||
backdrop: modalOptions.backdrop, | ||
keyboard: modalOptions.keyboard, | ||
backdropClass: modalOptions.backdropClass, | ||
windowClass: modalOptions.windowClass, | ||
windowTemplateUrl: modalOptions.windowTemplateUrl, | ||
size: modalOptions.size, | ||
openedClass: modalOptions.openedClass | ||
}); | ||
modalOpenedDeferred.resolve(true); | ||
|
||
}, function resolveError(reason) { | ||
modalResultDeferred.reject(reason); | ||
}); | ||
|
||
templateAndResolvePromise.then(function() { | ||
modalOpenedDeferred.resolve(true); | ||
}, function(reason) { | ||
modalOpenedDeferred.reject(reason); | ||
modalResultDeferred.reject(reason); | ||
}) | ||
.finally(function() { | ||
if (promiseChain === samePromise) { | ||
promiseChain = null; | ||
} | ||
}); | ||
|
||
return modalInstance; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How about getting the top opened window's
opened
promise and appending it here?You can get it by doing
$modalStack.getTop().opened
. You should also handle the case that there's no top window.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's a good suggestion, but I don't think it can work because
$modalStack
isn't updated untiltemplateAndResolvePromise
is resolved.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've reorganized things so that the opened promise is the only one burdened with chaining concerns. It shuffles things around a little, but it leaves the
templateAndResolvePromise
alone.