Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
switch (action.type) {
case 'INCREMENT':
return state + 1;
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();
}
}
function testCombineReducers(
a: Reducer,
b: (state: StateB, action: Action) => StateB,
c: (state: StateC, action: Action) => StateC | [StateC, Effect]
) {
// ok
const reducer = combineReducers({ a, b, c }, { a: 1, b: "two", c: false });
// ok
const reducer2: Reducer = combineReducers(
{ a, b, c },
{ a: 1, b: "two", c: false }
);
// ok
const result: [State, Effect] = reducer({ a: 1, b: "two", c: false }, action);
//
// Checks type of state input to reducer
//
// $ExpectError
reducer({}, action);
// $ExpectError
reducer({ a: "badvalue", b: "two", c: false }, action);
//
// Checks shape of initial state
//
// TODO: This should fail, but does not. It appears that `$Shape` does not
// combine well with `$ObjMap`.
//
// combineReducers({ a, b, c }, { a: 'one' })
//
// State accessor and modifier
//
// ok
combineReducers(
{ a, b, c },
{},
(state, key) => state[key],
(state, key, value) => (state[key] = value)
);
}
let wrapper;
function counter(state = 1, action) {
switch (action.type) {
case 'INCREMENT':
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();
function testCombineReducers(
a: Reducer,
b: (state: StateB, action: Action) => StateB,
c: (state: StateC, action: Action) => StateC | [StateC, Effect]
) {
// ok
const reducer = combineReducers({ a, b, c }, { a: 1, b: "two", c: false });
// ok
const reducer2: Reducer = combineReducers(
{ a, b, c },
{ a: 1, b: "two", c: false }
);
// ok
const result: [State, Effect] = reducer({ a: 1, b: "two", c: false }, action);
//
// Checks type of state input to reducer
//
// $ExpectError
reducer({}, action);
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 };
};
import { combineReducers } from 'redux-loop';
import { routerReducer as routing } from 'react-router-redux';
import { reducer as reduxAsyncConnect } from 'redux-async-connect';
import { reducer as form } from 'redux-form';
import holidays from './holidays';
const reducers = combineReducers({
reduxAsyncConnect,
form,
routing,
holidays
});
export default reducers;
import React from 'react';
import { render } from 'react-dom';
import { createStore } from 'redux';
import { Provider } from 'react-redux';
import { SubspaceProvider } from 'react-redux-subspace'
import { install, combineReducers } from 'redux-loop';
import { namespaced } from 'redux-subspace-loop'
import { CounterApp, reducer as counterReducer } from './counter';
/**
* Namespace the counter reducers
*/
const reducer = combineReducers({
counter1: namespaced('counter1')(counterReducer),
counter2: namespaced('counter2')(counterReducer)
})
/**
* Mount the counter app multiple times inside subspaces
*/
const App = () => (
<div>
state.counter1} namespace="counter1">
<hr>
state.counter2} namespace="counter2">
</div>