-
-
Notifications
You must be signed in to change notification settings - Fork 74
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
Contexts / Environment state #278
Conversation
…ironment objects & react contexts)
Quite impressive how far you get with ~80 LOC which is almost the entire feature. |
@JordanMarr @sleepyfran I'm not happy with the naming and the API yet, but it works. Feedback is as always appreciated. Describe valueAvalonia.FuncUI/src/Examples/Component Examples/Examples.EnvApp/Program.fs Lines 15 to 19 in e2ddeba
Provide valueAvalonia.FuncUI/src/Examples/Component Examples/Examples.EnvApp/Program.fs Lines 172 to 197 in e2ddeba
Consume valueAvalonia.FuncUI/src/Examples/Component Examples/Examples.EnvApp/Program.fs Lines 24 to 32 in e2ddeba
|
Looks good, although I'd maybe make the whole providing a bit more friendly by going full React. If you make the SharedState.brush.provider(
value = brush,
content = (
...
)
) Consumption-wise I think the API is okay. I'm not a huge fan of contexts in general because they couple components with an invisible provider that makes it very hard to refactor later (going right now through a very painful transition with them in React at work, so this hits close to home 😆), and I think we have this partially solved with the store pattern that we have in some of the samples, but I also think they won't hurt and it might feel more familiar for people coming from React. |
I haven’t quite recovered from my GitHub session yesterday, but I will look at this in more detail later. @sleepyfran I recently refactored a React app to use Fable.Store instead of useContext. What is an example of the store pattern you are referring to for FuncUI? |
@JordanMarr for example the Generic Algorithm sample declares this store: Avalonia.FuncUI/src/Examples/Component Examples/Examples.GeneticAlgorithm/Views.fs Lines 15 to 28 in 200bae3
Which are then used as a normal state: Avalonia.FuncUI/src/Examples/Component Examples/Examples.GeneticAlgorithm/Views.fs Lines 168 to 170 in 200bae3
I'm not familiar with Fable.Store, so not sure if they do something different, but basicaly this just creates a global state that is then shared between all components that reference it. So in order to have something similar to a context, declaring a store like this scoped to a set of components would end up being the same. |
Good point 👍 that might be handy.
I personally think both (global shared state & shared state via contexts) have their place. |
That's actually a really good point. I guess I've never had this exact use case, but it definitely makes sense to offer this out of the box. Well, as I said, other than the provider change the rest looks all good to me. Awesome job! |
Allows controls to pass state to descendants (similar to swift UI environment objects & react contexts)