Skip to content

Commit

Permalink
#10 Adding custom model/collection got MongoDB parsing
Browse files Browse the repository at this point in the history
  • Loading branch information
tracend committed Nov 22, 2012
1 parent 928dc2d commit bc1bc0f
Show file tree
Hide file tree
Showing 5 changed files with 65 additions and 3 deletions.
2 changes: 1 addition & 1 deletion build/backbone.app-min.js

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

33 changes: 32 additions & 1 deletion build/backbone.app.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/**@license
* backbone.app <>
* Version: 0.6.0 (Mon, 12 Nov 2012 02:03:37 GMT)
* Version: 0.6.0 (Thu, 22 Nov 2012 12:07:04 GMT)
* License:
*/
(function(_, Backbone) {
Expand Down Expand Up @@ -85,6 +85,22 @@
}
});


// *** Extensions ***

MongoModel = Model.extend({

parse: function( data ){
//console.log(data);
// "normalize" result with proper ids
if(data._id){
data.id = data._id;
delete data._id;
}
return data;
}
});

})(this._, this.Backbone);
(function(_, Backbone) {

Expand Down Expand Up @@ -158,6 +174,21 @@
}
});


// *** Extensions ***

MongoCollection = Collection.extend({

parse: function( data ){
//console.log(data);
// "normalize" result with proper ids
for(var i in data){
data[i].id = data[i]._id;
delete data[i]._id;
}
return data;
}
});
})(this._, this.Backbone);
(function(_, Backbone, $) {

Expand Down
15 changes: 15 additions & 0 deletions lib/app.collection.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,4 +70,19 @@
}
});


// *** Extensions ***

MongoCollection = Collection.extend({

parse: function( data ){
//console.log(data);
// "normalize" result with proper ids
for(var i in data){
data[i].id = data[i]._id;
delete data[i]._id;
}
return data;
}
});
})(this._, this.Backbone);
16 changes: 16 additions & 0 deletions lib/app.model.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,4 +41,20 @@
}
});


// *** Extensions ***

MongoModel = Model.extend({

parse: function( data ){
//console.log(data);
// "normalize" result with proper ids
if(data._id){
data.id = data._id;
delete data._id;
}
return data;
}
});

})(this._, this.Backbone);
2 changes: 1 addition & 1 deletion readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ An APP for your client app using simple conventions in Backbone.js

## Usage

Find the compilled library in the "build/" folder. Choose between the uncompressed and comment annotated **backbone.app.js** and the minified **backbone.app.min.js**
Find the compilled library in the "build/" folder. Choose between the uncompressed and comment annotated **backbone.app.js** and the minified **backbone.app-min.js**

## Build

Expand Down

0 comments on commit bc1bc0f

Please sign in to comment.