Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
T
todomvc
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Eugene Shen
todomvc
Commits
6f8b0d9b
Commit
6f8b0d9b
authored
Dec 22, 2015
by
dmitriz
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
angularjs-perf: Simplified functions
parent
8d40a1c0
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
31 additions
and
43 deletions
+31
-43
examples/angularjs-perf/index.html
examples/angularjs-perf/index.html
+6
-6
examples/angularjs-perf/js/controllers/todoCtrl.js
examples/angularjs-perf/js/controllers/todoCtrl.js
+25
-37
No files found.
examples/angularjs-perf/index.html
View file @
6f8b0d9b
...
...
@@ -12,21 +12,21 @@
<header
id=
"header"
>
<h1>
todos
</h1>
<form
id=
"todo-form"
ng-submit=
"TC.addTodo()"
>
<input
id=
"new-todo"
placeholder=
"What needs to be done?"
ng-model=
"TC.newTodo"
autofocus
>
<input
id=
"new-todo"
placeholder=
"What needs to be done?"
ng-model=
"TC.newTodo
.title
"
autofocus
>
</form>
</header>
<section
id=
"main"
ng-show=
"TC.todos.length"
ng-cloak
>
<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"
ng-change=
"TC.todoCompleted(todo)"
>
<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(
todo
)"
></button>
<button
class=
"destroy"
ng-click=
"TC.removeTodo(
$index
)"
></button>
</div>
<form
ng-submit=
"TC.doneEditing(todo)"
>
<input
class=
"edit"
ng-trim=
"false"
ng-model=
"todo.title"
ng-blur=
"TC.doneEditing(todo
)"
todo-escape=
"TC.revertEditing(todo)"
todo-focus=
"todo
== TC.editedTodo"
>
<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"
>
</form>
</li>
</ul>
...
...
examples/angularjs-perf/js/controllers/todoCtrl.js
View file @
6f8b0d9b
...
...
@@ -9,13 +9,13 @@
* - retrieves and persists the model via the todoStorage service
* - exposes the model to the template and provides event handlers
*/
.
controller
(
'
TodoCtrl
'
,
function
TodoCtrl
(
$scope
,
$location
,
$filter
,
todoStorage
)
{
.
controller
(
'
TodoCtrl
'
,
function
TodoCtrl
(
$scope
,
$location
,
todoStorage
)
{
var
TC
=
this
;
var
todos
=
TC
.
todos
=
todoStorage
.
get
();
TC
.
newTodo
=
''
;
TC
.
remainingCount
=
$filter
(
'
filter
'
)(
todos
,
{
completed
:
false
}).
length
;
TC
.
editedTodo
=
null
;
TC
.
newTodo
=
{
title
:
''
,
completed
:
false
}
;
TC
.
editedTodo
=
{}
;
if
(
$location
.
path
()
===
''
)
{
$location
.
path
(
'
/
'
);
...
...
@@ -27,73 +27,61 @@
TC
.
statusFilter
=
{
'
/active
'
:
{
completed
:
false
},
'
/completed
'
:
{
completed
:
true
}
}[
path
];
});
$scope
.
$watch
(
'
TC.remainingCount == 0
'
,
function
(
val
)
{
TC
.
allChecked
=
val
;
});
// 3rd argument `true` for deep object watching
$scope
.
$watch
(
'
TC.todos
'
,
function
()
{
TC
.
remainingCount
=
todos
.
filter
(
function
(
todo
)
{
return
!
todo
.
completed
;
}).
length
;
TC
.
allChecked
=
(
TC
.
remainingCount
===
0
);
// Save any changes to localStorage
todoStorage
.
put
(
todos
);
},
true
);
TC
.
addTodo
=
function
()
{
var
newT
odo
=
TC
.
newTodo
.
trim
();
if
(
newT
odo
.
length
===
0
)
{
var
newT
itle
=
TC
.
newTodo
.
title
=
TC
.
newTodo
.
title
.
trim
();
if
(
newT
itle
.
length
===
0
)
{
return
;
}
todos
.
push
({
title
:
newTodo
,
completed
:
false
});
todoStorage
.
put
(
todos
);
todos
.
push
(
TC
.
newTodo
);
TC
.
newTodo
=
''
;
TC
.
remainingCount
++
;
TC
.
newTodo
=
{
title
:
''
,
completed
:
false
};
};
TC
.
editTodo
=
function
(
todo
)
{
TC
.
editedTodo
=
todo
;
// Clone the original todo to restore it on demand.
TC
.
originalTodo
=
angular
.
extend
({},
todo
);
TC
.
originalTodo
=
angular
.
copy
(
todo
);
};
TC
.
doneEditing
=
function
(
todo
)
{
TC
.
editedTodo
=
null
;
TC
.
doneEditing
=
function
(
todo
,
index
)
{
TC
.
editedTodo
=
{}
;
todo
.
title
=
todo
.
title
.
trim
();
if
(
!
todo
.
title
)
{
TC
.
removeTodo
(
todo
);
TC
.
removeTodo
(
index
);
}
todoStorage
.
put
(
todos
);
};
TC
.
revertEditing
=
function
(
todo
)
{
todos
[
todos
.
indexOf
(
todo
)
]
=
TC
.
originalTodo
;
TC
.
revertEditing
=
function
(
index
)
{
todos
[
index
]
=
TC
.
originalTodo
;
TC
.
doneEditing
(
TC
.
originalTodo
);
};
TC
.
removeTodo
=
function
(
todo
)
{
TC
.
remainingCount
-=
todo
.
completed
?
0
:
1
;
todos
.
splice
(
todos
.
indexOf
(
todo
),
1
);
todoStorage
.
put
(
todos
);
};
TC
.
todoCompleted
=
function
(
todo
)
{
TC
.
remainingCount
+=
todo
.
completed
?
-
1
:
1
;
todoStorage
.
put
(
todos
);
TC
.
removeTodo
=
function
(
index
)
{
todos
.
splice
(
index
,
1
);
};
TC
.
clearCompletedTodos
=
function
()
{
TC
.
todos
=
todos
=
todos
.
filter
(
function
(
val
)
{
return
!
val
.
completed
;
});
todoStorage
.
put
(
todos
);
};
TC
.
markAll
=
function
(
completed
)
{
todos
.
forEach
(
function
(
todo
)
{
todo
.
completed
=
completed
;
});
TC
.
remainingCount
=
completed
?
0
:
todos
.
length
;
todoStorage
.
put
(
todos
);
};
});
})();
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment