Skip to content

Instantly share code, notes, and snippets.

@ckirkendall
Last active August 29, 2015 14:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ckirkendall/9a3ebe92bd9d4c279241 to your computer and use it in GitHub Desktop.
Save ckirkendall/9a3ebe92bd9d4c279241 to your computer and use it in GitHub Desktop.
Supporting transformations in cursors
(def app-state (atom {:options [{:id "1" :name "test1" :creative_type_id "2"}
{:id "2" :name "test2" :creative_type_id "1"}
{:id "3" :name "test3" :creative_type_id "1"}
{:id "4" :name "test4" :creative_type_id "2"}]
:creatives [{:id "1" :name "my creative" :type_id "1"}]}}))
(let [ref (q
(select
;;construct builds a proxy cursor
(construct {:value (?- ['op :id])
:description (?- ['op :name])})
(from
(join [:options] 'op)
(join [:creatives] 'c (on (eq (?- ['c :type_id])
(?- ['op :creative_type_id]))))))
(om/root-cursor app-cursor)]
(om/transact! ref [0 :description] "test-updated")])
;;below is the state of app after the trasact is applied
#_{:options [{:id "1" :name "test1" :creative_type_id "2"}
{:id "2" :name "test-updated" :creative_type_id "1"}
{:id "3" :name "test3" :creative_type_id "1"}
{:id "4" :name "test4" :creative_type_id "2"}]
:creatives [{:id "1" :name "my creative" :type_id "1"}]}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment