mirror of
https://github.com/vale981/Vulcan
synced 2025-03-06 01:51:40 -05:00
defer creation of apolloClient until it is first used
This commit is contained in:
parent
485f7bad37
commit
374dc2510d
1 changed files with 14 additions and 4 deletions
|
@ -14,15 +14,12 @@ export const initContext = () => {
|
|||
// init
|
||||
const history = browserHistory;
|
||||
const loginToken = global.localStorage['Meteor.loginToken'];
|
||||
const apolloClient = createApolloClient();
|
||||
addReducer({ apollo: apolloClient.reducer() });
|
||||
addMiddleware(apolloClient.middleware());
|
||||
let apolloClient;
|
||||
|
||||
// init context
|
||||
context = {
|
||||
history,
|
||||
loginToken,
|
||||
apolloClient,
|
||||
addAction, // context.addAction same as addAction
|
||||
getActions, // context.getActions same as getActions
|
||||
addReducer, // context.addReducer same as addReducer
|
||||
|
@ -31,6 +28,19 @@ export const initContext = () => {
|
|||
getMiddlewares, // context.getMiddlewares same as getMiddlewares
|
||||
};
|
||||
|
||||
// defer creation of apolloClient until it is first used
|
||||
Object.defineProperty(context, 'apolloClient', {
|
||||
enumerable: true,
|
||||
get: () => {
|
||||
if (!apolloClient) {
|
||||
apolloClient = createApolloClient();
|
||||
addReducer({ apollo: apolloClient.reducer() });
|
||||
addMiddleware(apolloClient.middleware());
|
||||
}
|
||||
return apolloClient;
|
||||
},
|
||||
});
|
||||
|
||||
// init store
|
||||
context.store = configureStore(context.getReducers, {}, (store) => {
|
||||
let chain, newDispatch;
|
||||
|
|
Loading…
Add table
Reference in a new issue