UNPKG

@zedux/core

Version:

A high-level, declarative, composable form of Redux

28 lines (27 loc) 1.21 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.extractActionTypes = exports.extractActionType = void 0; /** Pulls the string action type out of an ActionFactory or returns a given string action type as-is. */ const extractActionType = (reactable, method) => { // The reactable may be a literal action type string if (typeof reactable === 'string') return reactable; if (true /* DEV */ && (typeof reactable !== 'function' || typeof reactable.type !== 'string')) { const type = typeof reactable === 'function' ? `function with invalid "type" property - ${typeof reactable.type}` : typeof reactable; throw new TypeError(`Zedux: ${method} - reactable must be either a string or a function with a "type" property. Received ${type}`); } return reactable.type; }; exports.extractActionType = extractActionType; /** Pulls the string action types out of a list of (possibly) mixed reactables and string action types. */ const extractActionTypes = (reactables, method) => reactables.map(reactable => (0, exports.extractActionType)(reactable, method)); exports.extractActionTypes = extractActionTypes;