Skip to content

Lifetime beta ​

Class of @v12-engine/client

ts
export declare class Lifetime

The owner of what a part makes (C12): each thing kept at the line it is made (own), what to undo besides (onDispose), what it hears (listen, which owns the stopping), all taken apart in the reverse order of their making by one dispose. Safe halfway through being made, and twice; every step is taken whatever the one before it did, and one that throws is said in the log. What is kept after the end is taken apart at once

Members ​

constructor ​

ts
constructor(
    what?: string, log?: Logger);

Constructs a new instance of the Lifetime class

dispose ​

ts
dispose(): void;

Takes everything kept apart, the last kept first

disposed ​

ts
get disposed(): boolean;

Whether it was taken apart

listen ​

ts
listen(subscribe: () => (() => void) | undefined | void): void;

Hears something until the end: subscribe starts hearing and gives what stops it, which is run with the rest (lifetime.listen(() => renderer.onFrame(step)))

onDispose ​

ts
onDispose(step: (() => void) | undefined | void): void;

What to undo with the rest: nothing, for a part with nothing to undo

own ​

ts
own<T extends Disposable>(thing: T): T;

Keeps a thing, to dispose it with the rest. Gives it back, so that it is kept where it is made