Skip to content

Commit

Permalink
feat(GoogleMapsMixin): create mixin for context usage
Browse files Browse the repository at this point in the history
  • Loading branch information
tomchentw committed Oct 24, 2014
1 parent 8c5429c commit 526ca9d
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 56 deletions.
56 changes: 0 additions & 56 deletions src/GoogleMap.js

This file was deleted.

52 changes: 52 additions & 0 deletions src/GoogleMapsMixin.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
/** @jsx React.DOM */
"use strict";
var React = require("react/addons");

module.exports = {

getInitialState () {
return {
googleMapsApi: this.props.googleMapsApi,
map: null
};
},

childContextTypes: {
getMap: React.PropTypes.func,
getApi: React.PropTypes.func,
hasMap: React.PropTypes.func,
_set_map: React.PropTypes.func
},

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

getChildContext () {
return {
getMap: this._get_map,
getApi: this._get_api,
hasMap: this._has_map,
_set_map: this._set_map
};
},

_get_map () {
return this.state.map;
},

_get_api () {
return this.state.googleMapsApi;
},

_has_map () {
return !!this._get_map();
},

_set_map (map) {
this.setState({ map });
}
};

0 comments on commit 526ca9d

Please sign in to comment.