59 lines
1.3 KiB
JavaScript
59 lines
1.3 KiB
JavaScript
// Metro module 3954 (f3955).
|
|
import { useEffect, useRef } from "react";
|
|
const deps = Symbol("UNINITIALIZED");
|
|
export function useDisposableMemo(a0, a1, a2, a3) {
|
|
const ref = useRef({
|
|
value: void 0,
|
|
deps,
|
|
pendingDisposal: null
|
|
});
|
|
const ref2 = useRef(a1);
|
|
ref2.current = a1;
|
|
const ref3 = useRef(a3);
|
|
ref3.current = a3;
|
|
if (!(ref.current.deps !== deps && (function depsEqual(a0, a1) {
|
|
if (a0.length !== a1.length) {
|
|
return false;
|
|
}
|
|
const length = a0.length;
|
|
let r0 = 0;
|
|
if (0 < length) {
|
|
do {
|
|
const r14 = Object.is(a0[r0], a1[r0]);
|
|
const r1 = r0;
|
|
if (!r14) {
|
|
return false;
|
|
}
|
|
r0 = r1 + 1;
|
|
} while (r0 < a0.length);
|
|
}
|
|
return true;
|
|
})(ref.current.deps, a2))) {
|
|
if (ref.current.deps !== deps) {
|
|
if (ref3.current) {
|
|
ref3.current.current = void 0;
|
|
}
|
|
try {
|
|
ref2.current(ref.current.value);
|
|
} catch ($e) {}
|
|
}
|
|
ref.current = {
|
|
value: a0(),
|
|
deps: a2,
|
|
pendingDisposal: null
|
|
};
|
|
if (ref3.current) {
|
|
ref3.current.current = ref.current.value;
|
|
}
|
|
}
|
|
useEffect(() => () => {
|
|
if (ref3.current) {
|
|
ref3.current.current = void 0;
|
|
}
|
|
try {
|
|
ref2.current(ref.current.value);
|
|
} catch ($e) {}
|
|
}, []);
|
|
return ref.current.value;
|
|
}
|