Skip to content
This repository has been archived by the owner on Sep 5, 2024. It is now read-only.

Commit

Permalink
feat(tabs): replaces unnecessary watches with getter/setter syntax fo…
Browse files Browse the repository at this point in the history
…r improved performance
  • Loading branch information
Robert Messerle committed Jun 9, 2015
1 parent 761ded6 commit c806e8b
Showing 1 changed file with 21 additions and 12 deletions.
33 changes: 21 additions & 12 deletions src/components/tabs/js/tabsController.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,21 @@ angular
*/
function MdTabsController ($scope, $element, $window, $timeout, $mdConstant, $mdTabInkRipple,
$mdUtil, $animate) {
var ctrl = this,
locked = false,
elements = getElements(),
queue = [],
destroyed = false,
loaded = false;
var ctrl = this,
locked = false,
elements = getElements(),
queue = [],
destroyed = false,
loaded = false;

defineProperty('focusIndex', handleFocusIndexChange, $scope.selectedIndex || 0);
defineProperty('offsetLeft', handleOffsetChange, 0);
defineProperty('hasContent', handleHasContent, false);

ctrl.scope = $scope;
ctrl.parent = $scope.$parent;
ctrl.tabs = [];
ctrl.lastSelectedIndex = null;
ctrl.focusIndex = $scope.selectedIndex || 0;
ctrl.offsetLeft = 0;
ctrl.hasContent = false;
ctrl.hasFocus = false;
ctrl.lastClick = true;
ctrl.shouldPaginate = false;
Expand All @@ -47,9 +48,6 @@ function MdTabsController ($scope, $element, $window, $timeout, $mdConstant, $md

function init () {
$scope.$watch('selectedIndex', handleSelectedIndexChange);
$scope.$watch('$mdTabsCtrl.focusIndex', handleFocusIndexChange);
$scope.$watch('$mdTabsCtrl.offsetLeft', handleOffsetChange);
$scope.$watch('$mdTabsCtrl.hasContent', handleHasContent);
angular.element($window).on('resize', handleWindowResize);
angular.element(elements.paging).on('DOMSubtreeModified', ctrl.updateInkBarStyles);
angular.element(elements.paging).on('DOMSubtreeModified', updatePagination);
Expand Down Expand Up @@ -286,6 +284,17 @@ function MdTabsController ($scope, $element, $window, $timeout, $mdConstant, $md

//-- Utility methods

function defineProperty (key, handler, value) {
Object.defineProperty(ctrl, key, {
get: function () { return value; },
set: function (newValue) {
var oldValue = value;
value = newValue;
handler(newValue, oldValue);
}
});
}

function updatePagination () {
ctrl.shouldPaginate = shouldPaginate();
ctrl.shouldCenterTabs = shouldCenterTabs();
Expand Down

0 comments on commit c806e8b

Please sign in to comment.