-
-
Notifications
You must be signed in to change notification settings - Fork 718
[Enhancement]: Add a default Effect Handler For Promises #808
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
Comments
Maybe also add a |
First impression: to me this looks a bit awkward compared to other re-frame syntax (overloaded And isn't a call to Could you point to a discussion of the problem that this solves? |
I wonder if passing a function that returns a JS promise would mitigate things:
|
Seems like nice sugar. We do a lot of re-frame testing using jvm i.e. cljc I presume this would not have any adverse affects on the portability? |
Something slightly different I would love Re-frame to support, is promises in the effects and waiting for them in this way: (rf/reg-fx :fetch
(fn [{:keys [url]}]
(js/fetch url)))
(rf/reg-event-fx ::fetch-data
(fn [_ [_ params]]
{:fx [[:promise {:fx [:fetch {:url "https://api.example.com/data"}]
:then ,,,
:catch ,,,}]]})) |
I've been using https://github.com/smogg/re-promise as a promises effect handler and it works just fine |
I'd add two more features:
(rf/reg-fx
:promise
(fn [{:keys [promise on-success on-failure]}]
(-> promise
force
(js/Promise.resolve)
(.then ...)
...)))
;; all supported:
:promise (js/fetch "https://api.example.com/data")
:promise (delay (js/fetch "https://api.example.com/data"))
:promise {:literal :value}
:promise (delay {:literal :value})
|
This is something that I'd rather see in the documentation as an code example than as a feature implemented in the library. Promises are an everyday thing for JS developers; explaining how to handle them with fx may help the understanding of fx through a familiar concept. |
Uh oh!
There was an error while loading. Please reload this page.
Something basic like:
Example Usage:
The text was updated successfully, but these errors were encountered: