Skip to content

Commit 910c18a

Browse files
committed
chore: adds an event when the components instance have been initialized
1 parent 7c50e8d commit 910c18a

File tree

1 file changed

+21
-2
lines changed
  • packages/core/src/core/Components

1 file changed

+21
-2
lines changed

packages/core/src/core/Components/index.ts

+21-2
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,26 @@ export class Components implements Disposable {
3333

3434
private _clock: THREE.Clock;
3535

36+
/**
37+
* Event that triggers the Components instance is initialized.
38+
*
39+
* @remarks
40+
* This event is triggered once when the {@link Components.init} method has been called and finish processing.
41+
* This is useful to set configuration placeholders that need to be executed when the components instance is initialized.
42+
* For example, enabling and configuring custom effects in a post-production renderer.
43+
*
44+
* @example
45+
* ```typescript
46+
* const components = new Components();
47+
* components.onInit.add(() => {
48+
* // Enable custom effects in the post-production renderer
49+
* // or any other operation dependant on the component initialization
50+
* });
51+
* components.init();
52+
* ```
53+
*/
54+
readonly onInit = new Event<undefined>();
55+
3656
/**
3757
* Adds a component to the list of components.
3858
* Throws an error if a component with the same UUID already exists.
@@ -88,13 +108,12 @@ export class Components implements Disposable {
88108
* Initializes the Components instance.
89109
* This method starts the animation loop, sets the enabled flag to true,
90110
* and calls the update method.
91-
*
92-
* @returns {void}
93111
*/
94112
init() {
95113
this.enabled = true;
96114
this._clock.start();
97115
this.update();
116+
this.onInit.trigger();
98117
}
99118

100119
/**

0 commit comments

Comments
 (0)