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 TrackedComponentEcstatic 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#
onAddCalled when the TrackedComponent
is added to an Entity
.
#
onUpdateCalled whenever a property on the Component
changes. Can be called very frequently on active components, so be careful with this.
#
onRemoveCalled when a TrackedComponent
is removed from an Entity
.