Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
function configureStore(initialState: StoreState) {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
const middlewares: Array = [router]
if (process.env.NODE_ENV === "development") {
middlewares.push(logger)
}
const enhancer = composeEnhancers(
applyMiddleware.apply(undefined, middlewares)
)
const store = createStore(connectRouter(history)(rootReducer), initialState, enhancer)
if (module.hot) {
module.hot.accept("app/renderer/reducers", () => {
// eslint-disable-line global-require
store.replaceReducer(require("app/renderer/reducers").default)
})
}
return store
}
// 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'
? window.devToolsExtension()
: f => f,
];
const finalCreateStore: CreateStore = compose(...composeArgs)(createStore);
const store: Store = finalCreateStore(
reducer,
typeof window !== 'undefined' ? window.__INITIAL_STATE__ : {},
);
// Useful for adding reducers dynamically
store.reducers = reducers;
import { createStore, applyMiddleware, compose } from 'redux';
import { devTools, persistState } from 'redux-devtools';
import middleware from './middleware';
import reducer from './modules/reducer';
import DevTools from '../containers/DevTools';
let finalCreateStore;
if (__DEVELOPMENT__ && __DEVTOOLS__) {
finalCreateStore = compose(
applyMiddleware.apply(this, middleware),
// Provides support for DevTools:
DevTools.instrument(),
// Optional. Lets you write ?debug_session= in address bar to persist debug sessions
persistState(getDebugSessionKey())
)(createStore);
} else {
finalCreateStore = compose(
applyMiddleware.apply(this, middleware)
)(createStore);
}
function getDebugSessionKey() {
// You can write custom logic here!
// By default we try to read the key from ?debug_session= in the address bar
const matches = window.location.href.match(/[?&]debug_session=([^&]+)\b/);
return (matches && matches.length > 0)? matches[1] : null;
import notifMiddleware from './modules/notifMiddleware'
import storeChannelsMiddleware from './modules/storeChannels'
import type { IrcState } from './flow'
const inProduction = process.env.NODE_ENV === 'production'
const initialState = {}
const middleware = [thunkMiddleware, notifMiddleware, storeChannelsMiddleware]
const composeEnhancers = inProduction
? compose
: window.__REDUX_DEVTOOLS_EXTENSION_COMPOSE__ || compose
if (!inProduction) middleware.push(require('redux-logger').default)
const store: ReduxStore = createStore(
rootReducer,
initialState,
composeEnhancers(applyMiddleware.apply(null, middleware))
)
window.addEventListener('beforeunload', () => {
const state: IrcState = store.getState()
state.connections.list.map(conn => {
conn.stream.quit(state.settings.quitMessage)
})
})
const el = document.getElementById('main')
if (el) {
render(
,
el
enhancer: function(middleware, config) {
if (config.redux.devToolsEnabled) {
return compose(
applyMiddleware.apply(null, middleware),
DevTools.instrument(),
batchedSubscribe(_.debounce(function(notify) {
notify();
}, config.redux.debounceWait))
);
}
return compose(
applyMiddleware.apply(null, middleware),
batchedSubscribe(_.debounce(function(notify) {
notify();
}, config.redux.debounceWait))
);
}
import { createStore, applyMiddleware, combineReducers, compose } from 'redux';
import thunkMiddleware from 'redux-thunk';
import { routerReducer } from 'react-router-redux';
import posts from 'wordpress-query-posts/lib/state';
import pages from 'wordpress-query-page/lib/state';
import terms from 'wordpress-query-term/lib/state';
import comments from 'wordpress-query-comments/lib/state';
import menu from 'wordpress-query-menu/lib/state';
import media from 'wordpress-query-media/lib/state';
import users from 'wordpress-query-user/lib/state';
let reducer = combineReducers( { posts, pages, terms, comments, menu, media, users, routing: routerReducer } );
let middleware = [ thunkMiddleware ];
let createStoreWithMiddleware = applyMiddleware.apply( null, middleware );
export function createReduxStore( initialState = {} ) {
if (
typeof window === 'object' &&
window.devToolsExtension
) {
createStoreWithMiddleware = compose( createStoreWithMiddleware, window.devToolsExtension() );
}
return createStoreWithMiddleware( createStore )( reducer, initialState );
}
enhancer: function(middleware, config) {
if (config.redux.devToolsEnabled) {
return compose(
applyMiddleware.apply(null, middleware),
DevTools.instrument(),
batchedSubscribe(_.debounce(function(notify) {
notify();
}, config.redux.debounceWait))
);
}
return compose(
applyMiddleware.apply(null, middleware),
batchedSubscribe(_.debounce(function(notify) {
notify();
}, config.redux.debounceWait))
);
}
_defineProperty(_assertThisInitialized(_assertThisInitialized(_this)), "dispatch", function () {
var action = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
return _this.store.dispatch(action);
});
var reducer = props.reducer,
saga = props.saga,
middleware = props.middleware,
actions = props.actions,
devToolsOptions = props.devToolsOptions;
_this.sagaMiddleware = saga && createSagaMiddleware && createSagaMiddleware();
var allMiddleware = _toConsumableArray(middleware);
if (_this.sagaMiddleware) allMiddleware.push(_this.sagaMiddleware);
var enhancers = applyMiddleware.apply(void 0, _toConsumableArray(allMiddleware));
var composeEnhancers = (typeof window === "undefined" ? "undefined" : _typeof(window)) === 'object' && window.__REDUX_DEVTOOLS_EXTENSION_COMPOSE__ ? window.__REDUX_DEVTOOLS_EXTENSION_COMPOSE__(devToolsOptions) : compose;
_this.state = reducer(undefined, {});
_this.store = createStore(reducer, devToolsOptions ? composeEnhancers(enhancers) : enhancers);
_this.store.subscribe(function () {
return _this.setState(_this.store.getState());
});
if (_this.sagaMiddleware) _this.saga = _this.sagaMiddleware.run(saga);
_this.boundActions = bindActionCreators(actions, _this.dispatch);
return _this;
}
export function createStore(state) {
return reduxCreateStore(
reducers,
state,
applyMiddleware.apply(null, middlewares)
);
}
var reducer = combineReducers({
alitaState: alitaState
});
/*
* File: Provider
* Desc: redux provider
* File Created: 2019-03-18 00:40:01
* Author: chenghao
* ------
* Copyright 2019 - present, chenghao
*/
var middleware = [thunk];
var store = createStore(reducer, applyMiddleware.apply(void 0, middleware));
var Provider = (function (_ref) {
var children = _ref.children;
return React.createElement(Provider$1, {
store: store
}, children);
});
/*
* File: index.js
* Desc: redux actions
* File Created: 2019-03-18 00:25:41
* Author: chenghao
* ------
* Copyright 2019 - present, chenghao
*/
var funcs;