-
-
Notifications
You must be signed in to change notification settings - Fork 103
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
InstanceProperty(instance, propertyName) state-like helper #47
Comments
This is definitely something we can consider, though perhaps with a more concise name.
There shouldn't be any reason to do this - instead of connecting to Heartbeat, you could also connect to a property change event in a comparable number of characters. |
Unfortunately not all events fire with GetPropertyChangedSignal. Looking at you, BasePart.Velocity. local partColor = State(myPart.Color)
myPart:GetPropertyChangedSignal("Color"):Connect(function()
partColor:set(myPart.Color)
end)
local partTransparency = State(myPart.Transparency)
myPart:GetPropertyChangedSignal("Transparency"):Connect(function()
partTransparency:set(myPart.Transparency)
end)
-- now we can use partColor and partTransparency as opposed to local partColor = InstanceProperty(myPart, "Color")
local partTransparency = InstanceProperty(myPart, "Transparency")
-- now we can use partColor and partTransparency |
Worth noting that this is now supported for static instances with #121: local instanceTransparency = Value(instance.Transparency)
Hydrate(instance)({
[Out("Transparency")] = instanceTransparency,
})
-- later
local foo = Computed(function()
return 1 - instanceTransparency:get()
end) And for dynamic instance references, is in consideration at #134 |
Currently it is quite annoying in Fusion to base a Computed off of an instance property. It usually ends up being wrapped in a heartbeat updating state. It also easily causes footguns with #44 if it is a table generated based off of the property.
This state-like would use either GetPropertyChangedSignal or Heartbeat (and maybe automatically choosing between those two) to update the state's dependents when the property changes.
Adding this would probably be subject to #40
The text was updated successfully, but these errors were encountered: