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)
|
(js/console.log :logging args)
|
||||||
(apply f 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
|
(defn transduce-cursor
|
||||||
"Allows to transduce over all values in a cursor.
|
"Allows to transduce over all values in a cursor.
|
||||||
|
|
||||||
|
|
@ -148,18 +156,14 @@
|
||||||
xform (xform rf)]
|
xform (xform rf)]
|
||||||
(js/Promise.
|
(js/Promise.
|
||||||
(fn [resolve _]
|
(fn [resolve _]
|
||||||
(.addEventListener cursor-req "success"
|
(iterate-cursor (fn [cursor]
|
||||||
(fn [ev]
|
(if cursor
|
||||||
(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))]
|
(let [step (xform @result (.-value cursor))]
|
||||||
(if (reduced? step)
|
(if (reduced? step)
|
||||||
(resolve @step)
|
(resolve @step)
|
||||||
(do
|
(vreset! result step)))
|
||||||
(vreset! result step)
|
(resolve @result)))
|
||||||
(.continue cursor))))
|
cursor-req))))))
|
||||||
(resolve @result)))))))))
|
|
||||||
|
|
||||||
(defn first-result
|
(defn first-result
|
||||||
"Given a cursor, will return a promise that resolves to the 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