-
Notifications
You must be signed in to change notification settings - Fork 117
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Rethinking State Management #158
Comments
Originally, it was designed similar. I had StatefulView and the Body build passed in the State. You can see it in the old history. However it was removed since this is simpler long term. State is needed for basic data types, if you want to use them directly. And right now, I you can subclass BindingObject for complex objects or implement the interface. This is temporary! Eventually I want you to be able to do: [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 as well using the same techniques! But that is long term. However I still shouldnt need any of the StatefulView<> or State stuff. 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 |
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 { 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.The text was updated successfully, but these errors were encountered: