summaryrefslogtreecommitdiffstats
path: root/packages/gitbook-core/src/lib/renderWithContext.js
blob: f9a093ccc85b2ebf2900c28e670dd4aeb5759704 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
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 Navigation = require('../actions/navigation');
const contextShape = require('../shapes/context');

const GitBookApplication = React.createClass({
    propTypes: {
        context:  contextShape,
        matching: React.PropTypes.object
    },

    componentDidMount() {
        const { context } = this.props;
        context.dispatch(Navigation.activate());
    },

    componentWillUnmount() {
        const { context } = this.props;
        context.dispatch(Navigation.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;