AppliedMechanic
This was deprecated in v1.0.0
The object a Mechanic creates for each instance it is applied to. You get
one from Mechanic:Apply, Mechanic:GetApplied
or as the second argument of Mechanic:OnAdded. Do not construct it
yourself; use Mechanic:Apply instead.
It owns a Trove that is cleaned (and the instance removed from the Mechanic) when the
instance is destroyed, leaves the allowed Ancestors, or is revoked. Its Data field starts as
a shallow copy (table.clone) of the Mechanic's Shared table unless data was passed to
Apply, and newConstructor / bindToClass replace it with the constructed object.
local applied = Spinner:GetApplied(workspace.Windmill)
if applied then
applied:GetData().Speed = 10
applied.Trove:Add(function() print("cleaned") end)
end
This package is no longer maintained; see the deprecation notice on Mechanic.
Properties
Instance
This item is read only and cannot be modified. Read OnlyAppliedMechanic.Instance: InstanceThe instance this mechanic is applied to.
Mechanic
This item is read only and cannot be modified. Read OnlyThe Mechanic that created this object.
Shared
This item is read only and cannot be modified. Read OnlyAppliedMechanic.Shared: TThe Mechanic's shared table (the same table for every instance).
Data
AppliedMechanic.Data: TPer-instance data. A shallow copy of Shared, the data passed to Apply, or the object built by newConstructor / bindToClass.
Trove
AppliedMechanic.Trove: TroveA Trove extended from the Mechanic's Trove. It is cleaned when the instance is destroyed, untagged, leaves the allowed ancestors, or Destroy is called; put per-instance connections in it.
Functions
new
AppliedMechanic.new(data: T?--
Initial Data; defaults to a shallow copy of mechanic.Shared.
) → AppliedMechanic<T>--
The new applied mechanic.
Constructs a new AppliedMechanic for instance, registers it in mechanic.Applications,
attaches its Trove to the instance and fires mechanic.InstanceAdded. Called by
Mechanic:Apply; you should not need to call it directly because it skips the duplicate check
and does not add the tag.
GetData
AppliedMechanic:GetData() → T--
The per-instance data.
Returns the per-instance data associated with this applied mechanic (the same table as
the Data field).
GetShared
AppliedMechanic:GetShared() → T--
The Mechanic's shared table.
Returns the shared table inherited from the Mechanic config. It is shared by every instance of the mechanic, so changes here affect all of them.
Destroy
AppliedMechanic:Destroy() → ()
Cleans the Trove, removes the instance from the Mechanic's Applications and fires
InstanceRemoved. The tag stays on the instance, so the mechanic will be re-applied if the
instance is re-tagged or Apply is called again; use Mechanic:Revoke to also remove the tag.