mirror of
https://github.com/Hopiu/angular.js.git
synced 2026-03-16 23:30:23 +00:00
fix($compile): make order directives w/ same priority deterministic
Array.prototype.sort is speced out to be as potentionally unstable sort, which is how it's implemented in FF and IE. This has caused the order of directives with the same priority to vary between browsers. For consistency sake, we now consider directive name and registration, order when determining the order of directives with the same priority. Note: it is still possible to get into a situation when the directive order is underministic - when source files are loaded asynchronously in non-deterministic order and there are are directives registered with the same name and priority, the order in which they will be applied will depend on the file load order.
This commit is contained in:
parent
83fbaa54f1
commit
4357da8575
1 changed files with 6 additions and 2 deletions
|
|
@ -186,7 +186,7 @@ function $CompileProvider($provide) {
|
|||
$provide.factory(name + Suffix, ['$injector', '$exceptionHandler',
|
||||
function($injector, $exceptionHandler) {
|
||||
var directives = [];
|
||||
forEach(hasDirectives[name], function(directiveFactory) {
|
||||
forEach(hasDirectives[name], function(directiveFactory, index) {
|
||||
try {
|
||||
var directive = $injector.invoke(directiveFactory);
|
||||
if (isFunction(directive)) {
|
||||
|
|
@ -195,6 +195,7 @@ function $CompileProvider($provide) {
|
|||
directive.compile = valueFn(directive.link);
|
||||
}
|
||||
directive.priority = directive.priority || 0;
|
||||
directive.index = index;
|
||||
directive.name = directive.name || name;
|
||||
directive.require = directive.require || (directive.controller && directive.name);
|
||||
directive.restrict = directive.restrict || 'A';
|
||||
|
|
@ -1277,7 +1278,10 @@ function $CompileProvider($provide) {
|
|||
* Sorting function for bound directives.
|
||||
*/
|
||||
function byPriority(a, b) {
|
||||
return b.priority - a.priority;
|
||||
var diff = b.priority - a.priority;
|
||||
if (diff !== 0) return diff;
|
||||
if (a.name !== b.name) return (a.name < b.name) ? -1 : 1;
|
||||
return a.index - b.index;
|
||||
}
|
||||
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue