Skip to content

Commit

Permalink
angularjs-perf: Removed todo-escaped directive
Browse files Browse the repository at this point in the history
Using the native `ng-keydown` instead
  • Loading branch information
dmitriz committed Dec 23, 2015
1 parent 6f8b0d9 commit c705f8b
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 35 deletions.
11 changes: 8 additions & 3 deletions examples/angularjs-perf/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,20 @@ <h1>todos</h1>
<input id="toggle-all" type="checkbox" ng-model="TC.allChecked" ng-click="TC.markAll(TC.allChecked)">
<label for="toggle-all">Mark all as complete</label>
<ul id="todo-list">
<li ng-repeat="todo in TC.todos | filter:TC.statusFilter track by $index" ng-class="{completed: todo.completed, editing: todo === TC.editedTodo}">
<li ng-repeat="todo in TC.todos | filter:TC.statusFilter track by $index"
ng-class="{completed: todo.completed, editing: todo === TC.editedTodo}">
<div class="view">
<input class="toggle" type="checkbox" ng-model="todo.completed">
<label ng-dblclick="TC.editTodo(todo)">{{todo.title}}</label>
<button class="destroy" ng-click="TC.removeTodo($index)"></button>
</div>
<form ng-submit="TC.doneEditing(todo, $index)">
<input class="edit" ng-trim="false" ng-model="todo.title" ng-blur="TC.doneEditing(todo, $index)" todo-escape="TC.revertEditing($index)" todo-focus="todo === TC.editedTodo">
<input class="edit"
ng-trim="false"
ng-model="todo.title"
ng-blur="TC.doneEditing(todo, $index)"
ng-keydown="($event.keyCode === TC.ESCAPE_KEY) && TC.revertEditing($index)"
todo-focus="todo === TC.editedTodo">
</form>
</li>
</ul>
Expand Down Expand Up @@ -65,6 +71,5 @@ <h1>todos</h1>
<script src="js/controllers/todoCtrl.js"></script>
<script src="js/services/todoStorage.js"></script>
<script src="js/directives/todoFocus.js"></script>
<script src="js/directives/todoEscape.js"></script>
</body>
</html>
4 changes: 2 additions & 2 deletions examples/angularjs-perf/js/app.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/* jshint undef: true, unused: true */
/*global angular */
/*jshint unused:false */
(function () {
'use strict';

Expand All @@ -8,5 +8,5 @@
*
* @type {angular.Module}
*/
angular.module('todomvc', ['todoCtrl', 'todoEscape', 'todoFocus', 'todoStorage']);
angular.module('todomvc', ['todoCtrl', 'todoFocus', 'todoStorage']);
})();
22 changes: 17 additions & 5 deletions examples/angularjs-perf/js/controllers/todoCtrl.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,11 @@
/* jshint undef: true, unused: true */
/*global angular */

/*
* Line below lets us save `this` as `TC`
* to make properties look exactly the same as in the template
*/
//jscs:disable safeContextKeyword
(function () {
'use strict';

Expand All @@ -13,10 +20,15 @@
var TC = this;
var todos = TC.todos = todoStorage.get();

TC.newTodo = {title: '', completed: false};

TC.ESCAPE_KEY = 27;
TC.editedTodo = {};

function resetTodo() {
TC.newTodo = {title: '', completed: false};
}

resetTodo();

if ($location.path() === '') {
$location.path('/');
}
Expand All @@ -43,8 +55,7 @@
}

todos.push(TC.newTodo);

TC.newTodo = {title: '', completed: false};
resetTodo();
};

TC.editTodo = function (todo) {
Expand All @@ -64,8 +75,8 @@
};

TC.revertEditing = function (index) {
TC.editedTodo = {};
todos[index] = TC.originalTodo;
TC.doneEditing(TC.originalTodo);
};

TC.removeTodo = function (index) {
Expand All @@ -85,3 +96,4 @@
};
});
})();
//jscs:enable
25 changes: 0 additions & 25 deletions examples/angularjs-perf/js/directives/todoEscape.js

This file was deleted.

1 change: 1 addition & 0 deletions examples/angularjs-perf/js/directives/todoFocus.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* jshint undef: true, unused: true */
/*global angular */
(function () {
'use strict';
Expand Down
1 change: 1 addition & 0 deletions examples/angularjs-perf/js/services/todoStorage.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* jshint undef: true, unused: true */
/*global angular */
(function () {
'use strict';
Expand Down

0 comments on commit c705f8b

Please sign in to comment.