Expose a 'tempid' function on transaction results, because JS object lookup doesn't work for TempIds.

This commit is contained in:
Richard Newman 2016-10-07 16:07:41 -07:00
parent 7728648b39
commit 4f10100174

View file

@ -75,13 +75,20 @@
(try (try
(let [tx-data (js->tx-data tx-data)] (let [tx-data (js->tx-data tx-data)]
(go-promise clj->js (go-promise clj->js
(let [tx-result (<? (d/<transact! conn tx-data))] (let [tx-result (<? (d/<transact! conn tx-data))
(select-keys tx-result tempids (:tempids tx-result)
[:tempids to-return (select-keys tx-result
:added-idents [:tempids
:added-attributes :added-idents
:tx :added-attributes
:txInstant])))) :tx
:txInstant])
jsified (clj->js to-return)]
;; The tempids map isn't enough for a JS caller to look up one of
;; these objects, so we need a lookup function.
(aset jsified "tempid" (fn [t] (get tempids t)))
jsified)))
(catch js/Error e (catch js/Error e
(println "Error in transact:" e)))) (println "Error in transact:" e))))
@ -103,7 +110,11 @@
:q (fn [find opts] (q (d/db c) find opts)) :q (fn [find opts] (q (d/db c) find opts))
:close (fn [] (db/close-db db)) :close (fn [] (db/close-db db))
;; So you can generate keywords for binding in `:inputs`.
:keyword keyword
;; Some helpers for testing the bridge. ;; Some helpers for testing the bridge.
:println (fn [& xs] (apply println xs))
:equal = :equal =
:idx (fn [tempid] (:idx tempid)) :idx (fn [tempid] (:idx tempid))
:cljify cljify :cljify cljify