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
fdcac4ed
Commit
fdcac4ed
authored
Aug 03, 2012
by
Addy Osmani
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #256 from Atinux/master
Improvements in Backbone.js application
parents
29732c99
ab586ed8
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
29 additions
and
57 deletions
+29
-57
architecture-examples/backbone/js/models/todo.js
architecture-examples/backbone/js/models/todo.js
+2
-15
architecture-examples/backbone/js/views/app.js
architecture-examples/backbone/js/views/app.js
+6
-5
architecture-examples/backbone/js/views/todos.js
architecture-examples/backbone/js/views/todos.js
+6
-8
dependency-examples/backbone_require/js/models/todo.js
dependency-examples/backbone_require/js/models/todo.js
+2
-15
dependency-examples/backbone_require/js/views/app.js
dependency-examples/backbone_require/js/views/app.js
+6
-5
dependency-examples/backbone_require/js/views/todos.js
dependency-examples/backbone_require/js/views/todos.js
+7
-9
No files found.
architecture-examples/backbone/js/models/todo.js
View file @
fdcac4ed
...
...
@@ -7,31 +7,18 @@
// Our basic **Todo** model has `title`, `order`, and `completed` attributes.
window
.
app
.
Todo
=
Backbone
.
Model
.
extend
({
// Default attributes for the todo.
// Default attributes for the todo
// and ensure that each todo created has `title` and `completed` keys.
defaults
:
{
title
:
''
,
completed
:
false
},
// Ensure that each todo created has `title`.
initialize
:
function
()
{
if
(
!
this
.
get
(
'
title
'
)
)
{
this
.
set
({
'
title
'
:
this
.
defaults
.
title
});
}
},
// Toggle the `completed` state of this todo item.
toggle
:
function
()
{
this
.
save
({
completed
:
!
this
.
get
(
'
completed
'
)
});
},
// Remove this Todo from *localStorage* and delete its view.
clear
:
function
()
{
this
.
destroy
();
}
});
...
...
architecture-examples/backbone/js/views/app.js
View file @
fdcac4ed
...
...
@@ -9,7 +9,7 @@ $(function( $ ) {
// Instead of generating a new element, bind to the existing skeleton of
// the App already present in the HTML.
el
:
$
(
'
#todoapp
'
)
,
el
:
'
#todoapp
'
,
// Our template for the line of statistics at the bottom of the app.
statsTemplate
:
_
.
template
(
$
(
'
#stats-template
'
).
html
()
),
...
...
@@ -28,12 +28,13 @@ $(function( $ ) {
this
.
input
=
this
.
$
(
'
#new-todo
'
);
this
.
allCheckbox
=
this
.
$
(
'
#toggle-all
'
)[
0
];
window
.
app
.
Todos
.
on
(
'
add
'
,
this
.
add
One
,
this
);
window
.
app
.
Todos
.
on
(
'
add
'
,
this
.
add
All
,
this
);
window
.
app
.
Todos
.
on
(
'
reset
'
,
this
.
addAll
,
this
);
window
.
app
.
Todos
.
on
(
'
change:completed
'
,
this
.
addAll
,
this
);
window
.
app
.
Todos
.
on
(
'
all
'
,
this
.
render
,
this
);
this
.
$footer
=
$
(
'
#footer
'
);
this
.
$main
=
$
(
'
#main
'
);
this
.
$footer
=
this
.
$
(
'
#footer
'
);
this
.
$main
=
this
.
$
(
'
#main
'
);
window
.
app
.
Todos
.
fetch
();
},
...
...
@@ -112,7 +113,7 @@ $(function( $ ) {
// Clear all completed todo items, destroying their models.
clearCompleted
:
function
()
{
_
.
each
(
window
.
app
.
Todos
.
completed
(),
function
(
todo
)
{
todo
.
clear
();
todo
.
destroy
();
});
return
false
;
...
...
architecture-examples/backbone/js/views/todos.js
View file @
fdcac4ed
...
...
@@ -32,10 +32,8 @@ $(function() {
// Re-render the titles of the todo item.
render
:
function
()
{
var
$el
=
$
(
this
.
el
);
$el
.
html
(
this
.
template
(
this
.
model
.
toJSON
()
)
);
$el
.
toggleClass
(
'
completed
'
,
this
.
model
.
get
(
'
completed
'
)
);
this
.
$el
.
html
(
this
.
template
(
this
.
model
.
toJSON
()
)
);
this
.
$el
.
toggleClass
(
'
completed
'
,
this
.
model
.
get
(
'
completed
'
)
);
this
.
input
=
this
.
$
(
'
.edit
'
);
return
this
;
...
...
@@ -48,7 +46,7 @@ $(function() {
// Switch this view into `"editing"` mode, displaying the input field.
edit
:
function
()
{
$
(
this
.
el
)
.
addClass
(
'
editing
'
);
this
.
$el
.
addClass
(
'
editing
'
);
this
.
input
.
focus
();
},
...
...
@@ -62,7 +60,7 @@ $(function() {
this
.
clear
();
}
$
(
this
.
el
)
.
removeClass
(
'
editing
'
);
this
.
$el
.
removeClass
(
'
editing
'
);
},
// If you hit `enter`, we're through editing the item.
...
...
@@ -72,9 +70,9 @@ $(function() {
}
},
// Remove the item, destroy the model.
// Remove the item, destroy the model
from *localStorage* and delete its view
.
clear
:
function
()
{
this
.
model
.
clear
();
this
.
model
.
destroy
();
}
});
});
dependency-examples/backbone_require/js/models/todo.js
View file @
fdcac4ed
...
...
@@ -4,31 +4,18 @@ define([
],
function
(
_
,
Backbone
)
{
var
TodoModel
=
Backbone
.
Model
.
extend
({
// Default attributes for the todo.
// Default attributes for the todo
// and ensure that each todo created has `title` and `completed` keys.
defaults
:
{
title
:
''
,
completed
:
false
},
// Ensure that each todo created has `title`.
initialize
:
function
()
{
if
(
!
this
.
get
(
'
title
'
)
)
{
this
.
set
({
'
title
'
:
this
.
defaults
.
title
});
}
},
// Toggle the `completed` state of this todo item.
toggle
:
function
()
{
this
.
save
({
completed
:
!
this
.
get
(
'
completed
'
)
});
},
// Remove this Todo from *localStorage* and delete its view.
clear
:
function
()
{
this
.
destroy
();
}
});
...
...
dependency-examples/backbone_require/js/views/app.js
View file @
fdcac4ed
...
...
@@ -12,7 +12,7 @@ define([
// Instead of generating a new element, bind to the existing skeleton of
// the App already present in the HTML.
el
:
$
(
'
#todoapp
'
)
,
el
:
'
#todoapp
'
,
// Compile our stats template
template
:
_
.
template
(
statsTemplate
),
...
...
@@ -30,11 +30,12 @@ define([
initialize
:
function
()
{
this
.
input
=
this
.
$
(
'
#new-todo
'
);
this
.
allCheckbox
=
this
.
$
(
'
#toggle-all
'
)[
0
];
this
.
$footer
=
$
(
'
#footer
'
);
this
.
$main
=
$
(
'
#main
'
);
this
.
$footer
=
this
.
$
(
'
#footer
'
);
this
.
$main
=
this
.
$
(
'
#main
'
);
Todos
.
on
(
'
add
'
,
this
.
add
One
,
this
);
Todos
.
on
(
'
add
'
,
this
.
add
All
,
this
);
Todos
.
on
(
'
reset
'
,
this
.
addAll
,
this
);
Todos
.
on
(
'
change:completed
'
,
this
.
addAll
,
this
);
Todos
.
on
(
'
all
'
,
this
.
render
,
this
);
Todos
.
fetch
();
},
...
...
@@ -113,7 +114,7 @@ define([
// Clear all completed todo items, destroying their models.
clearCompleted
:
function
()
{
_
.
each
(
Todos
.
completed
(),
function
(
todo
)
{
todo
.
clear
();
todo
.
destroy
();
});
return
false
;
...
...
dependency-examples/backbone_require/js/views/todos.js
View file @
fdcac4ed
...
...
@@ -31,10 +31,8 @@ define([
// Re-render the titles of the todo item.
render
:
function
()
{
var
$el
=
$
(
this
.
el
);
$el
.
html
(
this
.
template
(
this
.
model
.
toJSON
()
)
);
$el
.
toggleClass
(
'
completed
'
,
this
.
model
.
get
(
'
completed
'
)
);
this
.
$el
.
html
(
this
.
template
(
this
.
model
.
toJSON
()
)
);
this
.
$el
.
toggleClass
(
'
completed
'
,
this
.
model
.
get
(
'
completed
'
)
);
this
.
input
=
this
.
$
(
'
.edit
'
);
return
this
;
...
...
@@ -47,7 +45,7 @@ define([
// Switch this view into `"editing"` mode, displaying the input field.
edit
:
function
()
{
$
(
this
.
el
)
.
addClass
(
'
editing
'
);
this
.
$el
.
addClass
(
'
editing
'
);
this
.
input
.
focus
();
},
...
...
@@ -61,7 +59,7 @@ define([
this
.
clear
();
}
$
(
this
.
el
)
.
removeClass
(
'
editing
'
);
this
.
$el
.
removeClass
(
'
editing
'
);
},
// If you hit `enter`, we're through editing the item.
...
...
@@ -71,11 +69,11 @@ define([
}
},
// Remove the item, destroy the model.
// Remove the item, destroy the model
from *localStorage* and delete its view
.
clear
:
function
()
{
this
.
model
.
clear
();
this
.
model
.
destroy
();
}
});
return
TodoView
;
});
});
\ No newline at end of file
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