Permalink
Browse files

Angular perf - code style

  • Loading branch information...
1 parent ad9e023 commit 33e1cf94d35847fb4e59de9d691c353f7b900f40 @sindresorhus sindresorhus committed Mar 9, 2013
@@ -46,7 +46,7 @@
<a ng-class="{selected: location.path() == '/completed'}" href="#/completed">Completed</a>
</li>
</ul>
- <button id="clear-completed" ng-click="clearDoneTodos()" ng-show="remainingCount < todos.length">Clear completed ({{todos.length - remainingCount}})</button>
+ <button id="clear-completed" ng-click="clearCompletedTodos()" ng-show="remainingCount < todos.length">Clear completed ({{todos.length - remainingCount}})</button>
</footer>
</section>
<footer id="info">
@@ -1,9 +1,9 @@
-/*global angular*/
-/*jshint unused:false*/
+/*global angular */
+/*jshint unused:false */
'use strict';
/**
- * The main TodoMVC app module.
+ * The main TodoMVC app module
*
* @type {angular.Module}
*/
@@ -1,4 +1,4 @@
-/*global todomvc*/
+/*global todomvc */
'use strict';
/**
@@ -16,6 +16,7 @@ todomvc.controller('TodoCtrl', function TodoCtrl($scope, $location, todoStorage,
if ($location.path() === '') {
$location.path('/');
}
+
$scope.location = $location;
$scope.$watch('location.path()', function (path) {
@@ -28,7 +29,6 @@ todomvc.controller('TodoCtrl', function TodoCtrl($scope, $location, todoStorage,
$scope.allChecked = val;
});
-
$scope.addTodo = function () {
if ($scope.newTodo.length === 0) {
return;
@@ -44,28 +44,26 @@ todomvc.controller('TodoCtrl', function TodoCtrl($scope, $location, todoStorage,
$scope.remainingCount++;
};
-
$scope.editTodo = function (todo) {
$scope.editedTodo = todo;
};
-
$scope.doneEditing = function (todo) {
$scope.editedTodo = null;
+
if (!todo.title) {
$scope.removeTodo(todo);
}
+
todoStorage.put(todos);
};
-
$scope.removeTodo = function (todo) {
$scope.remainingCount -= todo.completed ? 0 : 1;
todos.splice(todos.indexOf(todo), 1);
todoStorage.put(todos);
};
-
$scope.todoCompleted = function (todo) {
if (todo.completed) {
$scope.remainingCount--;
@@ -75,20 +73,18 @@ todomvc.controller('TodoCtrl', function TodoCtrl($scope, $location, todoStorage,
todoStorage.put(todos);
};
-
- $scope.clearDoneTodos = function () {
+ $scope.clearCompletedTodos = function () {
$scope.todos = todos = todos.filter(function (val) {
return !val.completed;
});
todoStorage.put(todos);
};
-
- $scope.markAll = function (done) {
+ $scope.markAll = function (completed) {
todos.forEach(function (todo) {
- todo.completed = done;
+ todo.completed = completed;
});
- $scope.remainingCount = done ? 0 : todos.length;
+ $scope.remainingCount = completed ? 0 : todos.length;
todoStorage.put(todos);
};
});
@@ -1,8 +1,8 @@
-/*global todomvc*/
+/*global todomvc */
'use strict';
/**
- * Directive that executes an expression when the element it is applied to loses focus.
+ * Directive that executes an expression when the element it is applied to loses focus
*/
todomvc.directive('todoBlur', function () {
return function (scope, elem, attrs) {
@@ -1,13 +1,13 @@
-/*global todomvc*/
+/*global todomvc */
'use strict';
/**
- * Directive that places focus on the element it is applied to when the expression it binds to evaluates to true.
+ * Directive that places focus on the element it is applied to when the expression it binds to evaluates to true
*/
todomvc.directive('todoFocus', function ($timeout) {
return function (scope, elem, attrs) {
- scope.$watch(attrs.todoFocus, function (newval) {
- if (newval) {
+ scope.$watch(attrs.todoFocus, function (newVal) {
+ if (newVal) {
$timeout(function () {
elem[0].focus();
}, 0, false);
@@ -1,8 +1,8 @@
-/*global todomvc*/
+/*global todomvc */
'use strict';
/**
- * Services that persists and retrieves TODOs from localStorage.
+ * Services that persists and retrieves TODOs from localStorage
*/
todomvc.factory('todoStorage', function () {
var STORAGE_ID = 'todos-angularjs-perf';

0 comments on commit 33e1cf9

Please sign in to comment.