Skip to content
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

Closed
Dionysusnu opened this issue Sep 8, 2021 · 4 comments
Closed

InstanceProperty(instance, propertyName) state-like helper #47

Dionysusnu opened this issue Sep 8, 2021 · 4 comments
Labels
kind: enhancement New feature or request status: rejected This will not be worked on

Comments

@Dionysusnu
Copy link
Contributor

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

@dphfox
Copy link
Owner

dphfox commented Sep 8, 2021

This is definitely something we can consider, though perhaps with a more concise name.

It usually ends up being wrapped in a heartbeat updating state.

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.

@dphfox dphfox added the kind: enhancement New feature or request label Sep 8, 2021
@Dionysusnu
Copy link
Contributor Author

This is definitely something we can consider, though perhaps with a more concise name.

It usually ends up being wrapped in a heartbeat updating state.

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.
Even so, that's verbose and a lot of code repetition.

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

@dphfox dphfox added the status: evaluating Currently gauging feedback label Sep 29, 2021
@dphfox
Copy link
Owner

dphfox commented Dec 7, 2021

After some more thinking, I think that this would be better served by hydration (#34) and out props (#88), so I'm going to close this issue for now.

@dphfox dphfox closed this as completed Dec 7, 2021
@dphfox dphfox added status: rejected This will not be worked on and removed status: evaluating Currently gauging feedback labels Dec 7, 2021
@Dionysusnu
Copy link
Contributor Author

Dionysusnu commented Mar 28, 2022

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind: enhancement New feature or request status: rejected This will not be worked on
Projects
None yet
Development

No branches or pull requests

2 participants