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
9afa4e96
Commit
9afa4e96
authored
May 24, 2014
by
Sindre Sorhus
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #903 from tomhaggie/gh-pages
Typescript switched from bool to boolean
parents
4da42bc1
04077d98
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
49 additions
and
28 deletions
+49
-28
labs/architecture-examples/typescript-backbone/js/app.js
labs/architecture-examples/typescript-backbone/js/app.js
+47
-26
labs/architecture-examples/typescript-backbone/js/app.ts
labs/architecture-examples/typescript-backbone/js/app.ts
+2
-2
No files found.
labs/architecture-examples/typescript-backbone/js/app.js
View file @
9afa4e96
var
__extends
=
this
.
__extends
||
function
(
d
,
b
)
{
var
__extends
=
this
.
__extends
||
function
(
d
,
b
)
{
for
(
var
p
in
b
)
if
(
b
.
hasOwnProperty
(
p
))
d
[
p
]
=
b
[
p
];
function
__
()
{
this
.
constructor
=
d
;
}
function
__
()
{
this
.
constructor
=
d
;
}
__
.
prototype
=
b
.
prototype
;
__
.
prototype
=
b
.
prototype
;
d
.
prototype
=
new
__
();
d
.
prototype
=
new
__
();
};
};
var
Todo
=
(
function
(
_super
)
{
var
Todo
=
(
function
(
_super
)
{
__extends
(
Todo
,
_super
);
__extends
(
Todo
,
_super
);
function
Todo
()
{
function
Todo
()
{
_super
.
apply
(
this
,
arguments
);
_super
.
apply
(
this
,
arguments
);
}
}
Todo
.
prototype
.
defaults
=
function
()
{
Todo
.
prototype
.
defaults
=
function
()
{
return
{
return
{
...
@@ -15,28 +16,27 @@ var Todo = (function (_super) {
...
@@ -15,28 +16,27 @@ var Todo = (function (_super) {
done
:
false
done
:
false
};
};
};
};
Todo
.
prototype
.
initialize
=
function
()
{
Todo
.
prototype
.
initialize
=
function
()
{
if
(
!
this
.
get
(
'
content
'
))
{
if
(
!
this
.
get
(
'
content
'
))
{
this
.
set
({
this
.
set
({
'
content
'
:
this
.
defaults
().
content
});
'
content
'
:
this
.
defaults
().
content
});
}
}
};
};
Todo
.
prototype
.
toggle
=
function
()
{
Todo
.
prototype
.
toggle
=
function
()
{
this
.
save
({
this
.
save
({
done
:
!
this
.
get
(
'
done
'
)
});
done
:
!
this
.
get
(
'
done
'
)
});
};
};
Todo
.
prototype
.
clear
=
function
()
{
Todo
.
prototype
.
clear
=
function
()
{
this
.
destroy
();
this
.
destroy
();
};
};
return
Todo
;
return
Todo
;
})(
Backbone
.
Model
);
})(
Backbone
.
Model
);
var
TodoList
=
(
function
(
_super
)
{
var
TodoList
=
(
function
(
_super
)
{
__extends
(
TodoList
,
_super
);
__extends
(
TodoList
,
_super
);
function
TodoList
()
{
function
TodoList
()
{
_super
.
apply
(
this
,
arguments
);
_super
.
apply
(
this
,
arguments
);
this
.
model
=
Todo
;
this
.
model
=
Todo
;
this
.
localStorage
=
new
Store
(
'
todos-typescript-backbone
'
);
this
.
localStorage
=
new
Store
(
'
todos-typescript-backbone
'
);
}
}
...
@@ -45,25 +45,30 @@ var TodoList = (function (_super) {
...
@@ -45,25 +45,30 @@ var TodoList = (function (_super) {
return
todo
.
get
(
'
done
'
);
return
todo
.
get
(
'
done
'
);
});
});
};
};
TodoList
.
prototype
.
remaining
=
function
()
{
TodoList
.
prototype
.
remaining
=
function
()
{
return
this
.
without
.
apply
(
this
,
this
.
done
());
return
this
.
without
.
apply
(
this
,
this
.
done
());
};
};
TodoList
.
prototype
.
nextOrder
=
function
()
{
TodoList
.
prototype
.
nextOrder
=
function
()
{
if
(
!
length
)
{
if
(
!
length
)
return
1
;
return
1
;
}
return
this
.
last
().
get
(
'
order
'
)
+
1
;
return
this
.
last
().
get
(
'
order
'
)
+
1
;
};
};
TodoList
.
prototype
.
comparator
=
function
(
todo
)
{
TodoList
.
prototype
.
comparator
=
function
(
todo
)
{
return
todo
.
get
(
'
order
'
);
return
todo
.
get
(
'
order
'
);
};
};
return
TodoList
;
return
TodoList
;
})(
Backbone
.
Collection
);
})(
Backbone
.
Collection
);
var
Todos
=
new
TodoList
();
var
Todos
=
new
TodoList
();
var
TodoView
=
(
function
(
_super
)
{
var
TodoView
=
(
function
(
_super
)
{
__extends
(
TodoView
,
_super
);
__extends
(
TodoView
,
_super
);
function
TodoView
(
options
)
{
function
TodoView
(
options
)
{
this
.
tagName
=
'
li
'
;
this
.
tagName
=
'
li
'
;
this
.
events
=
{
this
.
events
=
{
'
click .check
'
:
'
toggleDone
'
,
'
click .check
'
:
'
toggleDone
'
,
'
dblclick label.todo-content
'
:
'
edit
'
,
'
dblclick label.todo-content
'
:
'
edit
'
,
...
@@ -71,41 +76,47 @@ var TodoView = (function (_super) {
...
@@ -71,41 +76,47 @@ var TodoView = (function (_super) {
'
keypress .todo-input
'
:
'
updateOnEnter
'
,
'
keypress .todo-input
'
:
'
updateOnEnter
'
,
'
blur .todo-input
'
:
'
close
'
'
blur .todo-input
'
:
'
close
'
};
};
_super
.
call
(
this
,
options
);
_super
.
call
(
this
,
options
);
this
.
template
=
_
.
template
(
$
(
'
#item-template
'
).
html
());
this
.
template
=
_
.
template
(
$
(
'
#item-template
'
).
html
());
_
.
bindAll
(
this
,
'
render
'
,
'
close
'
,
'
remove
'
);
_
.
bindAll
(
this
,
'
render
'
,
'
close
'
,
'
remove
'
);
this
.
model
.
bind
(
'
change
'
,
this
.
render
);
this
.
model
.
bind
(
'
change
'
,
this
.
render
);
this
.
model
.
bind
(
'
destroy
'
,
this
.
remove
);
this
.
model
.
bind
(
'
destroy
'
,
this
.
remove
);
}
}
TodoView
.
ENTER_KEY
=
13
;
TodoView
.
prototype
.
render
=
function
()
{
TodoView
.
prototype
.
render
=
function
()
{
this
.
$el
.
html
(
this
.
template
(
this
.
model
.
toJSON
()));
this
.
$el
.
html
(
this
.
template
(
this
.
model
.
toJSON
()));
this
.
input
=
this
.
$
(
'
.todo-input
'
);
this
.
input
=
this
.
$
(
'
.todo-input
'
);
return
this
;
return
this
;
};
};
TodoView
.
prototype
.
toggleDone
=
function
()
{
TodoView
.
prototype
.
toggleDone
=
function
()
{
this
.
model
.
toggle
();
this
.
model
.
toggle
();
};
};
TodoView
.
prototype
.
edit
=
function
()
{
TodoView
.
prototype
.
edit
=
function
()
{
this
.
$el
.
addClass
(
'
editing
'
);
this
.
$el
.
addClass
(
'
editing
'
);
this
.
input
.
focus
();
this
.
input
.
focus
();
};
};
TodoView
.
prototype
.
close
=
function
()
{
TodoView
.
prototype
.
close
=
function
()
{
this
.
model
.
save
({
this
.
model
.
save
({
content
:
this
.
input
.
val
()
});
content
:
this
.
input
.
val
()
});
this
.
$el
.
removeClass
(
'
editing
'
);
this
.
$el
.
removeClass
(
'
editing
'
);
};
};
TodoView
.
prototype
.
updateOnEnter
=
function
(
e
)
{
TodoView
.
prototype
.
updateOnEnter
=
function
(
e
)
{
if
(
e
.
keyCode
==
TodoView
.
ENTER_KEY
)
{
if
(
e
.
keyCode
==
TodoView
.
ENTER_KEY
)
close
();
close
();
}
};
};
TodoView
.
prototype
.
clear
=
function
()
{
TodoView
.
prototype
.
clear
=
function
()
{
this
.
model
.
clear
();
this
.
model
.
clear
();
};
};
TodoView
.
ENTER_KEY
=
13
;
return
TodoView
;
return
TodoView
;
})(
Backbone
.
View
);
})(
Backbone
.
View
);
var
AppView
=
(
function
(
_super
)
{
var
AppView
=
(
function
(
_super
)
{
__extends
(
AppView
,
_super
);
__extends
(
AppView
,
_super
);
function
AppView
()
{
function
AppView
()
{
...
@@ -115,24 +126,31 @@ var AppView = (function (_super) {
...
@@ -115,24 +126,31 @@ var AppView = (function (_super) {
'
click .todo-clear button
'
:
'
clearCompleted
'
,
'
click .todo-clear button
'
:
'
clearCompleted
'
,
'
click .mark-all-done
'
:
'
toggleAllComplete
'
'
click .mark-all-done
'
:
'
toggleAllComplete
'
};
};
this
.
setElement
(
$
(
'
#todoapp
'
),
true
);
this
.
setElement
(
$
(
'
#todoapp
'
),
true
);
_
.
bindAll
(
this
,
'
addOne
'
,
'
addAll
'
,
'
render
'
,
'
toggleAllComplete
'
);
_
.
bindAll
(
this
,
'
addOne
'
,
'
addAll
'
,
'
render
'
,
'
toggleAllComplete
'
);
this
.
input
=
this
.
$
(
'
#new-todo
'
);
this
.
input
=
this
.
$
(
'
#new-todo
'
);
this
.
allCheckbox
=
this
.
$
(
'
.mark-all-done
'
)[
0
];
this
.
allCheckbox
=
this
.
$
(
'
.mark-all-done
'
)[
0
];
this
.
mainElement
=
this
.
$
(
'
#main
'
)[
0
];
this
.
mainElement
=
this
.
$
(
'
#main
'
)[
0
];
this
.
footerElement
=
this
.
$
(
'
#footer
'
)[
0
];
this
.
footerElement
=
this
.
$
(
'
#footer
'
)[
0
];
this
.
statsTemplate
=
_
.
template
(
$
(
'
#stats-template
'
).
html
());
this
.
statsTemplate
=
_
.
template
(
$
(
'
#stats-template
'
).
html
());
Todos
.
bind
(
'
add
'
,
this
.
addOne
);
Todos
.
bind
(
'
add
'
,
this
.
addOne
);
Todos
.
bind
(
'
reset
'
,
this
.
addAll
);
Todos
.
bind
(
'
reset
'
,
this
.
addAll
);
Todos
.
bind
(
'
all
'
,
this
.
render
);
Todos
.
bind
(
'
all
'
,
this
.
render
);
Todos
.
fetch
();
Todos
.
fetch
();
}
}
AppView
.
prototype
.
render
=
function
()
{
AppView
.
prototype
.
render
=
function
()
{
var
done
=
Todos
.
done
().
length
;
var
done
=
Todos
.
done
().
length
;
var
remaining
=
Todos
.
remaining
().
length
;
var
remaining
=
Todos
.
remaining
().
length
;
if
(
Todos
.
length
)
{
if
(
Todos
.
length
)
{
this
.
mainElement
.
style
.
display
=
'
block
'
;
this
.
mainElement
.
style
.
display
=
'
block
'
;
this
.
footerElement
.
style
.
display
=
'
block
'
;
this
.
footerElement
.
style
.
display
=
'
block
'
;
this
.
$
(
'
#todo-stats
'
).
html
(
this
.
statsTemplate
({
this
.
$
(
'
#todo-stats
'
).
html
(
this
.
statsTemplate
({
total
:
Todos
.
length
,
total
:
Todos
.
length
,
done
:
done
,
done
:
done
,
...
@@ -142,17 +160,19 @@ var AppView = (function (_super) {
...
@@ -142,17 +160,19 @@ var AppView = (function (_super) {
this
.
mainElement
.
style
.
display
=
'
none
'
;
this
.
mainElement
.
style
.
display
=
'
none
'
;
this
.
footerElement
.
style
.
display
=
'
none
'
;
this
.
footerElement
.
style
.
display
=
'
none
'
;
}
}
this
.
allCheckbox
.
checked
=
!
remaining
;
this
.
allCheckbox
.
checked
=
!
remaining
;
};
};
AppView
.
prototype
.
addOne
=
function
(
todo
)
{
AppView
.
prototype
.
addOne
=
function
(
todo
)
{
var
view
=
new
TodoView
({
var
view
=
new
TodoView
({
model
:
todo
});
model
:
todo
});
this
.
$
(
'
#todo-list
'
).
append
(
view
.
render
().
el
);
this
.
$
(
'
#todo-list
'
).
append
(
view
.
render
().
el
);
};
};
AppView
.
prototype
.
addAll
=
function
()
{
AppView
.
prototype
.
addAll
=
function
()
{
Todos
.
each
(
this
.
addOne
);
Todos
.
each
(
this
.
addOne
);
};
};
AppView
.
prototype
.
newAttributes
=
function
()
{
AppView
.
prototype
.
newAttributes
=
function
()
{
return
{
return
{
content
:
this
.
input
.
val
(),
content
:
this
.
input
.
val
(),
...
@@ -160,29 +180,30 @@ var AppView = (function (_super) {
...
@@ -160,29 +180,30 @@ var AppView = (function (_super) {
done
:
false
done
:
false
};
};
};
};
AppView
.
prototype
.
createOnEnter
=
function
(
e
)
{
AppView
.
prototype
.
createOnEnter
=
function
(
e
)
{
if
(
e
.
keyCode
!=
13
)
{
if
(
e
.
keyCode
!=
13
)
return
;
return
;
}
Todos
.
create
(
this
.
newAttributes
());
Todos
.
create
(
this
.
newAttributes
());
this
.
input
.
val
(
''
);
this
.
input
.
val
(
''
);
};
};
AppView
.
prototype
.
clearCompleted
=
function
()
{
AppView
.
prototype
.
clearCompleted
=
function
()
{
_
.
each
(
Todos
.
done
(),
function
(
todo
)
{
_
.
each
(
Todos
.
done
(),
function
(
todo
)
{
return
todo
.
clear
();
return
todo
.
clear
();
});
});
return
false
;
return
false
;
};
};
AppView
.
prototype
.
toggleAllComplete
=
function
()
{
AppView
.
prototype
.
toggleAllComplete
=
function
()
{
var
done
=
this
.
allCheckbox
.
checked
;
var
done
=
this
.
allCheckbox
.
checked
;
Todos
.
each
(
function
(
todo
)
{
Todos
.
each
(
function
(
todo
)
{
return
todo
.
save
({
return
todo
.
save
({
'
done
'
:
done
});
'
done
'
:
done
});
});
});
};
};
return
AppView
;
return
AppView
;
})(
Backbone
.
View
);
})(
Backbone
.
View
);
$
(
function
()
{
$
(
function
()
{
new
AppView
();
new
AppView
();
});
});
labs/architecture-examples/typescript-backbone/js/app.ts
View file @
9afa4e96
...
@@ -79,7 +79,7 @@ declare module Backbone {
...
@@ -79,7 +79,7 @@ declare module Backbone {
remove
():
void
;
remove
():
void
;
delegateEvents
:
any
;
delegateEvents
:
any
;
make
(
tagName
:
string
,
attrs
?
,
opts
?
):
View
;
make
(
tagName
:
string
,
attrs
?
,
opts
?
):
View
;
setElement
(
element
:
HTMLElement
,
delegate
?:
bool
):
void
;
setElement
(
element
:
HTMLElement
,
delegate
?:
bool
ean
):
void
;
tagName
:
string
;
tagName
:
string
;
events
:
any
;
events
:
any
;
...
@@ -102,7 +102,7 @@ class Todo extends Backbone.Model {
...
@@ -102,7 +102,7 @@ class Todo extends Backbone.Model {
content
:
''
,
content
:
''
,
done
:
false
done
:
false
}
}
}
;
}
// Ensure that each todo created has `content`.
// Ensure that each todo created has `content`.
initialize
()
{
initialize
()
{
...
...
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