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
9555657d
Commit
9555657d
authored
Dec 22, 2015
by
Colin Eberhardt
Committed by
Sam Saccone
Jan 05, 2016
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
code-style - simple fomatting changes
parent
60c78081
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
28 additions
and
2 deletions
+28
-2
examples/angular2/app/app.js
examples/angular2/app/app.js
+3
-1
examples/angular2/app/app.ts
examples/angular2/app/app.ts
+12
-1
examples/angular2/app/services/store.ts
examples/angular2/app/services/store.ts
+13
-0
No files found.
examples/angular2/app/app.js
View file @
9555657d
...
@@ -19,7 +19,9 @@ var TodoApp = (function () {
...
@@ -19,7 +19,9 @@ var TodoApp = (function () {
todo
.
setTitle
(
editedTitle
.
value
);
todo
.
setTitle
(
editedTitle
.
value
);
todo
.
editing
=
false
;
todo
.
editing
=
false
;
};
};
TodoApp
.
prototype
.
cancelEditingTodo
=
function
(
todo
)
{
todo
.
editing
=
false
;
};
TodoApp
.
prototype
.
cancelEditingTodo
=
function
(
todo
)
{
todo
.
editing
=
false
;
};
TodoApp
.
prototype
.
updateEditingTodo
=
function
(
editedTitle
,
todo
)
{
TodoApp
.
prototype
.
updateEditingTodo
=
function
(
editedTitle
,
todo
)
{
editedTitle
=
editedTitle
.
value
.
trim
();
editedTitle
=
editedTitle
.
value
.
trim
();
todo
.
editing
=
false
;
todo
.
editing
=
false
;
...
...
examples/angular2/app/app.ts
View file @
9555657d
...
@@ -10,14 +10,20 @@ const ENTER_KEY = 13;
...
@@ -10,14 +10,20 @@ const ENTER_KEY = 13;
})
})
export
default
class
TodoApp
{
export
default
class
TodoApp
{
todoStore
:
TodoStore
;
todoStore
:
TodoStore
;
constructor
()
{
constructor
()
{
this
.
todoStore
=
new
TodoStore
();
this
.
todoStore
=
new
TodoStore
();
}
}
stopEditing
(
todo
:
Todo
,
editedTitle
)
{
stopEditing
(
todo
:
Todo
,
editedTitle
)
{
todo
.
setTitle
(
editedTitle
.
value
);
todo
.
setTitle
(
editedTitle
.
value
);
todo
.
editing
=
false
;
todo
.
editing
=
false
;
}
}
cancelEditingTodo
(
todo
:
Todo
)
{
todo
.
editing
=
false
;
}
cancelEditingTodo
(
todo
:
Todo
)
{
todo
.
editing
=
false
;
}
updateEditingTodo
(
editedTitle
,
todo
:
Todo
)
{
updateEditingTodo
(
editedTitle
,
todo
:
Todo
)
{
editedTitle
=
editedTitle
.
value
.
trim
();
editedTitle
=
editedTitle
.
value
.
trim
();
todo
.
editing
=
false
;
todo
.
editing
=
false
;
...
@@ -28,18 +34,23 @@ export default class TodoApp {
...
@@ -28,18 +34,23 @@ export default class TodoApp {
todo
.
setTitle
(
editedTitle
);
todo
.
setTitle
(
editedTitle
);
}
}
editTodo
(
todo
:
Todo
)
{
editTodo
(
todo
:
Todo
)
{
todo
.
editing
=
true
;
todo
.
editing
=
true
;
}
}
removeCompleted
()
{
removeCompleted
()
{
this
.
todoStore
.
removeCompleted
();
this
.
todoStore
.
removeCompleted
();
}
}
toggleCompletion
(
todo
:
Todo
)
{
toggleCompletion
(
todo
:
Todo
)
{
this
.
todoStore
.
toggleCompletion
(
todo
);
this
.
todoStore
.
toggleCompletion
(
todo
);
}
}
remove
(
todo
:
Todo
){
remove
(
todo
:
Todo
){
this
.
todoStore
.
remove
(
todo
);
this
.
todoStore
.
remove
(
todo
);
}
}
addTodo
(
$event
,
newtodo
)
{
addTodo
(
$event
,
newtodo
)
{
if
(
$event
.
which
===
ENTER_KEY
&&
newtodo
.
value
.
trim
().
length
)
{
if
(
$event
.
which
===
ENTER_KEY
&&
newtodo
.
value
.
trim
().
length
)
{
this
.
todoStore
.
add
(
newtodo
.
value
);
this
.
todoStore
.
add
(
newtodo
.
value
);
...
...
examples/angular2/app/services/store.ts
View file @
9555657d
...
@@ -2,9 +2,11 @@ export class Todo {
...
@@ -2,9 +2,11 @@ export class Todo {
completed
:
Boolean
;
completed
:
Boolean
;
editing
:
Boolean
;
editing
:
Boolean
;
title
:
String
;
title
:
String
;
setTitle
(
title
:
String
)
{
setTitle
(
title
:
String
)
{
this
.
title
=
title
.
trim
();
this
.
title
=
title
.
trim
();
}
}
constructor
(
title
:
String
)
{
constructor
(
title
:
String
)
{
this
.
completed
=
false
;
this
.
completed
=
false
;
this
.
editing
=
false
;
this
.
editing
=
false
;
...
@@ -14,6 +16,7 @@ export class Todo {
...
@@ -14,6 +16,7 @@ export class Todo {
export
class
TodoStore
{
export
class
TodoStore
{
todos
:
Array
<
Todo
>
;
todos
:
Array
<
Todo
>
;
constructor
()
{
constructor
()
{
let
persistedTodos
=
JSON
.
parse
(
localStorage
.
getItem
(
'
angular2-todos
'
)
||
'
[]
'
);
let
persistedTodos
=
JSON
.
parse
(
localStorage
.
getItem
(
'
angular2-todos
'
)
||
'
[]
'
);
// Normalize back into classes
// Normalize back into classes
...
@@ -23,36 +26,46 @@ export class TodoStore {
...
@@ -23,36 +26,46 @@ export class TodoStore {
return
ret
;
return
ret
;
});
});
}
}
_updateStore
()
{
_updateStore
()
{
localStorage
.
setItem
(
'
angular2-todos
'
,
JSON
.
stringify
(
this
.
todos
));
localStorage
.
setItem
(
'
angular2-todos
'
,
JSON
.
stringify
(
this
.
todos
));
}
}
get
(
state
:
{
completed
:
Boolean
})
{
get
(
state
:
{
completed
:
Boolean
})
{
return
this
.
todos
.
filter
((
todo
:
Todo
)
=>
todo
.
completed
===
state
.
completed
);
return
this
.
todos
.
filter
((
todo
:
Todo
)
=>
todo
.
completed
===
state
.
completed
);
}
}
allCompleted
()
{
allCompleted
()
{
return
this
.
todos
.
length
===
this
.
getCompleted
().
length
;
return
this
.
todos
.
length
===
this
.
getCompleted
().
length
;
}
}
setAllTo
(
toggler
)
{
setAllTo
(
toggler
)
{
this
.
todos
.
forEach
((
t
:
Todo
)
=>
t
.
completed
=
toggler
.
checked
);
this
.
todos
.
forEach
((
t
:
Todo
)
=>
t
.
completed
=
toggler
.
checked
);
this
.
_updateStore
();
this
.
_updateStore
();
}
}
removeCompleted
()
{
removeCompleted
()
{
this
.
todos
=
this
.
get
({
completed
:
false
});
this
.
todos
=
this
.
get
({
completed
:
false
});
}
}
getRemaining
()
{
getRemaining
()
{
return
this
.
get
({
completed
:
false
});
return
this
.
get
({
completed
:
false
});
}
}
getCompleted
()
{
getCompleted
()
{
return
this
.
get
({
completed
:
true
});
return
this
.
get
({
completed
:
true
});
}
}
toggleCompletion
(
todo
:
Todo
)
{
toggleCompletion
(
todo
:
Todo
)
{
todo
.
completed
=
!
todo
.
completed
;
todo
.
completed
=
!
todo
.
completed
;
this
.
_updateStore
();
this
.
_updateStore
();
}
}
remove
(
todo
:
Todo
)
{
remove
(
todo
:
Todo
)
{
this
.
todos
.
splice
(
this
.
todos
.
indexOf
(
todo
),
1
);
this
.
todos
.
splice
(
this
.
todos
.
indexOf
(
todo
),
1
);
this
.
_updateStore
();
this
.
_updateStore
();
}
}
add
(
title
:
String
)
{
add
(
title
:
String
)
{
this
.
todos
.
push
(
new
Todo
(
title
));
this
.
todos
.
push
(
new
Todo
(
title
));
this
.
_updateStore
();
this
.
_updateStore
();
...
...
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