All files / src/store actions.js

100% Statements 15/15
100% Branches 2/2
100% Functions 4/4
100% Lines 14/14
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51                                        36x   65x 63x   2x 2x 4x     65x         48x 36x 36x       7x 7x 7x 7x            
/**
* Copyright 2018, Plotly, Inc.
* All rights reserved.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
 
/**
 * Creates a redux action of the following payload:
 * {
 *  type,
 *  payload: ...forwardedArgNames,
 * }
 * i.e. its payload is the given `type` and the forwarded argument names from the actions payload.
 * If no arguments are provided, the payload is forwarded as `payload` in accordance to FSA (Flux Standard Action).
 *
 * Similar to createAction from redux-actions
 */
export function createAction(type, ...argNames) {
  const actionCreator = function (...args) {
    let payload;
    if (argNames.length === 0) {
      payload = args[0];
    } else {
      payload = {};
      argNames.forEach((arg, index) => {
        payload[argNames[index]] = args[index];
      });
    }
    return {
      type,
      payload,
    }
  }
  actionCreator.toString = () => type.toString();
  actionCreator.key = actionCreator.toString();
  return actionCreator;
}
 
// TODO: maybe use createActions from redux-actions here
export const updateProps = createAction('PROPS_UPDATE');
export const updateProp = createAction('PROP_UPDATE', 'key', 'value');
export const updateSequences = createAction('SEQUENCES_UPDATE');
export const actions = {
  updateProp,
  updateProps,
  updateSequences,
};
export default actions;