Separate iterate-cursor and transduce-cursor
This commit is contained in:
parent
1573341c18
commit
97965ce8b0
1 changed files with 16 additions and 12 deletions
|
|
@ -131,6 +131,14 @@
|
|||
(js/console.log :logging args)
|
||||
(apply f args)))))
|
||||
|
||||
(defn iterate-cursor [f cursor-req]
|
||||
(.addEventListener cursor-req "success"
|
||||
(fn [ev]
|
||||
(if-let [cursor (-> ev .-target .-result)]
|
||||
(do (f cursor)
|
||||
(.continue cursor))
|
||||
(f)))))
|
||||
|
||||
(defn transduce-cursor
|
||||
"Allows to transduce over all values in a cursor.
|
||||
|
||||
|
|
@ -148,18 +156,14 @@
|
|||
xform (xform rf)]
|
||||
(js/Promise.
|
||||
(fn [resolve _]
|
||||
(.addEventListener cursor-req "success"
|
||||
(fn [ev]
|
||||
(if-let [cursor (-> ev .-target .-result)]
|
||||
; NOTE: each step will work with the raw js value
|
||||
; to avoid unnecessary conversion costs.
|
||||
(let [step (xform @result (.-value cursor))]
|
||||
(if (reduced? step)
|
||||
(resolve @step)
|
||||
(do
|
||||
(vreset! result step)
|
||||
(.continue cursor))))
|
||||
(resolve @result)))))))))
|
||||
(iterate-cursor (fn [cursor]
|
||||
(if cursor
|
||||
(let [step (xform @result (.-value cursor))]
|
||||
(if (reduced? step)
|
||||
(resolve @step)
|
||||
(vreset! result step)))
|
||||
(resolve @result)))
|
||||
cursor-req))))))
|
||||
|
||||
(defn first-result
|
||||
"Given a cursor, will return a promise that resolves to the first result.
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue