[#88,view/refactor][s]: start on state management and serialization with getState function on Explorer.

This commit is contained in:
Rufus Pollock 2012-04-14 11:42:02 +01:00
parent 05293cbb6f
commit 77414ff9ca
2 changed files with 28 additions and 1 deletions

View File

@ -108,6 +108,12 @@ my.DataExplorer = Backbone.View.extend({
})
}];
}
this.state = {
dataset: null,
queryState: this.model.queryState.toJSON(),
currentView: null
};
this._setupStateManagement();
// this must be called after pageViews are created
this.render();
@ -229,6 +235,25 @@ my.DataExplorer = Backbone.View.extend({
} else if (action === 'facets') {
this.$facetViewer.show();
}
},
_setupStateManagement: function() {
var self = this;
this.model.queryState.bind('change', function() {
self.state.queryState = this.model.queryState.toJSON();
});
_.each(this.pageViews, function(pageView) {
if (pageView.view.state && pageView.view.state.bind) {
pageView.view.state.bind('change', function() {
self.state['view-' + pageView.view.id] = pageView.view.state.toJSON();
});
}
});
},
// Get the current state of dataset and views
getState: function() {
return this.state;
}
});

View File

@ -23,7 +23,9 @@ test('getState', function () {
model: dataset,
el: $el
});
// explorer.getState();
var state = explorer.getState();
ok(state.queryState);
equal(state.queryState.size, 100);
$el.remove();
});