mirror of
https://github.com/Hopiu/angular.js.git
synced 2026-03-24 10:20:23 +00:00
- Speed improvements (about 4x on flush phase) - Memory improvements (uses no function closures) - Break $eval into $apply, $dispatch, $flush - Introduced $watch and $observe Breaks angular.equals() use === instead of == Breaks angular.scope() does not take parent as first argument Breaks scope.$watch() takes scope as first argument Breaks scope.$set(), scope.$get are removed Breaks scope.$config is removed Breaks $route.onChange callback has not "this" bounded
69 lines
1.8 KiB
JavaScript
69 lines
1.8 KiB
JavaScript
'use strict';
|
|
|
|
/**
|
|
* @workInProgress
|
|
* @ngdoc service
|
|
* @name angular.service.$invalidWidgets
|
|
*
|
|
* @description
|
|
* Keeps references to all invalid widgets found during validation.
|
|
* Can be queried to find whether there are any invalid widgets currently displayed.
|
|
*
|
|
* @example
|
|
*/
|
|
angularServiceInject("$invalidWidgets", function(){
|
|
var invalidWidgets = [];
|
|
|
|
|
|
/** Remove an element from the array of invalid widgets */
|
|
invalidWidgets.markValid = function(element){
|
|
var index = indexOf(invalidWidgets, element);
|
|
if (index != -1)
|
|
invalidWidgets.splice(index, 1);
|
|
};
|
|
|
|
|
|
/** Add an element to the array of invalid widgets */
|
|
invalidWidgets.markInvalid = function(element){
|
|
var index = indexOf(invalidWidgets, element);
|
|
if (index === -1)
|
|
invalidWidgets.push(element);
|
|
};
|
|
|
|
|
|
/** Return count of all invalid widgets that are currently visible */
|
|
invalidWidgets.visible = function() {
|
|
var count = 0;
|
|
forEach(invalidWidgets, function(widget){
|
|
count = count + (isVisible(widget) ? 1 : 0);
|
|
});
|
|
return count;
|
|
};
|
|
|
|
|
|
/* At the end of each eval removes all invalid widgets that are not part of the current DOM. */
|
|
this.$watch(function() {
|
|
for(var i = 0; i < invalidWidgets.length;) {
|
|
var widget = invalidWidgets[i];
|
|
if (isOrphan(widget[0])) {
|
|
invalidWidgets.splice(i, 1);
|
|
if (widget.dealoc) widget.dealoc();
|
|
} else {
|
|
i++;
|
|
}
|
|
}
|
|
});
|
|
|
|
|
|
/**
|
|
* Traverses DOM element's (widget's) parents and considers the element to be an orphan if one of
|
|
* it's parents isn't the current window.document.
|
|
*/
|
|
function isOrphan(widget) {
|
|
if (widget == window.document) return false;
|
|
var parent = widget.parentNode;
|
|
return !parent || isOrphan(parent);
|
|
}
|
|
|
|
return invalidWidgets;
|
|
});
|