Skip to content

Commit

Permalink
Add :api/send and rename :api/dispatch event handler
Browse files Browse the repository at this point in the history
  • Loading branch information
just-sultanov committed May 5, 2022
1 parent 0004688 commit d3968ab
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions src/main/clojure/metaverse/ui/api.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,19 @@


(rf/reg-fx
:api/dispatch
:api/invoke
(fn [{:keys [event on-success on-failure]}]
(-> (.. js/window -bridge (dispatch (t/write event)))
(-> (.. js/window -bridge (invoke (t/write event)))
(t/then-read)
(.then (fn [res]
(if (r/anomaly? res)
(rf/dispatch (conj on-failure res))
(rf/dispatch (conj on-success res)))))
(.catch (fn [error]
(rf/dispatch (conj on-failure error)))))))


(rf/reg-fx
:api/send
(fn [event]
(.. js/window -bridge (send (t/write event)))))

0 comments on commit d3968ab

Please sign in to comment.