Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
if (!production) {
require('dotenv').config();
}
const restUrl = production ?
process.env.PROD_RESTURL :
process.env.JSONSERVER_RESTURL;
let middleware = [
thunk,
axiosMiddleware(axios.create({baseURL:restUrl}))
];
if (!production) {
middleware.push(require('redux-immutable-state-invariant').default());
console.log('added redux-immutable-state-invariant');
}
export default function configureStore(initialState = {}) {
const composeEnhancers = composeWithDevTools({
// Specify name here, actionsBlacklist, actionsCreators and other options if needed
});
//const restUrl = 'http://localhost:4000/rest';
//console.log('configureStore: ' + restUrl);
const client = axios.create({ //all axios can be used, shown in axios documentation
baseURL: restUrl,
//responseType: 'json'
});
if (!production) {
require('dotenv').config();
}
const restUrl = production ?
process.env.PROD_RESTURL :
process.env.JSONSERVER_RESTURL;
let middleware = [
thunk,
axiosMiddleware(axios.create({baseURL:restUrl}))
];
if (!production) {
middleware.push(require('redux-immutable-state-invariant').default());
console.log('added redux-immutable-state-invariant');
}
export default function configureStore(initialState = {}) {
const composeEnhancers = composeWithDevTools({
// Specify name here, actionsBlacklist, actionsCreators and other options if needed
});
//const restUrl = 'http://localhost:4000/rest';
const client = axios.create({ //all axios can be used, shown in axios documentation
baseURL: restUrl,
//responseType: 'json'
});
import {
toggleMTMergeModal,
toggleTMMergeModal
} from '../actions/version-actions'
import {
showExportTMXModal
} from '../actions/tmx-actions'
const DEV = process.env && process.env.NODE_ENV === 'development'
const logger = createLogger({
// options
})
const middleware = [
DEV && require('redux-immutable-state-invariant').default(),
thunk,
apiMiddleware,
// routerMiddleware,
DEV && logger // must be last to avoid logging thunk/promise
].filter(Boolean)
const finalCreateStore = compose(
applyMiddleware(...middleware)
)(createStore)
// Call and assign the store with no initial state
const store = ((initialState) => {
const store = finalCreateStore(rootReducer, initialState)
if (module.hot) {
// Enable Webpack hot module replacement for reducers
module.hot.accept('../reducers', () => {
'Source Code Pro:400,600'
]
},
timeout: 2000
})
const DEV = process.env && process.env.NODE_ENV === 'development'
// const routerMiddleware = syncHistory(history)
const logger = createLogger({
// options
})
const middleware = [
DEV && require('redux-immutable-state-invariant').default(),
thunk,
apiMiddleware,
// routerMiddleware,
DEV && logger // must be last to avoid logging thunk/promise
].filter(Boolean)
const finalCreateStore = compose(
applyMiddleware(...middleware)
)(createStore)
// Call and assign the store with no initial state
const store = ((initialState) => {
const store = finalCreateStore(rootReducer, initialState)
// @ts-ignore module.hot
if (module.hot) {
// Enable Webpack hot module replacement for reducers
actionTransformer: (action) => {
return {
...action,
// allow symbol action type to be printed properly in logs
// TODO remove when types are migrated to stop using symbol
type: String(action.type)
}
}
})
const middleware = [
// TODO check if react helmet works here instead
titleUpdateMiddleware,
newContextFetchMiddleware,
// reduxRouterMiddleware,
DEV && require('redux-immutable-state-invariant').default(),
thunk,
enhancedCallApi,
apiMiddleware,
// must run after thunk because it fails with thunks
getStateInActions,
DEV && logger // must be last to avoid logging thunk/promise
].filter(Boolean)
const createStoreWithMiddleware = applyMiddleware(...middleware)(createStore)
export default createStoreWithMiddleware
import thunkPayloadMiddleware from '../middlewares/thunkPayload';
import { combineReducersWith } from '../utils';
let isProdEnv = true;
try {
if (process.env.NODE_ENV !== 'production') {
isProdEnv = false;
}
} catch (ex) {}
const isSsrEnv = typeof location !== 'object';
const isDevToolsDisabled = isProdEnv || isSsrEnv;
let freezeMiddleware, logger, createLogger;
/* eslint-disable no-undef */
if (!isDevToolsDisabled) {
// https://github.com/leoasis/redux-immutable-state-invariant
freezeMiddleware = require('redux-immutable-state-invariant').default();
// https://www.npmjs.com/package/redux-logger
const reduxLogger = require('redux-logger');
logger = reduxLogger.default;
({ createLogger } = reduxLogger);
}
/* eslint-enable no-undef */
export default function appState({
// https://redux.js.org/docs/recipes/reducers/UsingCombineReducers.html
// https://redux.js.org/docs/recipes/reducers/ReusingReducerLogic.html
reducers,
// optional
// https://redux-observable.js.org/docs/basics/Epics.html
epics = [],
// optional
disableDevTools = false,
thunkMiddleware: Function,
enhancers: Array = [],
): Store {
const reducers = Object.assign({}, { _gluestick }, customRequire());
const reducer: Object = combineReducers(reducers);
let middleware: Function[] = [
promiseMiddleware(client),
// Using OR operator instead of default argument, since null value will be casted to false
thunkMiddleware || thunk,
];
// Include middleware that will warn when you mutate the state object
// but only include it in dev mode
if (devMode) {
middleware.push(require('redux-immutable-state-invariant').default());
}
// When `customMiddleware` is of type `function`, pass it current
// array of `middlewares` and expect a new value in return.
// Fallback to default behaviour.
middleware =
typeof customMiddleware === 'function'
? customMiddleware([...middleware])
: middleware.concat(customMiddleware);
const composeArgs: Function[] = [
applyMiddleware.apply(this, middleware),
...enhancers,
typeof window === 'object' &&
typeof window.devToolsExtension !== 'undefined' &&
process.env.NODE_ENV !== 'production'
function getDevMiddleware(): ReadonlyArray {
/* eslint-disable global-require */
const { createLogger: createLoggerMiddleware } = require('redux-logger');
const {
default: createImmutableStateInvariantMiddleware,
} = require('redux-immutable-state-invariant');
/* eslint-enable global-require */
const immutableStateInvariantMiddleware = createImmutableStateInvariantMiddleware();
const loggerMiddleware = createLoggerMiddleware();
const middleware = [immutableStateInvariantMiddleware, loggerMiddleware];
return middleware;
}
const createReduxImmutableStateInvariant = () =>
// eslint-disable-next-line
process.env.NODE_ENV !== 'production' ? require('redux-immutable-state-invariant').default() : null
function configureStoreDev(initialState) {
const createLogger = require('redux-logger').createLogger;
const loggerMiddleware = createLogger({
collapsed: (getState, action) => typeof action === 'function',
duration: true,
});
const middlewares = [
// Add other middleware on this line...
// Redux middleware that spits an error on you when you try to mutate your state either inside a dispatch or between dispatches.
sagaMiddleware,
require('redux-immutable-state-invariant').default(),
loggerMiddleware,
// thunk middleware can also accept an extra argument to be passed to each thunk action
// https://github.com/gaearon/redux-thunk#injecting-a-custom-argument
// thunk,
];
const composeEnhancers = /*window !== undefined ? (window.__REDUX_DEVTOOLS_EXTENSION_COMPOSE__ || compose) :*/ compose;
const store = createStore(
rootReducer,
initialState,
composeEnhancers(applyMiddleware(...middlewares)),
);
if (module.hot) {
// Enable Webpack hot module replacement for reducers
module.hot.accept('../reducers', () => {