decord/source/hooks/usePrevious.tsx

56 lines
1.4 KiB
TypeScript
Raw Normal View History

2026-08-25 06:04:03 +00:00
// Module ID: 9000
// Function ID: 9001
2026-07-20 16:05:17 +00:00
// Name: usePrevious
2026-07-29 08:29:29 +00:00
// Dependencies: [19, 2]
2026-07-31 08:44:05 +00:00
// Exports: default, useCurrentWhen, usePreviousWhen
2026-07-20 16:05:17 +00:00
2026-08-25 06:04:03 +00:00
// Module 9000 (usePrevious)
2026-08-24 06:08:38 +00:00
import set from "set" /* 2 */;
import noop from "noop" /* 19 */;
2026-07-23 10:11:24 +00:00
2026-07-29 08:29:29 +00:00
({ useRef: c0, useEffect: closure_1 } = noop);
2026-08-24 06:08:38 +00:00
const result = set.fileFinishedImporting("hooks/usePrevious.tsx");
2026-07-20 16:05:17 +00:00
export default function usePrevious(arg0) {
2026-07-23 10:11:24 +00:00
const callback = arg0;
const tmp = callback(null);
const callback2 = tmp;
2026-07-20 16:05:17 +00:00
const items = [arg0];
2026-07-23 10:11:24 +00:00
callback2(() => {
closure_1.current = closure_0;
2026-07-20 16:05:17 +00:00
}, items);
return tmp.current;
};
export const usePreviousWhen = function usePreviousWhen(value) {
value = value.value;
2026-07-29 08:29:29 +00:00
const callback = value;
2026-07-20 16:05:17 +00:00
const shouldUpdate = value.shouldUpdate;
2026-08-24 06:08:38 +00:00
closure_2 = undefined;
2026-07-29 08:29:29 +00:00
const tmp = callback(null);
2026-08-24 06:08:38 +00:00
closure_2 = tmp;
2026-07-20 16:05:17 +00:00
const items = [value, shouldUpdate];
shouldUpdate(() => {
if (shouldUpdate) {
2026-08-24 06:08:38 +00:00
closure_2.current = closure_0;
2026-07-20 16:05:17 +00:00
}
}, items);
return tmp.current;
};
2026-07-31 08:44:05 +00:00
export const useCurrentWhen = function useCurrentWhen(value) {
let current = value.value;
const shouldUpdate = value.shouldUpdate;
2026-08-24 06:08:38 +00:00
closure_2 = undefined;
2026-07-31 08:44:05 +00:00
const tmp = current(null);
2026-08-24 06:08:38 +00:00
closure_2 = tmp;
2026-07-31 08:44:05 +00:00
const items = [current, shouldUpdate];
shouldUpdate(() => {
if (shouldUpdate) {
2026-08-24 06:08:38 +00:00
closure_2.current = current;
2026-07-31 08:44:05 +00:00
}
}, items);
if (!shouldUpdate) {
current = tmp.current;
}
return current;
};