UNPKG

alt

Version:
117 lines (92 loc) 3.32 kB
'use strict'; Object.defineProperty(exports, "__esModule", { value: true }); var _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; exports.getInternalMethods = getInternalMethods; exports.getPrototypeChain = getPrototypeChain; exports.warn = warn; exports.uid = uid; exports.formatAsConstant = formatAsConstant; exports.dispatchIdentity = dispatchIdentity; exports.fsa = fsa; exports.dispatch = dispatch; var _functions = require('../functions'); var fn = _interopRequireWildcard(_functions); function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) newObj[key] = obj[key]; } } newObj['default'] = obj; return newObj; } } /*eslint-disable*/ var builtIns = Object.getOwnPropertyNames(NoopClass); var builtInProto = Object.getOwnPropertyNames(NoopClass.prototype); /*eslint-enable*/ function getInternalMethods(Obj, isProto) { var excluded = isProto ? builtInProto : builtIns; var obj = isProto ? Obj.prototype : Obj; return Object.getOwnPropertyNames(obj).reduce(function (value, m) { if (excluded.indexOf(m) !== -1) { return value; } value[m] = obj[m]; return value; }, {}); } function getPrototypeChain(Obj) { var methods = arguments.length <= 1 || arguments[1] === undefined ? {} : arguments[1]; return Obj === Function.prototype ? methods : getPrototypeChain(Object.getPrototypeOf(Obj), fn.assign(getInternalMethods(Obj, true), methods)); } function warn(msg) { /* istanbul ignore else */ /*eslint-disable*/ if (typeof console !== 'undefined') { console.warn(new ReferenceError(msg)); } /*eslint-enable*/ } function uid(container, name) { var count = 0; var key = name; while (Object.hasOwnProperty.call(container, key)) { key = name + String(++count); } return key; } function formatAsConstant(name) { return name.replace(/[a-z]([A-Z])/g, function (i) { return String(i[0]) + '_' + String(i[1].toLowerCase()); }).toUpperCase(); } function dispatchIdentity(x) { if (x === undefined) return null; for (var _len = arguments.length, a = Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) { a[_key - 1] = arguments[_key]; } return a.length ? [x].concat(a) : x; } function fsa(id, type, payload, details) { return { type: type, payload: payload, meta: _extends({ dispatchId: id }, details), id: id, action: type, data: payload, details: details }; } function dispatch(id, actionObj, payload, alt) { var data = actionObj.dispatch(payload); if (data === undefined) return null; var type = actionObj.id; var namespace = type; var name = type; var details = { id: type, namespace: namespace, name: name }; var dispatchLater = function dispatchLater(x) { return alt.dispatch(type, x, details); }; if (fn.isFunction(data)) return data(dispatchLater, alt); // XXX standardize this return alt.dispatcher.dispatch(fsa(id, type, data, details)); } /* istanbul ignore next */ function NoopClass() {}