mirror of
https://github.com/wassname/talk.git
synced 2026-09-09 11:38:08 +08:00
Support store in withMutation
This commit is contained in:
@@ -14,7 +14,7 @@ if (window.devToolsExtension) {
|
||||
middlewares.push(window.devToolsExtension());
|
||||
}
|
||||
|
||||
export default createStore(
|
||||
const store = createStore(
|
||||
combineReducers({
|
||||
...mainReducer,
|
||||
apollo: client.reducer()
|
||||
@@ -22,3 +22,6 @@ export default createStore(
|
||||
{},
|
||||
compose(...middlewares)
|
||||
);
|
||||
|
||||
window.coralStore = store;
|
||||
export default store;
|
||||
|
||||
@@ -8,16 +8,15 @@ import './graphql';
|
||||
import {addExternalConfig} from 'coral-embed-stream/src/actions/config';
|
||||
|
||||
import reducers from './reducers';
|
||||
import localStore, {injectReducers} from 'coral-framework/services/store';
|
||||
import {getStore, injectReducers} from 'coral-framework/services/store';
|
||||
import AppRouter from './AppRouter';
|
||||
import {pym} from 'coral-framework';
|
||||
|
||||
injectReducers(reducers);
|
||||
|
||||
const store = (window.opener && window.opener.coralStore) ? window.opener.coralStore : localStore;
|
||||
const store = getStore();
|
||||
|
||||
// Don't run this in the popup.
|
||||
if (store === localStore) {
|
||||
if (!window.opener) {
|
||||
injectReducers(reducers);
|
||||
store.dispatch(checkLogin());
|
||||
|
||||
pym.sendMessage('getConfig');
|
||||
|
||||
@@ -5,7 +5,7 @@ import uniq from 'lodash/uniq';
|
||||
import flatten from 'lodash/flatten';
|
||||
import isEmpty from 'lodash/isEmpty';
|
||||
import {getMutationOptions, resolveFragments} from 'coral-framework/services/graphqlRegistry';
|
||||
import {store} from 'coral-framework/services/store';
|
||||
import {getStore} from 'coral-framework/services/store';
|
||||
import {getDefinitionName} from '../utils';
|
||||
|
||||
/**
|
||||
@@ -23,7 +23,7 @@ export default (document, config) => (WrappedComponent) => {
|
||||
const callbacks = getMutationOptions(name);
|
||||
const mutate = (base) => {
|
||||
const variables = base.variables || config.options.variables;
|
||||
const configs = callbacks.map((cb) => cb({variables, state: store.getState()}));
|
||||
const configs = callbacks.map((cb) => cb({variables, state: getStore().getState()}));
|
||||
|
||||
const optimisticResponse = merge(
|
||||
base.optimisticResponse || config.options.optimisticResponse,
|
||||
|
||||
@@ -24,22 +24,32 @@ if (window.devToolsExtension) {
|
||||
middlewares.push(window.devToolsExtension());
|
||||
}
|
||||
|
||||
let storeReducers = {
|
||||
...mainReducer,
|
||||
apollo: client.reducer()
|
||||
};
|
||||
|
||||
export const store = createStore(
|
||||
combineReducers(storeReducers),
|
||||
{},
|
||||
compose(...middlewares)
|
||||
);
|
||||
|
||||
export default store;
|
||||
|
||||
export function injectReducers(reducers) {
|
||||
storeReducers = {...storeReducers, ...reducers};
|
||||
store.replaceReducer(combineReducers(storeReducers));
|
||||
const store = getStore();
|
||||
store.coralReducers = {...store.coralReducers, ...reducers};
|
||||
store.replaceReducer(combineReducers(store.coralReducers));
|
||||
}
|
||||
|
||||
window.coralStore = store;
|
||||
export function getStore() {
|
||||
if (window.coralStore) {
|
||||
return window.coralStore;
|
||||
}
|
||||
if (window.opener && window.opener.coralStore) {
|
||||
return window.opener.coralStore;
|
||||
}
|
||||
|
||||
const coralReducers = {
|
||||
...mainReducer,
|
||||
apollo: client.reducer()
|
||||
};
|
||||
|
||||
window.coralStore = createStore(
|
||||
combineReducers(coralReducers),
|
||||
{},
|
||||
compose(...middlewares)
|
||||
);
|
||||
|
||||
window.coralStore.coralReducers = coralReducers;
|
||||
|
||||
return window.coralStore;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user