From 910c18a5d13b8eb77f1ccadcf4b0eeb6c309bf1f Mon Sep 17 00:00:00 2001 From: Juan Hoyos Date: Mon, 30 Sep 2024 16:33:57 -0500 Subject: [PATCH] chore: adds an event when the components instance have been initialized --- packages/core/src/core/Components/index.ts | 23 ++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/packages/core/src/core/Components/index.ts b/packages/core/src/core/Components/index.ts index 2a53f64e4..08f7d9b98 100644 --- a/packages/core/src/core/Components/index.ts +++ b/packages/core/src/core/Components/index.ts @@ -33,6 +33,26 @@ export class Components implements Disposable { private _clock: THREE.Clock; + /** + * Event that triggers the Components instance is initialized. + * + * @remarks + * This event is triggered once when the {@link Components.init} method has been called and finish processing. + * This is useful to set configuration placeholders that need to be executed when the components instance is initialized. + * For example, enabling and configuring custom effects in a post-production renderer. + * + * @example + * ```typescript + * const components = new Components(); + * components.onInit.add(() => { + * // Enable custom effects in the post-production renderer + * // or any other operation dependant on the component initialization + * }); + * components.init(); + * ``` + */ + readonly onInit = new Event(); + /** * Adds a component to the list of components. * Throws an error if a component with the same UUID already exists. @@ -88,13 +108,12 @@ export class Components implements Disposable { * Initializes the Components instance. * This method starts the animation loop, sets the enabled flag to true, * and calls the update method. - * - * @returns {void} */ init() { this.enabled = true; this._clock.start(); this.update(); + this.onInit.trigger(); } /**