How to use the easy-peasy.actionOn function in easy-peasy

To help you get started, we’ve selected a few easy-peasy 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 ctrlplusb / easy-peasy / src / __tests__ / typescript / listener-action.ts View on Github external
const valid2: ActionOn = actionOn(
  actions => actions.doThunkString,
  (state, target) => {
    state.logs.push(target.payload);
  },
);

const invalid2: ActionOn = actionOn(
  actions => actions.doThunkNumber,
  (state, target) => {
    // typings:expect-error
    state.logs.push(target.payload);
  },
);

const valid3: ActionOn = actionOn(
  () => 'ADD_TODO',
  (state, target) => {
    state.logs.push(target.payload);
  },
);

const invalid3: ActionOn = actionOn(
  // typings:expect-error
  () => 1,
  // typings:expect-error
  (state, target) => {
    state.logs.push(target.payload);
  },
);

const invalid4: ActionOn = actionOn(
github ctrlplusb / easy-peasy / src / __tests__ / typescript / listener-action.ts View on Github external
doThunkString: Thunk;
  doActionNumber: Action;
  doThunkNumber: Thunk;
}

interface OtherModel {
  otherAction: Action;
  otherThunk: Thunk;
}

interface StoreModel {
  listening: ListeningModel;
  other: OtherModel;
}

const valid1: ActionOn = actionOn(
  actions => actions.doActionString,
  (state, target) => {
    const [foo] = target.resolvedTargets;
    foo + 'bar';
    target.type + 'foo';
    if (target.error != null) {
      target.error.stack;
    }
    state.logs.push(target.payload);
  },
);

