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
dbe7faa2
Commit
dbe7faa2
authored
Aug 03, 2012
by
Sindre Sorhus
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Backbone app: Improve namespacing
parent
fdcac4ed
Changes
8
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
33 additions
and
26 deletions
+33
-26
architecture-examples/backbone/index.html
architecture-examples/backbone/index.html
+0
-1
architecture-examples/backbone/js/app.js
architecture-examples/backbone/js/app.js
+4
-1
architecture-examples/backbone/js/collections/todos.js
architecture-examples/backbone/js/collections/todos.js
+4
-2
architecture-examples/backbone/js/init.js
architecture-examples/backbone/js/init.js
+0
-5
architecture-examples/backbone/js/models/todo.js
architecture-examples/backbone/js/models/todo.js
+3
-1
architecture-examples/backbone/js/routers/router.js
architecture-examples/backbone/js/routers/router.js
+3
-1
architecture-examples/backbone/js/views/app.js
architecture-examples/backbone/js/views/app.js
+16
-14
architecture-examples/backbone/js/views/todos.js
architecture-examples/backbone/js/views/todos.js
+3
-1
No files found.
architecture-examples/backbone/index.html
View file @
dbe7faa2
...
...
@@ -56,7 +56,6 @@
<script
src=
"js/lib/underscore-min.js"
></script>
<script
src=
"js/lib/backbone-min.js"
></script>
<script
src=
"js/lib/backbone-localstorage.js"
></script>
<script
src=
"js/init.js"
></script>
<script
src=
"js/models/todo.js"
></script>
<script
src=
"js/collections/todos.js"
></script>
<script
src=
"js/views/todos.js"
></script>
...
...
architecture-examples/backbone/js/app.js
View file @
dbe7faa2
var
app
=
app
||
{};
var
ENTER_KEY
=
13
;
$
(
function
()
{
// Kick things off by creating the **App**.
var
App
=
new
window
.
app
.
AppView
;
new
app
.
AppView
()
;
});
architecture-examples/backbone/js/collections/todos.js
View file @
dbe7faa2
var
app
=
app
||
{};
(
function
()
{
'
use strict
'
;
...
...
@@ -9,7 +11,7 @@
var
TodoList
=
Backbone
.
Collection
.
extend
({
// Reference to this collection's model.
model
:
window
.
app
.
Todo
,
model
:
app
.
Todo
,
// Save all of the todo items under the `"todos"` namespace.
localStorage
:
new
Store
(
'
todos-backbone
'
),
...
...
@@ -42,6 +44,6 @@
});
// Create our global collection of **Todos**.
window
.
app
.
Todos
=
new
TodoList
;
app
.
Todos
=
new
TodoList
()
;
}());
architecture-examples/backbone/js/init.js
deleted
100644 → 0
View file @
fdcac4ed
// Constants
var
ENTER_KEY
=
13
;
// Setup namespace for the app
window
.
app
=
window
.
app
||
{};
architecture-examples/backbone/js/models/todo.js
View file @
dbe7faa2
var
app
=
app
||
{};
(
function
()
{
'
use strict
'
;
...
...
@@ -5,7 +7,7 @@
// ----------
// Our basic **Todo** model has `title`, `order`, and `completed` attributes.
window
.
app
.
Todo
=
Backbone
.
Model
.
extend
({
app
.
Todo
=
Backbone
.
Model
.
extend
({
// Default attributes for the todo
// and ensure that each todo created has `title` and `completed` keys.
...
...
architecture-examples/backbone/js/routers/router.js
View file @
dbe7faa2
var
app
=
app
||
{};
(
function
()
{
'
use strict
'
;
...
...
@@ -18,7 +20,7 @@
}
});
window
.
app
.
TodoRouter
=
new
Workspace
();
app
.
TodoRouter
=
new
Workspace
();
Backbone
.
history
.
start
();
}());
architecture-examples/backbone/js/views/app.js
View file @
dbe7faa2
var
app
=
app
||
{};
$
(
function
(
$
)
{
'
use strict
'
;
...
...
@@ -5,7 +7,7 @@ $(function( $ ) {
// ---------------
// Our overall **AppView** is the top-level piece of UI.
window
.
app
.
AppView
=
Backbone
.
View
.
extend
({
app
.
AppView
=
Backbone
.
View
.
extend
({
// Instead of generating a new element, bind to the existing skeleton of
// the App already present in the HTML.
...
...
@@ -36,16 +38,16 @@ $(function( $ ) {
this
.
$footer
=
this
.
$
(
'
#footer
'
);
this
.
$main
=
this
.
$
(
'
#main
'
);
window
.
app
.
Todos
.
fetch
();
app
.
Todos
.
fetch
();
},
// Re-rendering the App just means refreshing the statistics -- the rest
// of the app doesn't change.
render
:
function
()
{
var
completed
=
window
.
app
.
Todos
.
completed
().
length
;
var
remaining
=
window
.
app
.
Todos
.
remaining
().
length
;
var
completed
=
app
.
Todos
.
completed
().
length
;
var
remaining
=
app
.
Todos
.
remaining
().
length
;
if
(
window
.
app
.
Todos
.
length
)
{
if
(
app
.
Todos
.
length
)
{
this
.
$main
.
show
();
this
.
$footer
.
show
();
...
...
@@ -56,7 +58,7 @@ $(function( $ ) {
this
.
$
(
'
#filters li a
'
)
.
removeClass
(
'
selected
'
)
.
filter
(
'
[href="#/
'
+
(
window
.
app
.
TodoFilter
||
''
)
+
'
"]
'
)
.
filter
(
'
[href="#/
'
+
(
app
.
TodoFilter
||
''
)
+
'
"]
'
)
.
addClass
(
'
selected
'
);
}
else
{
this
.
$main
.
hide
();
...
...
@@ -69,7 +71,7 @@ $(function( $ ) {
// Add a single todo item to the list by creating a view for it, and
// appending its element to the `<ul>`.
addOne
:
function
(
todo
)
{
var
view
=
new
window
.
app
.
TodoView
({
model
:
todo
});
var
view
=
new
app
.
TodoView
({
model
:
todo
});
$
(
'
#todo-list
'
).
append
(
view
.
render
().
el
);
},
...
...
@@ -77,15 +79,15 @@ $(function( $ ) {
addAll
:
function
()
{
this
.
$
(
'
#todo-list
'
).
html
(
''
);
switch
(
window
.
app
.
TodoFilter
)
{
switch
(
app
.
TodoFilter
)
{
case
'
active
'
:
_
.
each
(
window
.
app
.
Todos
.
remaining
(),
this
.
addOne
);
_
.
each
(
app
.
Todos
.
remaining
(),
this
.
addOne
);
break
;
case
'
completed
'
:
_
.
each
(
window
.
app
.
Todos
.
completed
(),
this
.
addOne
);
_
.
each
(
app
.
Todos
.
completed
(),
this
.
addOne
);
break
;
default
:
window
.
app
.
Todos
.
each
(
this
.
addOne
,
this
);
app
.
Todos
.
each
(
this
.
addOne
,
this
);
break
;
}
},
...
...
@@ -94,7 +96,7 @@ $(function( $ ) {
newAttributes
:
function
()
{
return
{
title
:
this
.
input
.
val
().
trim
(),
order
:
window
.
app
.
Todos
.
nextOrder
(),
order
:
app
.
Todos
.
nextOrder
(),
completed
:
false
};
},
...
...
@@ -106,7 +108,7 @@ $(function( $ ) {
return
;
}
window
.
app
.
Todos
.
create
(
this
.
newAttributes
()
);
app
.
Todos
.
create
(
this
.
newAttributes
()
);
this
.
input
.
val
(
''
);
},
...
...
@@ -122,7 +124,7 @@ $(function( $ ) {
toggleAllComplete
:
function
()
{
var
completed
=
this
.
allCheckbox
.
checked
;
window
.
app
.
Todos
.
each
(
function
(
todo
)
{
app
.
Todos
.
each
(
function
(
todo
)
{
todo
.
save
({
'
completed
'
:
completed
});
...
...
architecture-examples/backbone/js/views/todos.js
View file @
dbe7faa2
var
app
=
app
||
{};
$
(
function
()
{
'
use strict
'
;
...
...
@@ -5,7 +7,7 @@ $(function() {
// --------------
// The DOM element for a todo item...
window
.
app
.
TodoView
=
Backbone
.
View
.
extend
({
app
.
TodoView
=
Backbone
.
View
.
extend
({
//... is a list tag.
tagName
:
'
li
'
,
...
...
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