UNPKG

@rbxts/proton

Version:

Framework for Roblox game development

74 lines (73 loc) 2.45 kB
/// <reference types="@rbxts/compiler-types" /> declare type LifecycleCallback<T> = (...args: Parameters<T>) => void; /** * The execution behavior of a custom lifecycle. */ export declare enum LifecycleBehavior { /** * Execute the lifecycle callbacks one-by-one. */ Series = 0, /** * Execute the lifecycle callbacks all at the same * time. This calls the callbacks using `task.spawn` * internally. */ Concurrent = 1 } /** * Custom lifecycle for Proton providers. */ export declare class ProtonLifecycle<T extends LifecycleCallback<T>> { private callbacks; private onRegisteredCallbacks; private onUnregisteredCallbacks; /** * Constructs a new lifecycle * @param behavior Execution behavior (defaults to `LifecycleBehavior.Concurrent`) */ constructor(behavior?: LifecycleBehavior); private callOnUnregisteredCallbacks; private fireConcurrent; private fireSeries; /** * Fire the lifecycle. * @param args Arguments passed to the registered callbacks. */ fire(...args: Parameters<T>): void; /** * Register a lifecycle. This is usually only called from * the `@OnLifecycle` decorator. * @param callback Callback * @param memoryCategory Memory category */ register(callback: T, memoryCategory: string): void; /** * Unregister a lifecycle. * @param callback Callback to unregister */ unregister(callback: T): void; /** * Unregister all callbacks. */ unregisterAll(): void; /** * Listen to when a callback is registered. * @param callback Registered callback. * @returns `() => void` cleanup function (call to stop listening to `onRegistered`) */ onRegistered(callback: (c: T) => void): () => void; /** * Listen to when a callback is unregistered. * @param callback Unregistered callback. * @returns `() => void` cleanup function (call to stop listening to `onUnregistered`) */ onUnregistered(callback: (c: T) => void): () => void; } /** * OnLifecycle decorator. * @param lifecycle Attached lifecycle */ export declare function Lifecycle<T extends LifecycleCallback<T>>(lifecycle: ProtonLifecycle<T>): (target: defined, property: string, descriptor: TypedPropertyDescriptor<(this: defined, ...args: Parameters<T>) => void>) => void; export declare const ProtonStart: ProtonLifecycle<() => void>; export {};