Skip to content

Commit

Permalink
#3 common initialize for Model/Collection
Browse files Browse the repository at this point in the history
  • Loading branch information
tracend committed Jul 10, 2013
1 parent f7b4bce commit 86cee9d
Showing 1 changed file with 19 additions and 22 deletions.
41 changes: 19 additions & 22 deletions backbone.api.facebook.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,14 @@ if( window.FB ) (function(_, Backbone) {
},

initialize: function(model, options){
// fallbacks
options = options || {};
this.options = _.extend(this.options, options);
return Backbone.Model.prototype.initialize.apply(this, arguments);
//return Backbone.Model.prototype.initialize.apply(this, arguments);
// auto-fetch if requested...
if( options.fetch ){
this.fetch();
}
},

fetch : function(method, model, options) {
Expand Down Expand Up @@ -146,14 +151,6 @@ if( window.FB ) (function(_, Backbone) {
query: "SELECT url,normalized_url,share_count,like_count,comment_count,total_count,commentsbox_count,comments_fbid,click_count FROM link_stat WHERE url ='"+ this.get("url") +"'"
}
},
initialize: function( model, options){
// fallback
options = options || {};
// auto-fetch if requested...
if( options.fetch ){
this.fetch();
}
},

parse: function( response ){
// error control?
Expand Down Expand Up @@ -227,7 +224,7 @@ if( window.FB ) (function(_, Backbone) {

});

Backbone.API.Facebook.Models.WebPage = Backbone.Model.extend({
Backbone.API.Facebook.Models.WebPage = Model.extend({

defaults : {
"shares": 0,
Expand All @@ -242,12 +239,6 @@ if( window.FB ) (function(_, Backbone) {

url: function(){ return "https://graph.facebook.com/?ids="+ this.options.page },

initialize: function(model, options){
options = options || {};
this.options = _.extend(this.options, options);
return Backbone.Model.prototype.initialize.apply(this, arguments);
},

parse: function( data ){
// data arrives in a sub-object with the URL as the key
var model = {};
Expand All @@ -270,6 +261,18 @@ if( window.FB ) (function(_, Backbone) {
options : {
access_token : false
},

initialize: function(model, options){
// fallbacks
options = options || {};
this.options = _.extend(this.options, options);
//return Backbone.Model.prototype.initialize.apply(this, arguments);
// auto-fetch if requested...
if( options.fetch ){
this.fetch();
}
},

fetch : function(method, model, options) {
var self = this;

Expand Down Expand Up @@ -313,12 +316,6 @@ if( window.FB ) (function(_, Backbone) {
method: 'fql.query',
query: 'Select name, uid from user where is_app_user = 1 and uid in (select uid2 from friend where uid1 = me()) order by concat(first_name,last_name) asc'
}
},
initialize: function( model, options){
// auto-fetch if requested...
if( options.fetch ){
this.fetch();
}
}
});

Expand Down

0 comments on commit 86cee9d

Please sign in to comment.