[#88,view/refactor][s]: start on state management and serialization with getState function on Explorer.
This commit is contained in:
parent
05293cbb6f
commit
77414ff9ca
25
src/view.js
25
src/view.js
@ -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;
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
@ -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();
|
||||
});
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user