dphfox / Fusion

A modern reactive UI library, built specifically for Roblox and Luau.
https://elttob.uk/Fusion/
MIT License
530 stars 91 forks source link

Allow automatic wrapping of functions in springs #348

Closed Raild3x closed 2 weeks ago

Raild3x commented 2 weeks ago

This change allows for functions to be given directly to Springs so that you don't have to constantly wrap them in Computeds. Forced Old Method:

Spring(Computed(function(use)
   return if use(x) then 0 else 1
end))

New Optional Method:

Spring(function(use)
   return if use(x) then 0 else 1
end)

This would help reduce code bloat, allow for easier reading, and bring it in line with other state object usage. It should be entirely backwards compatible.

dphfox commented 2 weeks ago

This sort of API surface change isn't something that's suitable for changing without a proper design discussion. While I appreciate the initiative here, it's important that we first go over the implications of a change like this, because especially with libraries like Fusion, there could be niche edge cases that are hard to discover, that ultimately bring the idea down (as has already happened with other desirable feature requests in the past).

It's also worth noting that these API surfaces are already in the process of being reworked (see #87) so it'd be good to direct your ideas over there.

So for the time being, I'll be closing this pull request, but please do feel free to contribute to the issue with your thoughts on how the API design can be improved. It'd be useful to gather community feedback and scrutiny to see whether this is a truly backwards compatible change, how it can mesh with existing efforts, and whether it'd have implications for future API design.