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

Avoid calls to $apply #208

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 35 additions & 13 deletions src/ui-layout.js
Original file line number Diff line number Diff line change
Expand Up @@ -123,16 +123,20 @@ angular.module('ui.layout', [])
// move the splitbar
ctrl.movingSplitbar[position] = newPosition;

ctrl.movingSplitbar.updatePosition();
beforeContainer.update();
afterContainer.update();

// broadcast an event that resize happened (debounced to 50ms)
if(debounceEvent) $timeout.cancel(debounceEvent);
debounceEvent = $timeout(function() {
$scope.$digest();
$scope.$broadcast('ui.layout.resize', beforeContainer, afterContainer);
debounceEvent = null;
}, 50);
}, 50, false);
}
}
}

//Enable a new animation frame
animationFrameRequested = null;
}
Expand Down Expand Up @@ -653,8 +657,9 @@ angular.module('ui.layout', [])
});

function onResize() {
scope.$evalAsync(function() {
ctrl.calculate();
ctrl.calculate();
ctrl.containers.forEach(function(c) {
c.update();
});
}

Expand Down Expand Up @@ -835,23 +840,29 @@ angular.module('ui.layout', [])
e.stopPropagation();

htmlElement.on('mousemove touchmove', function(event) {
scope.$apply(angular.bind(ctrl, ctrl.mouseMoveHandler, event));
ctrl.mouseMoveHandler(event);
});
return false;
});

htmlElement.on('mouseup touchend', function(event) {
scope.$apply(angular.bind(ctrl, ctrl.mouseUpHandler, event));
ctrl.mouseUpHandler(event);
htmlElement.off('mousemove touchmove');
});

scope.$watch('splitbar.size', function(newValue) {
element.css(ctrl.sizeProperties.sizeProperty, newValue + 'px');
});

scope.$watch('splitbar.' + ctrl.sizeProperties.flowProperty, function(newValue) {
element.css(ctrl.sizeProperties.flowProperty, newValue + 'px');
});
scope.splitbar.updatePosition = function() {
element.css(ctrl.sizeProperties.flowProperty, scope.splitbar[ctrl.sizeProperties.flowProperty] + 'px');
};

scope.splitbar.update = function() {
scope.splitbar.updatePosition();
};

scope.$watch('splitbar.' + ctrl.sizeProperties.flowProperty, scope.splitbar.updatePosition);

scope.$on('$destroy', function() {
htmlElement.off('mouseup touchend mousemove touchmove');
Expand Down Expand Up @@ -929,18 +940,29 @@ angular.module('ui.layout', [])
}
});

scope.container.updateSize = function() {
element.css(ctrl.sizeProperties.sizeProperty, scope.container.size + 'px');
};

scope.$watch('container.size', function(newValue) {
element.css(ctrl.sizeProperties.sizeProperty, newValue + 'px');
scope.container.updateSize();
if(newValue === 0) {
element.addClass('ui-layout-hidden');
} else {
element.removeClass('ui-layout-hidden');
}
});

scope.$watch('container.' + ctrl.sizeProperties.flowProperty, function(newValue) {
element.css(ctrl.sizeProperties.flowProperty, newValue + 'px');
});
scope.container.updatePosition = function() {
element.css(ctrl.sizeProperties.flowProperty, scope.container[ctrl.sizeProperties.flowProperty] + 'px');
};

scope.container.update = function() {
scope.container.updatePosition();
scope.container.updateSize();
};

scope.$watch('container.' + ctrl.sizeProperties.flowProperty, scope.container.updatePosition);

//TODO: add ability to disable auto-adding a splitbar after the container
var parent = element.parent();
Expand Down