const invalid1: ActionOn = actionOn(
  actions => actions.doActionNumber,
  (state, target) => {
    // typings:expect-error
github ctrlplusb / easy-peasy / src / __tests__ / typescript / listener-action.ts View on Github external
() => 'ADD_TODO',
  (state, target) => {
    state.logs.push(target.payload);
  },
);

const invalid3: ActionOn = actionOn(
  // typings:expect-error
  () => 1,
  // typings:expect-error
  (state, target) => {
    state.logs.push(target.payload);
  },
);

const invalid4: ActionOn = actionOn(
  // typings:expect-error
  () => undefined,
  // typings:expect-error
  (state, target) => {
    state.logs.push(target.payload);
  },
);

const valid4: ActionOn = actionOn(
  actions => [actions.doActionString, actions.doThunkString],
  (state, target) => {
    state.logs.push(target.payload);
  },
);

const invalid5: ActionOn = actionOn(
github ctrlplusb / easy-peasy / src / __tests__ / typescript / listener-action.ts View on Github external
const invalid1: ActionOn = actionOn(
  actions => actions.doActionNumber,
  (state, target) => {
    // typings:expect-error
    state.logs.push(target.payload);
  },
);

const valid2: ActionOn = actionOn(
  actions => actions.doThunkString,
  (state, target) => {
    state.logs.push(target.payload);
  },
);

const invalid2: ActionOn = actionOn(
  actions => actions.doThunkNumber,
  (state, target) => {
    // typings:expect-error
    state.logs.push(target.payload);
  },
);

const valid3: ActionOn = actionOn(
  () => 'ADD_TODO',
  (state, target) => {
    state.logs.push(target.payload);
  },
);

const invalid3: ActionOn = actionOn(
  // typings:expect-error
github ctrlplusb / easy-peasy / src / __tests__ / typescript / listener-action.ts View on Github external
const invalid2: ActionOn = actionOn(
  actions => actions.doThunkNumber,
  (state, target) => {
    // typings:expect-error
    state.logs.push(target.payload);
  },
);

const valid3: ActionOn = actionOn(
  () => 'ADD_TODO',
  (state, target) => {
    state.logs.push(target.payload);
  },
);

const invalid3: ActionOn = actionOn(
  // typings:expect-error
  () => 1,
  // typings:expect-error
  (state, target) => {
    state.logs.push(target.payload);
  },
);

const invalid4: ActionOn = actionOn(
  // typings:expect-error
  () => undefined,
  // typings:expect-error
  (state, target) => {
    state.logs.push(target.payload);
  },
);
github ctrlplusb / easy-peasy / src / __tests__ / typescript / listener-action.ts View on Github external
if (target.error != null) {
      target.error.stack;
    }
    state.logs.push(target.payload);
  },
);

const invalid1: ActionOn = actionOn(
  actions => actions.doActionNumber,
  (state, target) => {
    // typings:expect-error
    state.logs.push(target.payload);
  },
);

const valid2: ActionOn = actionOn(
  actions => actions.doThunkString,
  (state, target) => {
    state.logs.push(target.payload);
  },
);

const invalid2: ActionOn = actionOn(
  actions => actions.doThunkNumber,
  (state, target) => {
    // typings:expect-error
    state.logs.push(target.payload);
  },
);

const valid3: ActionOn = actionOn(
  () => 'ADD_TODO',
github ctrlplusb / easy-peasy / src / __tests__ / typescript / listener-action.ts View on Github external
// typings:expect-error
  (state, target) => {
    state.logs.push(target.payload);
  },
);

const invalid4: ActionOn = actionOn(
  // typings:expect-error
  () => undefined,
  // typings:expect-error
  (state, target) => {
    state.logs.push(target.payload);
  },
);

const valid4: ActionOn = actionOn(
  actions => [actions.doActionString, actions.doThunkString],
  (state, target) => {
    state.logs.push(target.payload);
  },
);

const invalid5: ActionOn = actionOn(
  actions => [actions.doActionString, actions.doThunkNumber],
  (state, target) => {
    // typings:expect-error
    state.logs.push(target.payload);
  },
);

const valid5: ActionOn = actionOn(
  actions => [actions.doActionString, actions.doThunkNumber],
github jamaljsr / polar / src / store / models / designer.ts View on Github external
.map(getStoreActions().lightning.getAllInfo),
        );
      }

      const nodesData = getStoreState().lightning.nodes;
      const { allCharts } = getState();
      // sync the chart with data from all of the nodes
      const chart = updateChartFromNodes(allCharts[network.id], network, nodesData);
      actions.setAllCharts({
        ...allCharts,
        [network.id]: chart,
      });
      actions.redrawChart();
    },
  ),
  onNetworkSetStatus: actionOn(
    (actions, storeActions) => storeActions.network.setStatus,
    (state, { payload }) => {
      const { id, status, only, all = true } = payload;
      const chart = state.allCharts[id];
      if (only) {
        // only update a specific node's status
        chart.nodes[only].properties.status = status;
      } else if (all) {
        // update all node statuses
        Object.keys(chart.nodes).forEach(
          name => (chart.nodes[name].properties.status = status),
        );
      }
    },
  ),
  removeLink: action((state, linkId) => {
github ctrlplusb / easy-peasy / src / __tests__ / typescript / listener-action.ts View on Github external
if (typeof target.payload === 'string') {
      state.logs.push(target.payload);
    } else {
      target.payload + 10;
    }
  },
);

const valid6: ActionOn = actionOn(
  () => ['foo', 'bar'],
  (state, target) => {
    state.logs.push(target.payload);
  },
);

const valid7: ActionOn = actionOn(
  () => 'foo',
  (state, target) => {
    state.logs.push(target.payload);
  },
);
github ctrlplusb / easy-peasy / src / __tests__ / typescript / listener-action.ts View on Github external
state.logs.push(target.payload);
  },
);

const valid5: ActionOn = actionOn(
  actions => [actions.doActionString, actions.doThunkNumber],
  (state, target) => {
    if (typeof target.payload === 'string') {
      state.logs.push(target.payload);
    } else {
      target.payload + 10;
    }
  },
);

const valid6: ActionOn = actionOn(
  () => ['foo', 'bar'],
  (state, target) => {
    state.logs.push(target.payload);
  },
);

const valid7: ActionOn = actionOn(
  () => 'foo',
  (state, target) => {
    state.logs.push(target.payload);
  },
);