-
-
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
Add something like "ComputedInstanceProperty" #134
Comments
Sorry for the lack of response - I read the notification on my phone a couple days ago but never acted on it. I've been thinking about this though, and I think the real root issue here is that it's difficult to change what your UI hydrates. I'm not keen at all on introducing overly specific helpers - about the furthest I'm comfortable with is in the ballpark of things like I have many conflicting thoughts about being able to redirect where you're hydrating to:
It's worth noting that in Fusion v0.2 the code already becomes partially syntactically simplified thanks to local function InstanceDerivedProperty(source, property)
local currentProp = Value()
local function updateSource()
-- TODO: unbind this in the future
Hydrate(source:get()) {
[Out(property)] = currentProp
}
end
Observer(source):onChange(updateSource)
updateSource()
return Computed(function()
return currentProp:get()
end)
end Of course, being able to redirect Hydrate solves this use case perfectly, but it raises questions about whether it's actually a net positive for code quality: local function InstanceDerivedProperty(source, property)
local currentProp = Value()
Hydrate(source) {
[Out(property)] = currentProp
}
return Computed(function()
return currentProp:get()
end)
end This is not something I'm prepared to answer right now. |
Using Hydrate to make an existing interface functional and using Hydrate just to abuse Hydrate isn't what I'm looking for, I don't think. |
Kind of a duplicate of #47 but it seems it's being reconsidered. |
I think the difference is that the particular situation this issue is concerning can't really be solved by hydration (in a non-memory-leaky/unsound way) because the instance I want the property of is contained in state and may change. |
Merging with #206 |
I'm making a Tool and I'd like to use Fusion for its state management capabilities. It's just really nice for building up a dependency graph for the final "can this tool fire" state, one that won't ever error or fail due to unexpected edge cases.
One of my requirements for the tool firing is that the character's Humanoid must be alive. This sounds simple but is actually surprisingly nuanced for two main reasons:
nil
at any time, and may change any number of times.Humanoid.Health
property is not itself a state object, so you can't just puthumanoid:get().Health
in aComputed
.As described in #128, I have made a function that solves both of these problems:
I was waiting on feedback from @Elttob but as they haven't replied in a couple days and I've gotten a green-ish light from @nottirb to go ahead and make this a full feature request, I'm going to go ahead with this anyway.
This feature request is intended to track the possible inclusion of such a utility in Fusion so that tracking properties of an instance in state requires less boilerplate. It follows the trend of ComputedPairs/ComputedKeys/ComputedValues functions that take a state, extract something from whatever is inside, and properly update whenever that dependency does.
Please note that while the above function is technically sound as far as I can tell, it will most likely be implemented differently in Fusion so this should not be considered any sort of code proposal. It's only included for illustrative purposes, since it doesn't work perfectly with Luau's type system.
The text was updated successfully, but these errors were encountered: