How to use the redux-loop.combineReducers function in redux-loop

To help you get started, we’ve selected a few redux-loop examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github apollographql / react-apollo / test / react-web / client / libraries / redux.tsx View on Github external
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();
          }
        }
github flow-typed / flow-typed / definitions / npm / redux-loop_v2.2.x / flow_v0.33.x- / test_combineReducers.js View on Github external
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);
github flow-typed / flow-typed / definitions / npm / redux-loop_v2.2.x / flow_v0.33.x- / test_combineReducers.js View on Github external
//
  // 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)
  );
}
github apollographql / react-apollo / test / react-web / client / libraries / redux.tsx View on Github external
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();
github flow-typed / flow-typed / definitions / npm / redux-loop_v2.2.x / flow_v0.33.x- / test_combineReducers.js View on Github external
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);
github FormidableLabs / redux-little-router / test / store-enhancer.spec.js View on Github external
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 };
};
github Imater / 4redux / src / redux / modules / reducer.js View on Github external
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;
github ioof-holdings / redux-subspace / examples / redux-loop / redux-loop-example / src / index.js View on Github external
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"&gt;
      
    
    <hr>
     state.counter2} namespace="counter2"&gt;
      
    </div>