UNPKG

respond-framework

Version:
38 lines (35 loc) 1.4 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.memo = exports.isEqualShallow = exports.isEqualDeepPartial = exports.isEqualDeep = void 0; var _react = require("react"); const isEqualDeep = (x, y) => { const tx = typeof x; const ty = typeof y; return x && y && tx === obj && tx === ty ? ok(x).length === ok(y).length && ok(x).every(k => isEqualDeep(x[k], y[k])) : x === y; }; exports.isEqualDeep = isEqualDeep; const obj = 'object'; const ok = Object.keys; // isEqualDeepPartial(partialObject, completeObject) // eg: isEqualDeepPartial({ foo: 123 }, { foo: 123, bar: 'baz' }) === true const isEqualDeepPartial = (x, y) => { const tx = typeof x; const ty = typeof y; return x && y && tx === obj && tx === ty ? ok(x).every(k => isEqualDeepPartial(x[k], y[k])) : x === y; }; exports.isEqualDeepPartial = isEqualDeepPartial; const isEqualShallow = (x, y) => x && y && typeof x === obj && typeof y === obj ? ok(x).length === ok(y).length && ok(x).every(k => x[k] === y[k]) : x === y; exports.isEqualShallow = isEqualShallow; const createArePropsEqual = (k = 'arg') => ({ [k]: prevArg, testProps: _, ...prev }, { [k]: nextArg, testProps: __, ...next }) => isEqualShallow(prev, next) && isEqualShallow(prevArg, nextArg); const memo = (Component, k) => /*#__PURE__*/(0, _react.memo)(Component, createArePropsEqual(k)); exports.memo = memo;