Skip to content
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

Closed
jimbobbennett opened this issue Nov 29, 2018 · 7 comments
Closed

Add easy way to dispatch from app projects #239

jimbobbennett opened this issue Nov 29, 2018 · 7 comments
Labels
t/enhancement New feature or request

Comments

@jimbobbennett
Copy link

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.

@TimLariviere
Copy link
Member

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.
Do you have an example where you can't await inside the Core project?

In ElmishContacts, I used the PermissionsPlugin that allows to request asynchronously for a permission. Coupled with Cmd.ofAsyncMsgOption, you can react (or not) based on the choice of the user.
https://github.com/TimLariviere/ElmishContacts/blob/541ded8a94479090988c05a9062dc10c80955396/ElmishContacts/Helpers.fs#L41-L52

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.
And I think exposing dispatch outside can be dangerous. (a previous global dispatch has been marked obsolete).

@TimLariviere TimLariviere added the t/enhancement New feature or request label Nov 29, 2018
@dsyme
Copy link
Collaborator

dsyme commented Nov 29, 2018

And I think exposing dispatch outside can be dangerous. (a previous global dispatch has been marked obsolete).

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.

@TimLariviere
Copy link
Member

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.
It's the same function, but using the one passed in parameter is way easier to know where a dispatch occurs.

@jimbobbennett
Copy link
Author

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.

@TimLariviere
Copy link
Member

Did a pull request with this feature.
Let me know what you think.

@TimLariviere TimLariviere added this to the 1.0.0 milestone Dec 2, 2018
@jimbobbennett
Copy link
Author

Looks like a great implementation, does exactly what is needed.

@TimLariviere
Copy link
Member

Great. I will add it to the next release (0.28)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
t/enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants