Skip to content

Commit

Permalink
Implement trick to remove deprecated React.withContext (see facebook/…
Browse files Browse the repository at this point in the history
  • Loading branch information
slorber committed Mar 13, 2015
1 parent 957301e commit 9e3c74d
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 9 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "atom-react",
"version": "0.13.1",
"version": "0.13.2",
"description": "An opiniated way to use ReactJS in a functional way in plain old Javascript, inspired by popular Clojurescript wrappers like Om ",
"keywords": [
"react",
Expand Down
20 changes: 12 additions & 8 deletions src/atomReactContext.js
Original file line number Diff line number Diff line change
Expand Up @@ -297,12 +297,11 @@ AtomReactContext.prototype.renderAtomState = function(atomToRender) {
this.logStateBeforeRender();
var timeBeforeRendering = Date.now();
atomToRender.doWithLock("Atom state should not be modified during the render phase",function() {
React.withContext(reactContextHolder.context,function() {
// TODO 0.13 temporary ?, See https://github.com/facebook/react/issues/3392
var component = this.mountConfig.reactElementFactory(props);
var componentWithContext = reactContextHolder.childContextProviderFactory({children: component, context: reactContextHolder.context});
React.render(componentWithContext, this.mountConfig.domNode);
}.bind(this));
// TODO 0.13 temporary ?, See https://github.com/facebook/react/issues/3392
var componentFactory = this.mountConfig.reactElementFactory;
var componentProvider = function() { return componentFactory(props); };
var componentWithContext = reactContextHolder.childContextProviderFactory({componentProvider: componentProvider, context: reactContextHolder.context});
React.render(componentWithContext, this.mountConfig.domNode);
}.bind(this));
console.debug("Time to render in millies",Date.now()-timeBeforeRendering);
} catch (error) {
Expand All @@ -313,7 +312,6 @@ AtomReactContext.prototype.renderAtomState = function(atomToRender) {
};


// TODO 0.13 temporary ?, See https://github.com/facebook/react/issues/3392
function ChildContextProviderFactory(context) {

// TODO we are very permissive on the childContextTypes (is it a good idea?)
Expand All @@ -325,11 +323,17 @@ function ChildContextProviderFactory(context) {
return React.createFactory(React.createClass({
displayName: "ChildContextProvider",
childContextTypes: childContextTypes,
propTypes: {
componentProvider: React.PropTypes.func.isRequired,
context: React.PropTypes.object.isRequired
},
getChildContext: function() {
return this.props.context;
},
render: function() {
return React.DOM.div({children: this.props.children});
// TODO simplify this "componentProvider hack" after React 0.14? See See https://github.com/facebook/react/issues/3392
var children = this.props.componentProvider();
return React.DOM.div({children: children});
}
}));
}
Expand Down

0 comments on commit 9e3c74d

Please sign in to comment.