Files
pihkaal-me/app/composables/useUpdate.ts
2025-11-09 16:20:30 +01:00

19 lines
539 B
TypeScript

export type UpdateCallback = (deltaTime: number, realFrameTime: number) => void;
export const useUpdate = (callback: UpdateCallback) => {
const registerUpdateCallback = inject<
(callback: UpdateCallback) => () => void
>("registerUpdateCallback");
onMounted(() => {
if (!registerUpdateCallback) {
throw new Error(
"Missing registerUpdateCallback - useUpdate must be used within a Screen component",
);
}
const unregister = registerUpdateCallback(callback);
onUnmounted(unregister);
});
};