summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSamy Pesse <samypesse@gmail.com>2016-10-05 14:22:01 +0200
committerSamy Pesse <samypesse@gmail.com>2016-10-05 14:22:01 +0200
commit805886e4a96bc543f39052f1d715c71bb76eee76 (patch)
treec4b0b2c468f389bac2516031bf8ba7dea7d81878
parent83c98cf4d88a62accda76193b478d97360bd405a (diff)
downloadgitbook-805886e4a96bc543f39052f1d715c71bb76eee76.zip
gitbook-805886e4a96bc543f39052f1d715c71bb76eee76.tar.gz
gitbook-805886e4a96bc543f39052f1d715c71bb76eee76.tar.bz2
We trigger current url history only once the page has been mounted
-rw-r--r--packages/gitbook-core/src/lib/createContext.js6
-rw-r--r--packages/gitbook-core/src/lib/renderWithContext.js41
2 files changed, 34 insertions, 13 deletions
diff --git a/packages/gitbook-core/src/lib/createContext.js b/packages/gitbook-core/src/lib/createContext.js
index c88baad..87593e3 100644
--- a/packages/gitbook-core/src/lib/createContext.js
+++ b/packages/gitbook-core/src/lib/createContext.js
@@ -19,12 +19,6 @@ const isBrowser = (typeof window !== 'undefined');
* @type {Plugin}
*/
const corePlugin = new Plugin({
- activate: (dispatch) => {
- dispatch(Navigation.activate());
- },
- deactivate: (dispatch) => {
- dispatch(Navigation.deactivate());
- },
reduce: coreReducers,
actions: {
Components, I18n, Navigation
diff --git a/packages/gitbook-core/src/lib/renderWithContext.js b/packages/gitbook-core/src/lib/renderWithContext.js
index 32553d9..44f8ba4 100644
--- a/packages/gitbook-core/src/lib/renderWithContext.js
+++ b/packages/gitbook-core/src/lib/renderWithContext.js
@@ -4,6 +4,39 @@ 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
+ },
+
+ componentDidMount() {
+ const { context } = this.props;
+ context.dispatch(Navigation.activate());
+ },
+
+ componentWillUnmount() {
+ const { context } = this.props;
+ context.dispatch(Navigation.deactivate());
+ },
+
+ render() {
+ const { context } = this.props;
+
+ return (
+ <ContextProvider context={context}>
+ <PJAXWrapper>
+ <I18nProvider>
+ <InjectedComponent matching={{ role: 'Body' }} />
+ </I18nProvider>
+ </PJAXWrapper>
+ </ContextProvider>
+ );
+ }
+});
+
/**
* Render the application for a GitBook context.
@@ -13,13 +46,7 @@ const ContextProvider = require('../components/ContextProvider');
*/
function renderWithContext(context) {
return (
- <ContextProvider context={context}>
- <PJAXWrapper>
- <I18nProvider>
- <InjectedComponent matching={{ role: 'Body' }} />
- </I18nProvider>
- </PJAXWrapper>
- </ContextProvider>
+ <GitBookApplication context={context} />
);
}