diff options
Diffstat (limited to 'packages/gitbook-core/src/lib/renderWithContext.js')
-rw-r--r-- | packages/gitbook-core/src/lib/renderWithContext.js | 55 |
1 files changed, 55 insertions, 0 deletions
diff --git a/packages/gitbook-core/src/lib/renderWithContext.js b/packages/gitbook-core/src/lib/renderWithContext.js new file mode 100644 index 0000000..dc7e1f2 --- /dev/null +++ b/packages/gitbook-core/src/lib/renderWithContext.js @@ -0,0 +1,55 @@ +const React = require('react'); + +const { InjectedComponent } = require('../components/InjectedComponent'); +const PJAXWrapper = require('../components/PJAXWrapper'); +const I18nProvider = require('../components/I18nProvider'); +const ContextProvider = require('../components/ContextProvider'); +const History = require('../actions/history'); +const contextShape = require('../propTypes/context'); + +const GitBookApplication = React.createClass({ + propTypes: { + context: contextShape, + matching: React.PropTypes.object + }, + + componentDidMount() { + const { context } = this.props; + context.dispatch(History.activate()); + }, + + componentWillUnmount() { + const { context } = this.props; + context.dispatch(History.deactivate()); + }, + + render() { + const { context, matching } = this.props; + + return ( + <ContextProvider context={context}> + <PJAXWrapper> + <I18nProvider> + <InjectedComponent matching={matching} /> + </I18nProvider> + </PJAXWrapper> + </ContextProvider> + ); + } +}); + + +/** + * Render the application for a GitBook context. + * + * @param {GitBookContext} context + * @param {Object} matching + * @return {React.Element} element + */ +function renderWithContext(context, matching) { + return ( + <GitBookApplication context={context} matching={matching} /> + ); +} + +module.exports = renderWithContext; |