diff options
author | Maximilian Hils <git@maximilianhils.com> | 2015-03-27 21:58:04 +0100 |
---|---|---|
committer | Maximilian Hils <git@maximilianhils.com> | 2015-03-27 21:58:04 +0100 |
commit | 1913975fa60c76bfb7e79a908b18e7e93793f71f (patch) | |
tree | 54a4ea1605e2d8219d2983d2181ce4b27168ed49 /web/src/js/components/mainview.js | |
parent | f39e6c5c18890de902d061226ba413254114c8ad (diff) | |
download | mitmproxy-1913975fa60c76bfb7e79a908b18e7e93793f71f.tar.gz mitmproxy-1913975fa60c76bfb7e79a908b18e7e93793f71f.tar.bz2 mitmproxy-1913975fa60c76bfb7e79a908b18e7e93793f71f.zip |
web: use contexts to pass down stores.
Using contexts frees us from the contracts we have
using props - namely, we can assume them to be constant
for the lifetime of the object.
Diffstat (limited to 'web/src/js/components/mainview.js')
-rw-r--r-- | web/src/js/components/mainview.js | 63 |
1 files changed, 27 insertions, 36 deletions
diff --git a/web/src/js/components/mainview.js b/web/src/js/components/mainview.js index 9790a69e..54687373 100644 --- a/web/src/js/components/mainview.js +++ b/web/src/js/components/mainview.js @@ -10,22 +10,40 @@ FlowTable = require("./flowtable.js"); var FlowView = require("./flowview/index.js"); var MainView = React.createClass({ - mixins: [common.Navigation, common.State], + mixins: [common.Navigation, common.RouterState], + contextTypes: { + flowStore: React.PropTypes.object.isRequired, + }, childContextTypes: { - returnFocus: React.PropTypes.func.isRequired + returnFocus: React.PropTypes.func.isRequired, + view: React.PropTypes.object.isRequired, }, - getChildContext: function() { - return { returnFocus: this.returnFocus }; + getChildContext: function () { + return { + returnFocus: this.returnFocus, + view: this.state.view + }; }, - returnFocus: function(){ + returnFocus: function () { this.getDOMNode().focus(); }, getInitialState: function () { + var sortKeyFun = false; + var view = new views.StoreView(this.context.flowStore, this.getViewFilt(), sortKeyFun); + view.addListener("recalculate", this.onRecalculate); + view.addListener("add", this.onUpdate); + view.addListener("update", this.onUpdate); + view.addListener("remove", this.onUpdate); + view.addListener("remove", this.onRemove); + return { - flows: [], - sortKeyFun: false + view: view, + sortKeyFun: sortKeyFun }; }, + componentWillUnmount: function () { + this.state.view.close(); + }, getViewFilt: function () { try { var filt = Filt.parse(this.getQuery()[Query.FILTER] || ""); @@ -44,29 +62,12 @@ var MainView = React.createClass({ }; }, componentWillReceiveProps: function (nextProps) { - if (nextProps.flowStore !== this.props.flowStore) { - this.closeView(); - this.openView(nextProps.flowStore); - } - var filterChanged = (this.props.query[Query.FILTER] !== nextProps.query[Query.FILTER]); var highlightChanged = (this.props.query[Query.HIGHLIGHT] !== nextProps.query[Query.HIGHLIGHT]); if (filterChanged || highlightChanged) { this.state.view.recalculate(this.getViewFilt(), this.state.sortKeyFun); } }, - openView: function (store) { - var view = new views.StoreView(store, this.getViewFilt(), this.state.sortKeyFun); - this.setState({ - view: view - }); - - view.addListener("recalculate", this.onRecalculate); - view.addListener("add", this.onUpdate); - view.addListener("update", this.onUpdate); - view.addListener("remove", this.onUpdate); - view.addListener("remove", this.onRemove); - }, onRecalculate: function () { this.forceUpdate(); var selected = this.getSelected(); @@ -85,16 +86,7 @@ var MainView = React.createClass({ this.selectFlow(flow_to_select); } }, - closeView: function () { - this.state.view.close(); - }, - componentWillMount: function () { - this.openView(this.props.flowStore); - }, - componentWillUnmount: function () { - this.closeView(); - }, - setSortKeyFun: function(sortKeyFun){ + setSortKeyFun: function (sortKeyFun) { this.setState({ sortKeyFun: sortKeyFun }); @@ -221,7 +213,7 @@ var MainView = React.createClass({ e.preventDefault(); }, getSelected: function () { - return this.props.flowStore.get(this.getParams().flowId); + return this.context.flowStore.get(this.getParams().flowId); }, render: function () { var selected = this.getSelected(); @@ -239,7 +231,6 @@ var MainView = React.createClass({ return ( <div className="main-view" onKeyDown={this.onKeyDown} tabIndex="0"> <FlowTable ref="flowTable" - view={this.state.view} selectFlow={this.selectFlow} setSortKeyFun={this.setSortKeyFun} selected={selected} /> |