UNPKG

@threlte/core

Version:

A 3D framework for the web, built on top of Svelte and Three.js

50 lines (49 loc) 1.83 kB
import { type Readable } from 'svelte/store'; import { type Key, type Stage, type Task } from '../frame-scheduling'; export type ThrelteUseTask = { task: Task; stop: () => void; start: () => void; started: Readable<boolean>; }; export type ThrelteUseTaskOptions = { /** * If false, the task will not be started automatically and must be started * by invoking the `start` function. Defaults to true. */ autoStart?: boolean; /** * If false, the task handler will not automatically invalidate the task. * This is useful if you want to manually invalidate the task. Defaults to * true. */ autoInvalidate?: boolean; /** * The task will be added to the stage after the specified task. */ after?: (Key | Task) | (Key | Task)[]; /** * The task will be added to the stage before the specified task. */ before?: (Key | Task) | (Key | Task)[]; /** * The stage to add the task to. Defaults to the main stage. If a task object * is provided to `after` or `before`, the stage of that task will be used. */ stage?: Key | Stage; }; /** * Adds a handler to threltes unified render loop. * * `start` and `stop` functions are returned and the options allow setting the * handler to not start automatically. * * Use the options `after` and `before` to control the order of execution. Add * the task to a specific stage with the option `stage`. * * @param {(delta: number) => void} fn callback function * @param {ThrelteUseTaskOptions} options options * @returns {ThrelteUseTask} */ export declare function useTask(fn: (delta: number) => void, options?: ThrelteUseTaskOptions): ThrelteUseTask; export declare function useTask(key: Key, fn: (delta: number) => void, options?: ThrelteUseTaskOptions): ThrelteUseTask;