-
-
Save ckirkendall/9a3ebe92bd9d4c279241 to your computer and use it in GitHub Desktop.
Supporting transformations in cursors
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(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