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
Add easy way to dispatch from app projects #239
Comments
I can see the need for things like external events (e.g. deep-linking), where you won't be inside the Fabulous loop. But I don't think you should use dispatch from the App projects to ask for permissions. In ElmishContacts, I used the PermissionsPlugin that allows to request asynchronously for a permission. Coupled with Even if PermissionsPlugin doesn't provide a permission I need, I tend to use DependencyService and make an interface that encapsulates the whole "ask for permission" flow in a single awaitable method, called in the Core project. Globally, one strength of Fabulous is to centralize the events inside init\update\view\subscriptions. |
I think in the context of xamarin there is nothing dangerous about a global dispatch. However it has to have the right type, ie the message type must be that of the overall application. The previous global dispatch was broken as it had generic type. The 'program' could report a dispatch function for example I think. |
Accessing the dispatch function through the program runner (exposed only by the App class) can be a good solution. What worries me is that if we give a static global dispatch, it might be misused instead of correctly flowing the dispatch function given in parameter. |
I think we need some way to dispatch messages in a clean simple way. I get your point about using the dependency service, but that feels a bit janky, having to create a class/interface just to pass a message around. In a couple of projects I've used the Xamarin.Forms messenger to pass messages around, and set up a subscription to that which dispatches messages, but it feels a bit heavyweight and after the third app that uses it, feels like it should be baked in. Permissions probably wasn't the best example, but I've also used it for platform specific stuff like handling callbacks from ai services in a third-party jar that I've bound. Global dispatch doesn't feel right, and access to a dispatch function on the program on the App was my first thought. |
Did a pull request with this feature. |
Looks like a great implementation, does exactly what is needed. |
Great. I will add it to the next release (0.28) |
It would be nice if there was an easy way to dispatch messages from the App projects.
For example permissions - these are requested asynchronously in the Android and iOS app projects, and once accepted or rejected a message could then be dispatched to update the model and UI.
The text was updated successfully, but these errors were encountered: