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