Created
October 19, 2018 18:40
-
-
Save jagretz/a8ac551d5b0a4c0262ceaa80b59839e2 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export const APP = "r3"; | |
export const createActionType = app => duck => type => `${app}/${duck}/${type}`; | |
export const createDuckType = createActionType(APP); | |
/** | |
* Constructs a new action with a required type and optional additional action properties supplied as | |
* optional argument(s*); *see `...rest` param below. | |
* | |
* @export | |
* @param {string} type the action type | |
* @param {...any} rest addition action properties; one or more. | |
* @returns {Action} An action with the provided type and any additional props. | |
* @throws {TypeError} for an undefined or otherwise invalid type property. | |
* @example | |
* | |
* import import { createDuckType } from ../path/to/import; | |
* const createActionType = createDuckType("myReducer"); | |
* export const MY_ACTION_TYPE = createActionType("MY_ACTION_TYPE"); | |
*/ | |
export function createAction(type, ...rest) { | |
if (!type || typeof type !== "string") throw new TypeError(`An invalid type argument was supplied: ${type}`); | |
return { type, ...rest }; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment