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
Sven Franck
todomvc
Commits
2206d218
Commit
2206d218
authored
Mar 28, 2015
by
Arthur Verschaeve
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
typescript-backbone: use correct variable names
Ref #359 Close #1237
parent
c0762487
Changes
3
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
64 additions
and
101 deletions
+64
-101
examples/typescript-backbone/index.html
examples/typescript-backbone/index.html
+6
-6
examples/typescript-backbone/js/app.js
examples/typescript-backbone/js/app.js
+34
-71
examples/typescript-backbone/js/app.ts
examples/typescript-backbone/js/app.ts
+24
-24
No files found.
examples/typescript-backbone/index.html
View file @
2206d218
...
...
@@ -77,13 +77,13 @@ https://github.com/documentcloud/backbone/blob/master/examples/todos/index.html
<!-- Templates -->
<script
type=
"text/template"
id=
"item-template"
>
<
div
class
=
"
todo <%=
done
? 'done' : '' %>
"
>
<
div
class
=
"
todo <%=
completed
? 'done' : '' %>
"
>
<
div
class
=
"
view display
"
>
<
input
class
=
"
toggle check
"
type
=
"
checkbox
"
<%=
done
?
'
checked
'
:
''
%>>
<
label
class
=
"
todo-content
"
><%=
content
%><
/label
>
<
input
class
=
"
toggle check
"
type
=
"
checkbox
"
<%=
completed
?
'
checked
'
:
''
%>>
<
label
class
=
"
todo-content
"
><%=
title
%><
/label
>
<
button
class
=
"
destroy
"
><
/button
>
<
/div
>
<
input
class
=
"
edit todo-input
"
value
=
"
<%=
content
%>
"
>
<
input
class
=
"
edit todo-input
"
value
=
"
<%=
title
%>
"
>
<
/div
>
</script>
...
...
@@ -94,9 +94,9 @@ https://github.com/documentcloud/backbone/blob/master/examples/todos/index.html
<
span
class
=
"
word
"
><%=
remaining
==
1
?
'
item
'
:
'
items
'
%><
/span> lef
t
<
/span
>
<%
}
%>
<%
if
(
done
)
{
%>
<%
if
(
completed
)
{
%>
<
span
class
=
"
todo-clear
"
>
<
button
id
=
"
clear-completed
"
>
Clear
completed
(
<
span
class
=
"
number-done
"
><%=
done
%><
/span>
)
</
button
>
<
button
id
=
"
clear-completed
"
>
Clear
completed
(
<
span
class
=
"
number-done
"
><%=
completed
%><
/span>
)
</
button
>
<
/span
>
<%
}
%>
</script>
...
...
examples/typescript-backbone/js/app.js
View file @
2206d218
This diff is collapsed.
Click to expand it.
examples/typescript-backbone/js/app.ts
View file @
2206d218
...
...
@@ -93,27 +93,27 @@ declare var Store: any;
// Todo Model
// ----------
// Our basic **Todo** model has `
content`, `order`, and `done
` attributes.
// Our basic **Todo** model has `
title`, `order`, and `completed
` attributes.
class
Todo
extends
Backbone
.
Model
{
// Default attributes for the todo.
defaults
()
{
return
{
content
:
''
,
done
:
false
title
:
''
,
completed
:
false
}
}
// Ensure that each todo created has `
content
`.
// Ensure that each todo created has `
title
`.
initialize
()
{
if
(
!
this
.
get
(
'
content
'
))
{
this
.
set
({
'
content
'
:
this
.
defaults
().
content
});
if
(
!
this
.
get
(
'
title
'
))
{
this
.
set
({
'
title
'
:
this
.
defaults
().
title
});
}
}
// Toggle the `
done
` state of this todo item.
// Toggle the `
completed
` state of this todo item.
toggle
()
{
this
.
save
({
done
:
!
this
.
get
(
'
done
'
)
});
this
.
save
({
completed
:
!
this
.
get
(
'
completed
'
)
});
}
// Remove this Todo from *localStorage* and delete its view.
...
...
@@ -136,14 +136,14 @@ class TodoList extends Backbone.Collection {
// Save all of the todo items under the `'todos'` namespace.
localStorage
=
new
Store
(
'
todos-typescript-backbone
'
);
// Filter down the list of all todo items that are
finish
ed.
done
()
{
return
this
.
filter
((
todo
:
Todo
)
=>
todo
.
get
(
'
done
'
));
// Filter down the list of all todo items that are
complet
ed.
completed
()
{
return
this
.
filter
((
todo
:
Todo
)
=>
todo
.
get
(
'
completed
'
));
}
// Filter down the list to only todo items that are still not
finish
ed.
// Filter down the list to only todo items that are still not
complet
ed.
remaining
()
{
return
this
.
without
.
apply
(
this
,
this
.
done
());
return
this
.
without
.
apply
(
this
,
this
.
completed
());
}
// We keep the Todos in sequential order, despite being saved by unordered
...
...
@@ -212,7 +212,7 @@ class TodoView extends Backbone.View {
return
this
;
}
// Toggle the `
'done'
` state of the model.
// Toggle the `
completed
` state of the model.
toggleDone
()
{
this
.
model
.
toggle
();
}
...
...
@@ -228,7 +228,7 @@ class TodoView extends Backbone.View {
var
trimmedValue
=
this
.
input
.
val
().
trim
();
if
(
trimmedValue
)
{
this
.
model
.
save
({
content
:
trimmedValue
});
this
.
model
.
save
({
title
:
trimmedValue
});
}
else
{
this
.
clear
();
}
...
...
@@ -247,7 +247,7 @@ class TodoView extends Backbone.View {
if
(
e
.
which
===
TodoView
.
ESC_KEY
)
{
this
.
$el
.
removeClass
(
'
editing
'
);
// Also reset the hidden input back to the original value.
this
.
input
.
val
(
this
.
model
.
get
(
'
content
'
));
this
.
input
.
val
(
this
.
model
.
get
(
'
title
'
));
}
}
...
...
@@ -304,7 +304,7 @@ class AppView extends Backbone.View {
// Re-rendering the App just means refreshing the statistics -- the rest
// of the app doesn't change.
render
()
{
var
done
=
Todos
.
done
().
length
;
var
completed
=
Todos
.
completed
().
length
;
var
remaining
=
Todos
.
remaining
().
length
;
if
(
Todos
.
length
)
{
...
...
@@ -313,7 +313,7 @@ class AppView extends Backbone.View {
this
.
$
(
'
#todo-stats
'
).
html
(
this
.
statsTemplate
({
total
:
Todos
.
length
,
done
:
done
,
completed
:
completed
,
remaining
:
remaining
}));
}
else
{
...
...
@@ -339,9 +339,9 @@ class AppView extends Backbone.View {
// Generate the attributes for a new Todo item.
newAttributes
()
{
return
{
content
:
this
.
input
.
val
().
trim
(),
title
:
this
.
input
.
val
().
trim
(),
order
:
Todos
.
nextOrder
(),
done
:
false
completed
:
false
};
}
...
...
@@ -354,15 +354,15 @@ class AppView extends Backbone.View {
}
}
// Clear all
done
todo items, destroying their models.
// Clear all
completed
todo items, destroying their models.
clearCompleted
()
{
_
.
each
(
Todos
.
done
(),
(
todo
:
Todo
)
=>
todo
.
clear
());
_
.
each
(
Todos
.
completed
(),
(
todo
:
Todo
)
=>
todo
.
clear
());
return
false
;
}
toggleAllComplete
()
{
var
done
=
this
.
allCheckbox
.
checked
;
Todos
.
each
((
todo
:
Todo
)
=>
todo
.
save
({
'
done
'
:
done
}));
var
completed
=
this
.
allCheckbox
.
checked
;
Todos
.
each
((
todo
:
Todo
)
=>
todo
.
save
({
'
completed
'
:
completed
}));
}
}
...
...
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