TrackedComponent
Sometimes it can be really helpful to react to changes in a Component. Ecstatic helps with this by offering a TrackedComponent. a TrackedComponent is a decorated Component, allowing observability without changing the original Component.
caution
TrackedComponent uses JS Proxies under the hood, and as such incurs a very small performance hit. This generally is not a problem at all, but it might not be wise to always use them by default.
Creating a TrackedComponent#
Ecstatic offers a trackComponent function that is used to create a TrackedComponent class constructor. trackComponent takes the class constructor of the original Component, and a config object used to define lifecycle methods.
TrackedComponent Lifecycle Methods#
onAdd#
Called when the TrackedComponent is added to an Entity.
onUpdate#
Called whenever a property on the Component changes. Can be called very frequently on active components, so be careful with this.
onRemove#
Called when a TrackedComponent is removed from an Entity.