Closed OttoHatt closed 2 years ago
Bindings can explicitly be two way in this scenario. Right now the canonical way to do bindings is this:
local state = Instance.new("StringValue")
state.Text = "Hi"
Blend.New "TextBox" {
Text = state;
[Blend.OnChange("Text")] = state;
}
Note this nicely allows for multi-directional bindings in an explicit way.
BInd can be a nice way to shortcut this, at some confusion to the user on when to use one over the other.
I'll consider this.
Yep, been thinking about this since posting the issue and, I think defining it explicitly as two statements is better.
The concern I had that this fixes is that [...] =ValueObject
is not great for readability; you can't tell at a glance if it's a function or ValueObject. However, I now think this is fine as it's short to write - UI code doesn't need to get any messier!
Svelte is a frontend web library, with a feature I really like called Bindings. They allow you to define information as flowing both ways on a component's property.
Usage would be
[Blend.Bind(string)] = ValueObject<any>
. It would simply be a shorthand for defining[prop] = valueBase
and[Blend.OnChange(prop)] = valueBase
.In this example, both will function identically; setting the textbox contents to
"hi"
immediately, then updating the value of the state from aGetPropertyChangedSingnal("Text")
as the user enters text. And when the value of state changes, the property will be set again.This could even be used to deprecate ValueObject-like classes as event handlers (as it isn't a very intuitive API imo. It feels like hidden functionality, as with typical roblox
:Connect
you think it'd only take a Callback)