core
core copied to clipboard
Add support for yielding in component constructors
Constructors that yield are useful for setting up class members using functions like .WaitForChild()
. The component will not setup any lifecycle events until the constructor is complete. This allows for patterns like:
@Component({ tag: "CharacterComponent" })
export class CharacterComponent extends BaseComponent<{}, Model> implements OnPhysics {
private humanoid: Humanoid;
constructor() {
super();
const humanoid = this.instance.WaitForChild("Humanoid", 5);
assert(humanoid && humanoid.IsA("Humanoid"));
this.humanoid = humanoid;
}
onPhysics() {
// use this.humanoid
}
}
removeComponent
would need to wait for the constructor to finish before calling destroy()