@chayns-components/maps
Version:
A set of beautiful React components for developing your own applications with chayns.
36 lines (33 loc) • 2.04 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.useDeepCompareEffectForMaps = void 0;
var _react = _interopRequireWildcard(require("react"));
var _fastEquals = require("fast-equals");
var _typescriptGuards = require("@googlemaps/typescript-guards");
function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function (e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, default: e }; if (null === e || "object" != typeof e && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (const t in e) "default" !== t && {}.hasOwnProperty.call(e, t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, t)) && (i.get || i.set) ? o(f, t, i) : f[t] = e[t]); return f; })(e, t); }
// Note do not touch!
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
const deepCompareEqualsForMaps = (0, _fastEquals.createCustomEqual)(deepEqual => (a, b) => {
if ((0, _typescriptGuards.isLatLngLiteral)(a) || a instanceof google.maps.LatLng || (0, _typescriptGuards.isLatLngLiteral)(b) || b instanceof google.maps.LatLng) {
return new google.maps.LatLng(a).equals(new google.maps.LatLng(b));
}
// eslint-disable-next-line @typescript-eslint/no-unsafe-call,@typescript-eslint/no-unsafe-return
return deepEqual(a, b);
});
const useDeepCompareMemoize = value => {
const ref = _react.default.useRef();
if (!deepCompareEqualsForMaps(value, ref.current)) {
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
ref.current = value;
}
return ref.current;
};
const useDeepCompareEffectForMaps = (callback, dependencies) => {
// eslint-disable-next-line react-hooks/exhaustive-deps
(0, _react.useEffect)(callback, dependencies.map(useDeepCompareMemoize));
};
exports.useDeepCompareEffectForMaps = useDeepCompareEffectForMaps;
//# sourceMappingURL=positionInput.js.map