This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2021-03-21
Channels
- # announcements (2)
- # asami (8)
- # aws (4)
- # beginners (32)
- # calva (12)
- # cider (72)
- # clj-kondo (16)
- # clojure (11)
- # clojure-germany (2)
- # clojure-italy (4)
- # clojure-serbia (2)
- # clojurescript (26)
- # data-oriented-programming (8)
- # datomic (9)
- # deps-new (17)
- # eastwood (4)
- # emacs (20)
- # fulcro (18)
- # funcool (1)
- # graalvm (8)
- # leiningen (12)
- # lsp (34)
- # malli (25)
- # meander (4)
- # membrane (4)
- # off-topic (153)
- # practicalli (1)
- # releases (2)
- # remote-jobs (3)
- # rewrite-clj (77)
- # ring (5)
- # shadow-cljs (108)
- # spacemacs (12)
- # tools-deps (9)
- # vscode (11)
- # xtdb (4)
This is something I'm currently working on providing better support for. I'll try to write a more detailed explanation soon. If you look at a reference, they look something like:
[(keypath :todos)
(nth 0)
(keypath :complete?)]
which the equivalent query for a nested data structure would be something like:
(get-in state [:todos 0 :complete?])
If you wanted wanted to set the value at that reference, it's not too complicated to write a function that could accept the reference and set the value in a nested data structure:
(def $ref [(keypath :todos) (nth 0) (keypath :complete?)])
(set-nested state $ref true)
Similarly, if there is a schema, it's possible to take the same reference and provide versions of read, update, delete, and set for databases.
(get-ref db $ref)
(update-ref db $ref f & args)
(delete-ref db $ref)
(set-ref db $ref v)
To make this work for a datomic-like database, you really only need to know if attributes are :db.cardinality/many
and/or :db.type/ref
so you could expand
(def $ref [(keypath :todos) (nth 0) (keypath :complete?)])
(set-ref db $ref true)
into:
(d/transact! conn
[[:db/add 11 :complete? true]])
I've been hesitant to document the data format used for references since it's currently an implementation detail. The reference format was initially modeled after https://github.com/redplanetlabs/specter navigator paths since that the library I use for updating nested data structures, but it's possible that basing references on something like https://pathom3.wsscode.com/docs/ might be a better fit.