Skip to content

Commit

Permalink
tweak request util
Browse files Browse the repository at this point in the history
  • Loading branch information
andrew committed Jun 2, 2016
1 parent 9ca5716 commit ae23feb
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 8 deletions.
1 change: 1 addition & 0 deletions src/cljs/ulysses/pages/builder.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,7 @@
[:div.builder-header
[:h3.text-xs-center.mb-15 (:title op)]])


;; ----------------------------------------------------------------------------
;; main
;; ----------------------------------------------------------------------------
Expand Down
23 changes: 15 additions & 8 deletions src/cljs/ulysses/utils.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,11 @@
;; general
;; ----------------------------------------------------------------------------

(defn noop
"do nothing; return nil"
[& args]
nil)

(defn ptr
"print x, then return it. useful for
debugging inside threading macros or map"
Expand Down Expand Up @@ -315,12 +320,12 @@

(defn request
"make an api request, with progress tracking"
[db endpoint & {:keys [verb params handler error-handler finally]
[db endpoint & {:keys [verb params handler error-handler finish]
:or {verb :get
params nil
handler #()
error-handler #()
finally #()}}]
handler noop
error-handler noop
finish noop}}]
(let [progress-id (:next-progress-id db)
method (case verb :get ajax.core/GET
:post ajax.core/POST
Expand All @@ -334,7 +339,11 @@
(map
#(if (keyword? %) (name %) %)
endpoint)))
{:params (remap url-encode-component params)
{:params
(when params
(remap url-encode-component params))
:response-format :json
:keywords? true
:handler handler
:error-handler
(fn [e]
Expand All @@ -343,9 +352,7 @@
:finally
(fn [e]
(dispatch [:progress progress-id 100]) ; complete progress
(finally e)) ; user
:response-format :json
:keywords? true}))
(finish e))})) ; user
db) ; (no direct db change)

(def request-grant-ops-channel
Expand Down

0 comments on commit ae23feb

Please sign in to comment.