Skip to content

Commit

Permalink
chore: adds an event when the components instance have been initialized
Browse files Browse the repository at this point in the history
  • Loading branch information
HoyosJuan committed Sep 30, 2024
1 parent 7c50e8d commit 910c18a
Showing 1 changed file with 21 additions and 2 deletions.
23 changes: 21 additions & 2 deletions packages/core/src/core/Components/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<undefined>();

/**
* Adds a component to the list of components.
* Throws an error if a component with the same UUID already exists.
Expand Down Expand Up @@ -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();
}

/**
Expand Down

0 comments on commit 910c18a

Please sign in to comment.