Lifecycle
class exported by @mwillbanks/tuil-core.
class
Public class exported by @mwillbanks/tuil-core.
export class Lifecycle {
#state: AppLifecycleState;
readonly #observers: Set<
(state: AppLifecycleState, previous: AppLifecycleState) => void
>;
constructor() {
this.#state = "created";
this.#observers = new Set();
}
get state(): AppLifecycleState {
return this.#state;
}
transition(next: AppLifecycleState): void {
if (!transitions[this.#state].includes(next)) {
throw new Error(`Invalid lifecycle transition: ${this.#state} → ${next}`);
}
const previous = this.#state;
this.#state = next;
for (const observer of this.#observers) {
observer(next, previous);
}
}
observe(
observer: (state: AppLifecycleState, previous: AppLifecycleState) => void,
): () => void {
this.#observers.add(observer);
return deleteOnDispose(this.#observers, observer);
}
}Members
| Member | Type | Required | Description | Related types |
|---|---|---|---|---|
#state | AppLifecycleState | Yes | The #state member uses the AppLifecycleState contract. | AppLifecycleState |
#observers | Set<(state: AppLifecycleState, previous: AppLifecycleState) => void> | Yes | The #observers member uses the Set<(state: AppLifecycleState, previous: AppLifecycleState) => void> contract. | AppLifecycleState |
__constructor | any | Yes | The __constructor member uses the any contract. | — |
state | AppLifecycleState | Yes | The state member uses the AppLifecycleState contract. | AppLifecycleState |
transition | (next: AppLifecycleState) => void | Yes | The transition member uses the (next: AppLifecycleState) => void contract. | AppLifecycleState |
observe | (observer: (state: AppLifecycleState, previous: AppLifecycleState) => void) => () => void | Yes | The observe member uses the (observer: (state: AppLifecycleState, previous: AppLifecycleState) => void) => () => void contract. | AppLifecycleState |
Parameters
This declaration has no public members.
Returns
This declaration does not return a value.
Throws
No thrown errors are documented for this declaration.
Related types
Source
View the secondary source reference