Skip to content

Commit

Permalink
Improving docs, guarding against pending-operations being nilled #93
Browse files Browse the repository at this point in the history
  • Loading branch information
oliyh committed Aug 25, 2020
1 parent c6e32ac commit a3695b8
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 12 deletions.
21 changes: 11 additions & 10 deletions re-frame/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ that martian can bring:
```clj
(require '[martian.re-frame :as martian])
(require '[re-frame.core :as re-frame])
(require '[cljs.core.async :refer [<!]])
(require-macros '[cljs.core.async.macros :refer [go]])

(def interceptors [re-frame/trim-v])

Expand All @@ -27,14 +29,13 @@ that martian can bring:
(fn [db [response-or-error operation-id params]]
(update db :errors conj [operation-id response-or-error])))

(martian/init "http://pedestal-api.herokuapp.com/swagger.json")

(re-frame/dispatch [::martian/request ;; event for performing an http request
:create-pet ;; the route name to call
{:name "Doggy McDogFace" ;; data to send to the endpoint
:type "Dog"
:age 3}
::create-pet-success ;; event to dispatch on success
::http-failure ;; event to dispatch on failure
])
(go (<! (martian/init "http://pedestal-api.herokuapp.com/swagger.json"))
(re-frame/dispatch [::martian/request ;; event for performing an http request
:create-pet ;; the route name to call
{:name "Doggy McDogFace" ;; data to send to the endpoint
:type "Dog"
:age 3}
[::create-pet-success] ;; event to dispatch on success
[::http-failure] ;; event to dispatch on failure
]))
```
4 changes: 2 additions & 2 deletions re-frame/src/martian/re_frame.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,13 @@
(re-frame/reg-event-db
::on-complete
(fn [db [_ req]]
(update-in db [::martian :pending] disj req)))
(update-in db [::martian :pending] (fnil disj #{}) req)))

(defn- do-request [{:keys [db]} [_ operation-id params on-success on-failure]]
(let [request-key [operation-id params on-success on-failure]]
(if (contains? (get-in db [::martian :pending]) request-key)
{:db db}
{:db (update-in db [::martian :pending] conj request-key)
{:db (update-in db [::martian :pending] (fnil conj #{}) request-key)
::request [(instance db) operation-id params on-success on-failure]})))

;; deprecated, use ::request instead
Expand Down

0 comments on commit a3695b8

Please sign in to comment.