oliyh / martian

The HTTP abstraction library for Clojure/script, supporting OpenAPI, Swagger, Schema, re-frame and more
MIT License
526 stars 45 forks source link

[re-frame] Error when performing request immediately after init #57

Closed polymeris closed 5 years ago

polymeris commented 5 years ago

Calling martian/init and immediately dispatching a ::martian/request throws an error in ::on-complete: No protocol method ISet.-disjoin defined for type cljs.core/List

I think it is because re-frame/dispatch-sync is called in an async go block:

https://github.com/oliyh/martian/blob/6c1a3e6af971ebe3cd3352ffa44a45b65819a1b8/re-frame/src/martian/re_frame.cljs#L60

oliyh commented 5 years ago

Hi,

Yes, you are right - init is asynchronous because it involves an http call. You can use core.async/<! on the return value of init to block until it is ready, and then make your own call to Martian.

e.g.

(go (<! (martian/init "http://swagger.com")
    (re-frame/dispatch [::martian/request :some-operation {}]))
polymeris commented 5 years ago

Thanks for the quick response. That solution should work.