Skip to content

Commit

Permalink
Add an if to prevent unneeded saves
Browse files Browse the repository at this point in the history
  • Loading branch information
Foxandxss committed Jul 29, 2013
1 parent 401846d commit 3db7131
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions architecture-examples/angularjs/js/controllers/todoCtrl.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,13 @@ todomvc.controller('TodoCtrl', function TodoCtrl($scope, $location, todoStorage,
$scope.newTodo = '';
$scope.editedTodo = null;

$scope.$watch('todos', function () {
$scope.$watch('todos', function (newValue, oldValue) {
$scope.remainingCount = filterFilter(todos, { completed: false }).length;
$scope.completedCount = todos.length - $scope.remainingCount;
$scope.allChecked = !$scope.remainingCount;
todoStorage.put(todos);
if (newValue !== oldValue) { // This prevents unneeded calls to the local storage
todoStorage.put(todos);
}
}, true);

if ($location.path() === '') {
Expand Down

0 comments on commit 3db7131

Please sign in to comment.