[#88,backend][s]: add __type__ attribute to all backends to identify them and provide a more robust and generic way to load backends from a string identifier such as that __type__ field.

* Also remove recline.Model.backends registry as can be replaced with this more generic solution.
* This refactoring is necessitated by our need to serialize backend info for save/reload of a dataset and explorer state in #88.
This commit is contained in:
Rufus Pollock
2012-04-15 22:19:43 +01:00
parent 002308f78f
commit 7743534eac
11 changed files with 80 additions and 23 deletions

View File

@@ -217,10 +217,11 @@ var dataProxyData = {
test('DataProxy Backend', function() {
// needed only if not stubbing
// stop();
var backend = new recline.Backend.DataProxy();
var dataset = new recline.Model.Dataset({
url: 'http://webstore.thedatahub.org/rufuspollock/gold_prices/data.csv'
},
'dataproxy'
backend
);
var stub = sinon.stub($, 'ajax', function(options) {
@@ -419,10 +420,11 @@ var sample_gdocs_spreadsheet_data = {
}
test("GDoc Backend", function() {
var backend = new recline.Backend.GDoc();
var dataset = new recline.Model.Dataset({
url: 'https://spreadsheets.google.com/feeds/list/0Aon3JiuouxLUdDQwZE1JdV94cUd6NWtuZ0IyWTBjLWc/od6/public/values?alt=json'
},
'gdocs'
backend
);
var stub = sinon.stub($, 'getJSON', function(options, cb) {
@@ -450,7 +452,7 @@ test("GDoc Backend.getUrl", function() {
var dataset = new recline.Model.Dataset({
url: 'https://docs.google.com/spreadsheet/ccc?key=' + key + '#gid=0'
});
var backend = recline.Model.backends['gdocs'];
var backend = new recline.Backend.GDoc();
var out = backend.getUrl(dataset);
var exp = 'https://spreadsheets.google.com/feeds/list/' + key + '/1/public/values?alt=json'
equal(exp, out);