fewkz / froact

Wrapper around Roact & Roact Hooks to simplify UI development and add full, correct Luau typing
MIT License
3 stars 0 forks source link

new way to do binding shiss #13

Open fewkz opened 1 year ago

fewkz commented 1 year ago

What do we want? Fully typed bindings! When do we want it? NOW! Anyways, here's what it would look like:

image

Beautiful, right? Absolutely glorious and game-changing. Anyways, I figured out how to implement the types, so we'll be seeing it soon(er or later). Instead of doing

local newBinding = Roact.joinBindings({binding1, binding2}):map(function(vals) 
    local v1, v2 = unpack(vals)
    return '' + v1 + ' ' + v2
end)

you get the luxury of being able to simply do:

local newBinding = froact.join(binding1, binding2).map(function(v1, v2)
    return '' + v1 + ' ' + v2
end)

Absolutely beautiful, if I do say so myself, and with full luau typing support! Everything is typed, which is not possible with the way Roact bindings are implemented. image

fewkz commented 1 year ago

This is a little complicated to implement, I also don't know what the type of Binding<T> would even be. It could be something like { getValue: () -> T }, although I think luau typing is a little finnicky when it comes to function types, so { value: T }, might be better, but you can't do .value on a binding, so we'd have to wrap bindings to make that work.

fewkz commented 1 year ago

An implementation of this is available in the https://github.com/fewkz/froact/tree/ref-binding branch