Skip to content

Commit

Permalink
Backbone+Require app improvements
Browse files Browse the repository at this point in the history
- Cleanup
- Code style
- Fix bug with removing todo after editing and the todo is empty
- Update dependencies
  • Loading branch information
sindresorhus committed Aug 1, 2012
1 parent 5995093 commit a7a4d9c
Show file tree
Hide file tree
Showing 20 changed files with 478 additions and 2,199 deletions.
10 changes: 7 additions & 3 deletions dependency-examples/backbone_require/index.html
Expand Up @@ -3,9 +3,13 @@
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<title>Backbone.js</title>
<title>Backbone.js + RequireJS • TodoMVC</title>
<link rel="stylesheet" href="../../assets/base.css">
<script data-main="js/main" src="js/libs/require/require.js"></script>
<script src="../../assets/base.js"></script>
<script data-main="js/main" src="js/lib/require/require.js"></script>
<!--[if IE]>
<script src="../../assets/ie.js"></script>
<![endif]-->
</head>
<body>
<section id="todoapp">
Expand All @@ -26,4 +30,4 @@ <h1>todos</h1>
<p>Part of <a href="http://todomvc.com">TodoMVC</a></p>
</footer>
</body>
</html>
</html>
19 changes: 10 additions & 9 deletions dependency-examples/backbone_require/js/collections/todos.js
Expand Up @@ -3,40 +3,41 @@ define([
'backbone',
'lib/backbone/localstorage',
'models/todo'
], function(_, Backbone, Store, Todo){
], function( _, Backbone, Store, Todo ) {

var TodosCollection = Backbone.Collection.extend({

// Reference to this collection's model.
model: Todo,

// Save all of the todo items under the `"todos"` namespace.
localStorage: new Store("todos-backbone"),
localStorage: new Store('todos-backbone'),

// Filter down the list of all todo items that are finished.
completed: function() {
return this.filter(function(todo){ return todo.get('completed'); });
return this.filter(function( todo ) {
return todo.get('completed');
});
},

// Filter down the list to only todo items that are still not finished.
remaining: function() {
return this.without.apply(this, this.completed());
return this.without.apply( this, this.completed() );
},

// We keep the Todos in sequential order, despite being saved by unordered
// GUID in the database. This generates the next order number for new items.
nextOrder: function() {
if ( !this.length ){
if ( !this.length ) {
return 1;
}
return this.last().get('order') + 1;
},

// Todos are sorted by their original insertion order.
comparator: function(todo) {
comparator: function( todo ) {
return todo.get('order');
}

});
return new TodosCollection;

return new TodosCollection();
});
7 changes: 2 additions & 5 deletions dependency-examples/backbone_require/js/common.js
@@ -1,12 +1,9 @@
define([], function(){

define([], function() {
return {
// Which filter are we using?
TodoFilter: "", // empty, active, completed
TodoFilter: '', // empty, active, completed

// What is the enter key constant?
ENTER_KEY: 13
};

});

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Large diffs are not rendered by default.

35 changes: 35 additions & 0 deletions dependency-examples/backbone_require/js/lib/require/require.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit a7a4d9c

Please sign in to comment.