How to use redux-loop - 10 common examples

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 flow-typed / flow-typed / definitions / npm / redux-loop_v2.2.x / flow_v0.33.x- / test_loop.js View on Github external
};

//
// liftState
//

// ok
const lifted: [State, Effect] = L.liftState({ first: true, second: false });

//
// loop accessors
//

const state: State = { first: true, second: false };

const loopState: [State, Effect] = loop(
  { first: true, second: false },
  Effects.constant({ type: "SECOND" })
);

// ok
const model1: State = L.getModel(loopState);

// ok
const model2: State = L.getModel(state);

// ok
const effect1: Effect = L.getEffect(loopState);

// ok
const effect2: null = L.getEffect(state);
github flow-typed / flow-typed / definitions / npm / redux-loop_v2.2.x / flow_v0.33.x- / test_effects.js View on Github external
function nestedAction(time: Date, action: { type: $Subtype }) {
  return { type: "NESTED_ACTION", payload: action, time };
}

function nestedActionWrongArgOrder(
  action: { type: $Subtype },
  time: Date
) {
  return { type: "NESTED_ACTION", payload: action, time };
}

const nestedEffect = Effects.call(zeroArg);

// ok
Effects.lift(nestedEffect, nestedAction, new Date());

// $ExpectError
Effects.lift(nestedEffect, nestedActionWrongArgOrder, new Date());
github flow-typed / flow-typed / definitions / npm / redux-loop_v2.2.x / flow_v0.33.x- / test_effects.js View on Github external
Effects.call(string, "one", "two");

//
// Effects.promise
//

function asyncActionCreator(x: string, y: number) {
  return Promise.resolve({
    type: "asyncAction",
    x,
    y
  });
}

// ok
Effects.promise(asyncActionCreator, "one", 2);

// $ExpectError
Effects.promise(asyncActionCreator, 1, "two");

//
// Effects.batch
//

// ok
Effects.batch([
  Effects.call(zeroArg),
  Effects.promise(asyncActionCreator, "one", 2)
]);

//
// Effects.lift
github flow-typed / flow-typed / definitions / npm / redux-loop_v2.2.x / flow_v0.33.x- / test_effects.js View on Github external
/* @flow */

import { Effects } from "redux-loop";
import type { Effect } from "redux-loop";

//
// Effects.none
//

// ok
const none: Effect = Effects.none();

//
// Effects.constant
//

// ok
const constant: Effect = Effects.constant({ type: "foo" });

// $ExpectError
Effects.constant({ noTypeProp: "foo" });

//
// Effects.call
//

function zeroArg() {
github flow-typed / flow-typed / definitions / npm / redux-loop_v2.2.x / flow_v0.33.x- / test_effects.js View on Github external
y
  });
}

// ok
Effects.promise(asyncActionCreator, "one", 2);

// $ExpectError
Effects.promise(asyncActionCreator, 1, "two");

//
// Effects.batch
//

// ok
Effects.batch([
  Effects.call(zeroArg),
  Effects.promise(asyncActionCreator, "one", 2)
]);

//
// Effects.lift
//

function nestedAction(time: Date, action: { type: $Subtype }) {
  return { type: "NESTED_ACTION", payload: action, time };
}

function nestedActionWrongArgOrder(
  action: { type: $Subtype },
  time: Date
) {
github apollographql / react-apollo / test / react-web / client / libraries / redux.tsx View on Github external
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;
        }
github apollographql / react-apollo / test / react-web / client / libraries / redux.tsx View on Github external
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;
        }
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)
  );
}