diff --git a/src/backend/base.js b/src/backend/base.js index caf317f9..94ab7fb1 100644 --- a/src/backend/base.js +++ b/src/backend/base.js @@ -14,29 +14,41 @@ this.recline.Backend = this.recline.Backend || {}; return model.backend.sync(method, model, options); } - // ## wrapInTimeout - // - // Crude way to catch backend errors - // Many of backends use JSONP and so will not get error messages and this is - // a crude way to catch those errors. - my.wrapInTimeout = function(ourFunction) { - var dfd = $.Deferred(); - var timeout = 5000; - var timer = setTimeout(function() { - dfd.reject({ - message: 'Request Error: Backend did not respond after ' + (timeout / 1000) + ' seconds' - }); - }, timeout); - ourFunction.done(function(arguments) { - clearTimeout(timer); - dfd.resolve(arguments); - }) - .fail(function(arguments) { - clearTimeout(timer); - dfd.reject(arguments); - }) - ; - return dfd.promise(); - } + // ## recline.Backend.Base + // + // Base class for backends providing a template and convenience functions. + // You do not have to inherit from this class but even when not it does provide guidance on the functions you must implement. + my.Base = Backbone.Model.extend({ + sync: function(method, model, options) { + }, + query: function(model, queryObj) { + }, + + // ## _wrapInTimeout + // + // Convenience method providing a crude way to catch backend errors on JSONP calls. + // Many of backends use JSONP and so will not get error messages and this is + // a crude way to catch those errors. + _wrapInTimeout: function(ourFunction) { + var dfd = $.Deferred(); + var timeout = 5000; + var timer = setTimeout(function() { + dfd.reject({ + message: 'Request Error: Backend did not respond after ' + (timeout / 1000) + ' seconds' + }); + }, timeout); + ourFunction.done(function(arguments) { + clearTimeout(timer); + dfd.resolve(arguments); + }) + .fail(function(arguments) { + clearTimeout(timer); + dfd.reject(arguments); + }) + ; + return dfd.promise(); + } + }); + }(jQuery, this.recline.Backend)); diff --git a/src/backend/dataproxy.js b/src/backend/dataproxy.js index 45abc89a..e2ddb767 100644 --- a/src/backend/dataproxy.js +++ b/src/backend/dataproxy.js @@ -16,7 +16,7 @@ this.recline.Backend = this.recline.Backend || {}; // * format: (optional) csv | xls (defaults to csv if not specified) // // Note that this is a **read-only** backend. - my.DataProxy = Backbone.Model.extend({ + my.DataProxy = my.Base.extend({ defaults: { dataproxy_url: 'http://jsonpdataproxy.appspot.com' }, @@ -47,7 +47,7 @@ this.recline.Backend = this.recline.Backend || {}; , dataType: 'jsonp' }); var dfd = $.Deferred(); - my.wrapInTimeout(jqxhr).done(function(results) { + this._wrapInTimeout(jqxhr).done(function(results) { if (results.error) { dfd.reject(results.error); } diff --git a/src/backend/elasticsearch.js b/src/backend/elasticsearch.js index 78e27af6..5668202c 100644 --- a/src/backend/elasticsearch.js +++ b/src/backend/elasticsearch.js @@ -19,7 +19,7 @@ this.recline.Backend = this.recline.Backend || {}; // localhost:9200 with index twitter and type tweet it would be // //
http://localhost:9200/twitter/tweet- my.ElasticSearch = Backbone.Model.extend({ + my.ElasticSearch = my.Base.extend({ _getESUrl: function(dataset) { var out = dataset.get('elasticsearch_url'); if (out) return out; @@ -39,7 +39,7 @@ this.recline.Backend = this.recline.Backend || {}; dataType: 'jsonp' }); var dfd = $.Deferred(); - my.wrapInTimeout(jqxhr).done(function(schema) { + this._wrapInTimeout(jqxhr).done(function(schema) { // only one top level key in ES = the type so we can ignore it var key = _.keys(schema)[0]; var fieldData = _.map(schema[key].properties, function(dict, fieldName) { diff --git a/src/backend/gdocs.js b/src/backend/gdocs.js index ff2c6444..63ce2eb7 100644 --- a/src/backend/gdocs.js +++ b/src/backend/gdocs.js @@ -16,7 +16,7 @@ this.recline.Backend = this.recline.Backend || {}; // 'gdocs' // ); // - my.GDoc = Backbone.Model.extend({ + my.GDoc = my.Base.extend({ getUrl: function(dataset) { var url = dataset.get('url'); if (url.indexOf('feeds/list') != -1) { diff --git a/src/backend/memory.js b/src/backend/memory.js index be86c936..97b585e0 100644 --- a/src/backend/memory.js +++ b/src/backend/memory.js @@ -69,7 +69,7 @@ this.recline.Backend = this.recline.Backend || {}; // dataset.fetch(); // etc ... // - my.Memory = Backbone.Model.extend({ + my.Memory = my.Base.extend({ initialize: function() { this.datasets = {}; },