apollo-client
Version:
A simple yet functional GraphQL client.
42 lines • 1.69 kB
JavaScript
;
var redux_1 = require('redux');
var store_1 = require('./data/store');
var store_2 = require('./queries/store');
var store_3 = require('./mutations/store');
var crashReporter = function (store) { return function (next) { return function (action) {
try {
return next(action);
}
catch (err) {
console.error('Caught an exception!', err);
console.error(err.stack);
throw err;
}
}; }; };
function createApolloReducer(config) {
return function apolloReducer(state, action) {
if (state === void 0) { state = {}; }
var newState = {
queries: store_2.queries(state.queries, action),
mutations: store_3.mutations(state.mutations, action),
data: store_1.data(state.data, action, state.queries, state.mutations, config),
};
return newState;
};
}
exports.createApolloReducer = createApolloReducer;
function createApolloStore(_a) {
var _b = _a === void 0 ? {} : _a, _c = _b.reduxRootKey, reduxRootKey = _c === void 0 ? 'apollo' : _c, initialState = _b.initialState, _d = _b.config, config = _d === void 0 ? {} : _d;
var enhancers = [];
if (typeof window !== 'undefined') {
var anyWindow = window;
if (anyWindow.devToolsExtension) {
enhancers.push(anyWindow.devToolsExtension());
}
}
enhancers.push(redux_1.applyMiddleware(crashReporter));
return redux_1.createStore(redux_1.combineReducers((_e = {}, _e[reduxRootKey] = createApolloReducer(config), _e)), initialState, redux_1.compose.apply(void 0, enhancers));
var _e;
}
exports.createApolloStore = createApolloStore;
//# sourceMappingURL=store.js.map