Open JeroMiya opened 4 years ago
Originally, it was designed similar. I had StatefulView
[BindingObject]
class MyObject
{
public string Foo{get;set;}
}
And that is it! Or maybe just let you subclass an interface?
Or I want some language/runtime changes that would eliminate both! But those would take longer.
Eventually, I may be able to remove State
Also, [Inject] exists, its just called [Environment], it will grab anything already set. I will add some better examples of that later!
How does Blazor do it? It seems almost magic. No state wrappers or attributes or interfaces. I'm guessing it just rerenders after any DOM event callback? That might be OK if you could opt-out of it and manage re-renders manually if desired (e.g. for performance).
Would it be possible to just reflect on the view classes themselves and sort of.. make the view or any of its public properties implicitly a [BindingObject] somehow?
Also, would it be possible to support both models with a separate base class? For instance, if the explicit React/Flutter style SetState(...)
method was a better model for an application's state management, could they opt-in to it?
[BindingObject] class MyObject { public string Foo {get;set;} public int ClickCount {get;set;} public void MyClickMethod() {....} }
So [BindingObject] binds the whole of MyObject to my View? And how would one reference (and bind to) individual properties from individual controls within my view, such as Foo?
Perhaps via an argument passed to the Body as mentioned above? Such as below:
Body = (state => new VStack { new Text (() => $"Click Count: {state.ClickCount}"), new Button("Update Text", () => state.MyClickMethod()), });
So "state" would be an instance of MyObject? Just a thought
Not sure if this is covered by the framework yet or not (if so it's not documented?) - state management seems a bit cumbersome in the current samples. Requiring the use of State or BindingObject subclasses seems like a lot of boilerplate for something that should be pretty simple. I'd like to see a couple of programming models supported:
Original sample:
Simplified POCO state management with
SetState(Action setter)
function:External state management with
NotifyStateChanged()
, equivalent toSetState(() => {})
:Going a bit further, if we change
Body
to take the state as an argument, we can make make this a bit more elegant:The nice thing about
StatefulView<TState>
would be that, given the framework is now explicitly aware of a view's state, it can serialize/deserialize it during hot reload to more easily implement a stateful hot reload.