Skip to content

Commit

Permalink
feat(ChildMixin): expose instance getters from prototype
Browse files Browse the repository at this point in the history
  • Loading branch information
tomchentw committed Oct 25, 2014
1 parent 8d07bd3 commit bad5456
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 5 deletions.
10 changes: 5 additions & 5 deletions src/Map.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,12 +52,12 @@ module.exports = React.createClass({
_init_map () {
var {context} = this;
var {Map} = context.getApi();
return context._set_map(
new Map(
this.refs.mapCanvas.getDOMNode(),
this.props
)
var map = new Map(
this.refs.mapCanvas.getDOMNode(),
this.props
);
this.expose_getters_from(Map.prototype, map);
return context._set_map(map);
},

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

expose_getters_from (prototype, instance) {
Object.keys(prototype).forEach((key) => {
if (key.match(/^get/)) {
this[key] = instance[key].bind(instance);
}
});
}
};

0 comments on commit bad5456

Please sign in to comment.