mirror of
https://github.com/vale981/Vulcan
synced 2025-03-06 01:51:40 -05:00
Merge branch 'patch-1' of https://github.com/wayfarerboy/Vulcan into wayfarerboy-patch-1
This commit is contained in:
commit
10ced441d2
2 changed files with 13 additions and 14 deletions
|
@ -8,10 +8,8 @@ import { Meteor } from 'meteor/meteor';
|
|||
import {
|
||||
Components,
|
||||
addRoute,
|
||||
addReducer, addMiddleware,
|
||||
Routes, populateComponentsApp, populateRoutesApp, runCallbacks, initializeFragments,
|
||||
getRenderContext,
|
||||
dynamicLoader,
|
||||
} from 'meteor/vulcan:lib';
|
||||
|
||||
import { RouterClient } from './router.jsx';
|
||||
|
@ -53,14 +51,16 @@ Meteor.startup(() => {
|
|||
context.addReducer({ apollo: apolloClientReducer });
|
||||
context.store.reload();
|
||||
context.store.dispatch({ type: '@@nova/INIT' }) // the first dispatch will generate a newDispatch function from middleware
|
||||
runCallbacks('router.client.rehydrate', { initialState, store: context.store});
|
||||
},
|
||||
historyHook(newHistory) {
|
||||
const { history } = getRenderContext();
|
||||
let { history } = getRenderContext();
|
||||
history = runCallbacks('router.client.history', history, { newHistory });
|
||||
return history;
|
||||
},
|
||||
wrapperHook(appGenerator) {
|
||||
const { apolloClient, store } = getRenderContext();
|
||||
const app = appGenerator({
|
||||
const app = runCallbacks('router.client.wrapper', appGenerator({
|
||||
onUpdate: () => {
|
||||
// the first argument is an item to iterate on, needed by vulcan:lib/callbacks
|
||||
// note: this item is not used in this specific callback: router.onUpdate
|
||||
|
@ -70,7 +70,7 @@ Meteor.startup(() => {
|
|||
// if the action is REPLACE, return false so that we don't jump back to top of page
|
||||
return !(nextRouterProps.location.action === 'REPLACE');
|
||||
}))
|
||||
});
|
||||
}));
|
||||
return <ApolloProvider store={store} client={apolloClient}>{app}</ApolloProvider>;
|
||||
},
|
||||
};
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
import React from 'react';
|
||||
import Helmet from 'react-helmet';
|
||||
import { getDataFromTree, ApolloProvider } from 'react-apollo';
|
||||
// import styleSheet from 'styled-components/lib/models/StyleSheet';
|
||||
|
||||
import { Meteor } from 'meteor/meteor';
|
||||
|
||||
|
@ -10,7 +9,7 @@ import {
|
|||
addRoute,
|
||||
Routes, populateComponentsApp, populateRoutesApp, initializeFragments,
|
||||
getRenderContext,
|
||||
dynamicLoader,
|
||||
runCallbacks,
|
||||
} from 'meteor/vulcan:lib';
|
||||
|
||||
import { RouterServer } from './router.jsx';
|
||||
|
@ -42,30 +41,30 @@ Meteor.startup(() => {
|
|||
|
||||
const options = {
|
||||
historyHook(req, res, newHistory) {
|
||||
const { history } = getRenderContext();
|
||||
let { history } = getRenderContext();
|
||||
history = runCallbacks('router.server.history', history, { req, res, newHistory });
|
||||
return history;
|
||||
},
|
||||
wrapperHook(req, res, appGenerator) {
|
||||
const { apolloClient, store } = getRenderContext();
|
||||
store.reload();
|
||||
store.dispatch({ type: '@@nova/INIT' }) // the first dispatch will generate a newDispatch function from middleware
|
||||
const app = appGenerator();
|
||||
const app = runCallbacks('router.server.wrapper', appGenerator(), { req, res, store, apolloClient });
|
||||
return <ApolloProvider store={store} client={apolloClient}>{app}</ApolloProvider>;
|
||||
},
|
||||
preRender(req, res, app) {
|
||||
runCallbacks('router.server.preRender', { req, res, app });
|
||||
return Promise.await(getDataFromTree(app));
|
||||
},
|
||||
dehydrateHook(req, res) {
|
||||
const context = getRenderContext();
|
||||
const context = runCallbacks('router.server.dehydrate', getRenderContext(), { req, res });
|
||||
return context.apolloClient.store.getState();
|
||||
},
|
||||
postRender(req, res) {
|
||||
// req.css = styleSheet.sheet ? styleSheet.rules().map(rule => rule.cssText).join('\n') : '';
|
||||
// const context = renderContext.get();
|
||||
// context.css = req.css;
|
||||
runCallbacks('router.server.postRender', { req, res });
|
||||
},
|
||||
htmlHook(req, res, dynamicHead, dynamicBody) {
|
||||
const head = Helmet.rewind();
|
||||
const head = runCallbacks('router.server.html', Helmet.rewind(), { req, res, dynamicHead, dynamicBody });
|
||||
return {
|
||||
dynamicHead: `${head.title}${head.meta}${head.link}${head.script}${dynamicHead}`,
|
||||
dynamicBody,
|
||||
|
|
Loading…
Add table
Reference in a new issue