UNPKG

undux

Version:

Dead simple state management for React

41 lines 1.28 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.some = exports.mapValues = exports.keys = exports.getDisplayName = exports.isImmutable = exports.equals = void 0; /** * TODO: Avoid diffing by passing individual values into a React component * rather than the whole `store`, and letting React and `shouldComponentUpdate` * handle diffing for us. */ function equals(a, b) { if (isImmutable(a) && isImmutable(b)) { return a.equals(b); } return a === b; } exports.equals = equals; function isImmutable(a) { return (!!a && typeof a === 'object' && ('@@__IMMUTABLE_ITERABLE__@@' in a || '@@__IMMUTABLE_RECORD__@@' in a)); } exports.isImmutable = isImmutable; function getDisplayName(Component) { return Component.displayName || Component.name || 'Component'; } exports.getDisplayName = getDisplayName; // Strict Object.keys function keys(o) { return Object.keys(o); } exports.keys = keys; function mapValues(o, f) { var result = {}; keys(o).forEach(function (k) { return (result[k] = f(o[k], k)); }); return result; } exports.mapValues = mapValues; function some(o, f) { return keys(o).some(function (k) { return f(o[k], k); }); } exports.some = some; //# sourceMappingURL=utils.js.map