Skip to content

Instantly share code, notes, and snippets.

@ninjudd
Forked from amalloy/gist:1299853
Created October 19, 2011 22:33
Show Gist options
  • Save ninjudd/1299885 to your computer and use it in GitHub Desktop.
Save ninjudd/1299885 to your computer and use it in GitHub Desktop.
(is (= (assoc node2 :id "1")
(-> layer-name
(write-txn (assoc-node "1" node2)
(update-node "1" assoc :baz [1 2 3])
(update-node "1" dissoc :baz))
(get-node "1"))))
;; the above is sugar for the below. seem useful?
(let [layer (layer layer-name)]
(dotxn layer
(-> layer
(assoc-node "1" node2)
(update-node "1" assoc :baz [1 2 3])
(update-node "1" dissoc :baz))))
(is (= (assoc node2 :id "1") (get-node layer-name "1")))
;; implementation:
(defmacro write-txn [layer-name & actions]
`(let [layer-name# ~layer-name
layer# (layer layer-name#)]
(retro/dotxn layer#
(-> layer#
~@actions))
layer-name#))
(with-txn :foo
(assoc-node "1" node2)
(update-node "1" assoc :baz [1 2 3])
(update-node "1" dissoc :baz))
(txn-> :foo
(assoc-node "1" node2)
(update-node "1" assoc :baz [1 2 3])
(update-node "1" dissoc :baz))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment