adospace / reactorui-maui

MauiReactor is a MVU UI framework built on top of .NET MAUI
MIT License
568 stars 47 forks source link

[Enhancement] Input control text two-way binding to State. #95

Closed chaoyebugao closed 1 year ago

chaoyebugao commented 1 year ago

In Button.Text(), it is always two-way bound, whether reading or writing. But in Entry/Editor it doesn't exist by default, it need to implement the OnTextChanged event, like below:

new Entry()
  .Text(State.Username)
  .Placeholder("Username")
  .OnTextChanged((s,e)=> SetState(_ => _.Username = e.NewTextValue, false))

Is it achievable if I'm not missing something? I suggest this.

adospace commented 1 year ago

I'm not sure that I correctly understand your question. Your code seems fundamentally correct, what's the possible enhancement you see?

adospace commented 1 year ago

Oh if you're asking that MauiReactor should handle two-way binding the answer is no, because in a mvu approach you should never directly modify the state. In other words, there isn't a binding one-way nor two-way here. You have just a model that describes how your app should appear based on the current state, reacts to events that in turn change state. Changing the component state usually triggers component rendering .