Skip to content

Commit

Permalink
fix(ChildMixin): remove invalid_context and duplicated contextTypes
Browse files Browse the repository at this point in the history
  • Loading branch information
tomchentw committed Oct 25, 2014
1 parent 3b1cfb8 commit 80110a2
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 23 deletions.
21 changes: 14 additions & 7 deletions src/Map.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,28 +11,35 @@ module.exports = React.createClass({
mixins: [ChildMixin, EventBindingMixin],

contextTypes: {
getMap: React.PropTypes.func,
_set_map: React.PropTypes.func
},

componentDidMount () {
if (this.invalid_context(true)) return;
var {context} = this;
if (!context.getApi()) return;
if (context.hasMap()) return;
this.add_listeners(this._init_map());
},

componentWillUpdate () {
if (this.invalid_context(true)) return;
this.clear_listeners(this.context.getMap());
var {context} = this;
if (!context.getApi()) return;
if (context.hasMap()) return;
this.clear_listeners(context.getMap());
},

componentDidUpdate () {
if (this.invalid_context(true)) return;
var {context} = this;
if (!context.getApi()) return;
if (context.hasMap()) return;
this.add_listeners(this._init_map());
},

componentWillUnmount () {
if (this.invalid_context(true)) return;
this.clear_listeners(this.context.getMap());
var {context} = this;
if (!context.getApi()) return;
if (context.hasMap()) return;
this.clear_listeners(context.getMap());
},

render () {
Expand Down
14 changes: 4 additions & 10 deletions src/Marker.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,35 +16,29 @@ module.exports = React.createClass({
};
},

contextTypes: {
getMap: React.PropTypes.func,
getApi: React.PropTypes.func,
hasMap: React.PropTypes.func,
},

componentDidMount () {
var {marker} = this.state;
if (this.invalid_context(marker)) return;
if (marker || !this.context.hasMap()) return;
marker = this._init_marker();
this.add_listeners(marker);
},

componentWillUpdate () {
var {marker} = this.state;
if (this.invalid_context(marker)) return;
if (marker || !this.context.hasMap()) return;
this.clear_listeners(marker);
},

componentDidUpdate () {
var {marker} = this.state;
if (this.invalid_context(marker)) return;
if (marker || !this.context.hasMap()) return;
marker = this._init_marker();
this.add_listeners(marker);
},

componentWillUnmount () {
var {marker} = this.state;
if (this.invalid_context(marker)) return;
if (marker || !this.context.hasMap()) return;
this.clear_listeners(marker);
},

Expand Down
6 changes: 0 additions & 6 deletions src/mixins/ChildMixin.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,5 @@ module.exports = {
getMap: React.PropTypes.func,
getApi: React.PropTypes.func,
hasMap: React.PropTypes.func,
},

invalid_context (instance) {
var {context} = this;
var invalidMap = (true === instance ? context.hasMap() : (instance || !context.hasMap()));
return invalidMap || !context.getApi();
}
};

0 comments on commit 80110a2

Please sign in to comment.