Commit 3db7131f authored by Jesus Rodriguez's avatar Jesus Rodriguez

Add an if to prevent unneeded saves

parent 401846de
...@@ -12,11 +12,13 @@ todomvc.controller('TodoCtrl', function TodoCtrl($scope, $location, todoStorage, ...@@ -12,11 +12,13 @@ todomvc.controller('TodoCtrl', function TodoCtrl($scope, $location, todoStorage,
$scope.newTodo = ''; $scope.newTodo = '';
$scope.editedTodo = null; $scope.editedTodo = null;
$scope.$watch('todos', function () { $scope.$watch('todos', function (newValue, oldValue) {
$scope.remainingCount = filterFilter(todos, { completed: false }).length; $scope.remainingCount = filterFilter(todos, { completed: false }).length;
$scope.completedCount = todos.length - $scope.remainingCount; $scope.completedCount = todos.length - $scope.remainingCount;
$scope.allChecked = !$scope.remainingCount; $scope.allChecked = !$scope.remainingCount;
todoStorage.put(todos); if (newValue !== oldValue) { // This prevents unneeded calls to the local storage
todoStorage.put(todos);
}
}, true); }, true);
if ($location.path() === '') { if ($location.path() === '') {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment