(cursor-in ref path & {:as options})
Given atom with deep nested value and path inside it, creates an atom-like structure
that can be used separately from main atom, but will sync changes both ways:
(def db (atom { :users { "Ivan" { :age 30 }}}))
(def ivan (rum/cursor db [:users "Ivan"]))
\@ivan ;; => { :age 30 }
(swap! ivan update :age inc) ;; => { :age 31 }
\@db ;; => { :users { "Ivan" { :age 31 }}}
(swap! db update-in [:users "Ivan" :age] inc) ;; => { :users { "Ivan" { :age 32 }}}
\@ivan ;; => { :age 32 }
Returned value supports deref, swap!, reset!, watches and metadata.
The only supported option is `:meta`
Source
(defn cursor-in
"Given atom with deep nested value and path inside it, creates an atom-like structure
that can be used separately from main atom, but will sync changes both ways:
(def db (atom { :users { \"Ivan\" { :age 30 }}}))
(def ivan (rum/cursor db [:users \"Ivan\"]))
\\@ivan ;; => { :age 30 }
(swap! ivan update :age inc) ;; => { :age 31 }
\\@db ;; => { :users { \"Ivan\" { :age 31 }}}
(swap! db update-in [:users \"Ivan\" :age] inc) ;; => { :users { \"Ivan\" { :age 32 }}}
\\@ivan ;; => { :age 32 }
Returned value supports deref, swap!, reset!, watches and metadata.
The only supported option is `:meta`"
^rum.cursor.Cursor [ref path & { :as options }]
(if (instance? Cursor ref)
(cursor/Cursor. (.-ref ^Cursor ref) (into (.-path ^Cursor ref) path) (:meta options) (volatile! {}))
(cursor/Cursor. ref path (:meta options) (volatile! {}))))