From 3db7131fed2896ba0903d6830a124379ae936bf9 Mon Sep 17 00:00:00 2001 From: Jesus Rodriguez Date: Mon, 29 Jul 2013 16:54:24 +0200 Subject: [PATCH] Add an if to prevent unneeded saves --- architecture-examples/angularjs/js/controllers/todoCtrl.js | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/architecture-examples/angularjs/js/controllers/todoCtrl.js b/architecture-examples/angularjs/js/controllers/todoCtrl.js index db16804c4b..f023836e8c 100644 --- a/architecture-examples/angularjs/js/controllers/todoCtrl.js +++ b/architecture-examples/angularjs/js/controllers/todoCtrl.js @@ -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() === '') {