undux
Version:
Dead simple state management for React
32 lines • 916 B
JavaScript
/**
* 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.
*/
export function equals(a, b) {
if (isImmutable(a) && isImmutable(b)) {
return a.equals(b);
}
return a === b;
}
export function isImmutable(a) {
return (!!a &&
typeof a === 'object' &&
('@@__IMMUTABLE_ITERABLE__@@' in a || '@@__IMMUTABLE_RECORD__@@' in a));
}
export function getDisplayName(Component) {
return Component.displayName || Component.name || 'Component';
}
// Strict Object.keys
export function keys(o) {
return Object.keys(o);
}
export function mapValues(o, f) {
let result = {};
keys(o).forEach((k) => (result[k] = f(o[k], k)));
return result;
}
export function some(o, f) {
return keys(o).some((k) => f(o[k], k));
}
//# sourceMappingURL=utils.js.map