Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
default:
return state;
}
}
// initial state, accessor and mutator for supporting root-level
// immutable data with redux-loop reducer combinator
const immutableStateContainer = Map();
const getImmutable = (child, key) => child ? child.get(key) : void 0;
const setImmutable = (child, key, value) => child.set(key, value);
const store = createStore(
loopCombine({
counter,
}, immutableStateContainer as any, getImmutable, setImmutable),
install()
);
@connect((state) => ({ first: state.get('counter') }))
@graphql(query)
class Container extends React.Component {
componentWillReceiveProps(nextProps) {
if (nextProps.first === 1) this.props.dispatch({ type: 'INCREMENT' });
if (nextProps.first === 2) {
if (nextProps.data.loading) return;
expect(nextProps.data.allPeople).to.deep.equal(data2.allPeople);
done();
}
}
render() {
return null;
}
return state + 1;
default:
return state;
}
}
// Typscript workaround
const apolloReducer = client.reducer() as () => any;
const store = createStore(
loopCombine({
counter,
apollo: apolloReducer,
}),
applyMiddleware(client.middleware()),
install()
);
@connect((state) => ({ first: state.counter }))
@graphql(query)
class Container extends React.Component {
componentWillReceiveProps(nextProps) {
if (nextProps.first === 1) this.props.dispatch({ type: 'INCREMENT' });
if (nextProps.first === 2) {
if (nextProps.data.loading) return;
expect(nextProps.data.allPeople).to.deep.equal(data2.allPeople);
done();
}
}
render() {
return null;
}
return (createStore) => (update, initialState, enhancer) => {
initialState = initialState || toReduxLoop(init()); // eslint-disable-line no-param-reassign
function reducer(state, action) {
if (isReduxAction(action)) return state;
return toReduxLoop(update(state, action));
}
const loopEnhancer = loopInstall();
return loopEnhancer(createStore)(reducer, initialState, enhancer);
};
}
export default ({
additionalReducers, enableReactRouterRedux, enableDevTools, enableThunk, enableLoop, history,
}) => {
let middleware = [];
let reactRouterReduxMiddleware;
if (enableThunk) middleware = middleware.concat(thunk);
if (enableReactRouterRedux && history) reactRouterReduxMiddleware = syncHistory(history);
if (reactRouterReduxMiddleware) middleware = middleware.concat(reactRouterReduxMiddleware);
let storeEnhancers = [];
if (enableLoop) storeEnhancers = storeEnhancers.concat(installLoop()); // this should come last, but devtools causes issue
if (enableDevTools) storeEnhancers = storeEnhancers.concat(window.devToolsExtension ? window.devToolsExtension() : f => f);
const reducers = additionalReducers && !isEmpty(additionalReducers) ? additionalReducers : {};
if (enableReactRouterRedux) reducers.routing = routeReducer;
const defaultReducer = (state = {}) => state;
const cr = enableLoop ? loopCombineReducers : reduxCombineReducers;
const reducer = isEmpty(reducers) ? defaultReducer : cr({
[NAMESPACE]: defaultReducer, // need to set if using combineReducers top level...
...reducers,
});
const store = createStore(reducer, {}, compose(
applyMiddleware(...middleware),
...storeEnhancers
));
export default function createStore(history, data) {
const reduxRouterMiddleware = routerMiddleware(history);
// const middleware = [createMiddleware(client), reduxRouterMiddleware];
let finalCreateStore;
if (__DEVELOPMENT__ && __CLIENT__ && __DEVTOOLS__) {
const { persistState } = require('redux-devtools'); // eslint-disable-line global-require
const DevTools = require('../containers/DevTools/DevTools'); // eslint-disable-line global-require
finalCreateStore = compose(
install(),
applyMiddleware(reduxRouterMiddleware),
window.devToolsExtension ? window.devToolsExtension() : DevTools.instrument(),
persistState(window.location.href.match(/[?&]debug_session=([^&]+)\b/))
)(_createStore);
} else {
finalCreateStore = compose(
install(),
applyMiddleware(reduxRouterMiddleware)
)(_createStore);
}
const reducer = require('./modules/reducer'); // eslint-disable-line global-require
const store = finalCreateStore(reducer, data);
// reduxRouterMiddleware.listenForReplays(store);
const createStore = (history, data) => {
const reduxRouterMiddleware = routerMiddleware(history)
// const middleware = [createMiddleware(client), reduxRouterMiddleware];
let finalCreateStore
if (__DEVELOPMENT__ && __CLIENT__ && __DEVTOOLS__) {
const { persistState } = require('redux-devtools') // eslint-disable-line global-require, import/no-extraneous-dependencies
const DevTools = require('../containers/DevTools/DevTools') // eslint-disable-line global-require
finalCreateStore = compose(
install(),
applyMiddleware(reduxRouterMiddleware),
window.devToolsExtension ? window.devToolsExtension() : DevTools.instrument(),
persistState(window.location.href.match(/[?&]debug_session=([^&]+)\b/))
)(_createStore)
} else {
finalCreateStore = compose(
install(),
applyMiddleware(reduxRouterMiddleware)
)(_createStore)
}
const store = finalCreateStore(makeReducers(), data)
store.asyncReducers = {}
// reduxRouterMiddleware.listenForReplays(store);
const enhancers = [
createStoreWithSpy,
createStoreWithRouter({
routes,
location,
history: historyStub,
passRouterStateToReducer
}),
applyMiddleware(
routerMiddleware({ history: historyStub })
)
];
if (isLoop) {
enhancers.push(install());
}
const store = createStore(
isLoop ? combineReducers({
stuff: state => state
}) : reducer,
initialState,
compose(...enhancers)
);
return { store, historyStub };
};
export default (containerDomId, init, update, View) => {
const initialState = toReduxLoop(init());
function reducer(state, action) {
if (action.type === '@@INIT') return state;
return toReduxLoop(update(state, action));
}
const storeFactory = compose(
install(),
window.devToolsExtension ? window.devToolsExtension() : f => f
)(createStore);
const store = storeFactory(reducer, initialState);
const ConnectedView = connect(appState => ({
model: appState
}))(View);
render((
), document.getElementById(containerDomId));
}
import { createStore } from "redux";
import rootReducer from "./reducers";
import { install } from "redux-loop";
export default createStore(rootReducer, undefined, install());
import React from 'react';
import ReactDOM from 'react-dom';
import { createStore } from 'redux';
import { ModuleProvider } from 'redux-modules';
import { install, combineReducers } from 'redux-loop';
import { BrowserRouter as Router } from 'react-router-dom';
import './App.css';
import App from './App';
import './index.css';
const store = createStore(s => s, {}, install());
ReactDOM.render(
<div style="{{">
</div>
,
document.getElementById('root'),
);