Created
May 14, 2015 03:02
-
-
Save karlbright/1a3e0fb5a6feba381485 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var React = require.requireActual('react') | |
var assign = require.requireActual('object-assign') | |
function stubContext(Component, context, props) { | |
var _component = Component | |
var _context = context | |
var _props = props | |
var _contextTypes = {} | |
Object.keys(_context).forEach((key) => { | |
_contextTypes[key] = React.PropTypes.any | |
}) | |
var ContextWrappedComponent = React.createClass({ | |
childContextTypes: _contextTypes, | |
getChildContext: function() { | |
return _context | |
}, | |
render: function() { | |
return <Component {...props} /> | |
} | |
}) | |
ContextWrappedComponent.withProps = function(props) { | |
return stubContext(_component, _context, assign({}, _props, props)) | |
} | |
return ContextWrappedComponent | |
} | |
module.exports = stubContext |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment