This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2017-12-04
Channels
- # adventofcode (171)
- # beginners (160)
- # boot (13)
- # chestnut (2)
- # cider (6)
- # cljs-dev (15)
- # cljsjs (35)
- # cljsrn (1)
- # clojure (139)
- # clojure-argentina (3)
- # clojure-brasil (1)
- # clojure-greece (31)
- # clojure-italy (5)
- # clojure-russia (5)
- # clojure-spec (18)
- # clojure-uk (11)
- # clojurescript (42)
- # clojurex (6)
- # core-async (12)
- # cursive (14)
- # dirac (13)
- # emacs (13)
- # events (1)
- # fulcro (46)
- # graphql (7)
- # leiningen (10)
- # lumo (3)
- # mount (31)
- # off-topic (20)
- # onyx (30)
- # perun (4)
- # planck (47)
- # re-frame (28)
- # reagent (14)
- # ring (5)
- # shadow-cljs (3)
- # spacemacs (7)
- # specter (13)
- # timbre (3)
- # unrepl (65)
- # yada (8)
@eoliphant a few things
you're misunderstanding cond-path
and keypath
a condition is true if it selects anything
keypath
always selects something, so it's pointless to be a condition on its own
you're also trying to navigate the maps and find the field in the submap at the same time, which isn't the right approach
instead do something like: (def NODES (recursive-path [] p (continue-then-stay :subgroups ALL)))
then from there you can do (transform [NODES :fields ...
hmm ok, will give that a shot, yeah i’d just tossed in keypath in trying to figure out why it wasn’t working. originally it was just
(sp/cond-path
:group/subgroups [ALL p]
but ok i think I see understand it a little better will break it outok. so after banging my head for a bit because i’d mistyped the key in NODES function lol, I’ve got everything working, needs some cleanup, but basically this:
(sp/setval [:designer/cur-form-def
:form/groups
sp/ALL
NODES
:group/fields
#(some? %)
(before-index-dynamic #(= (:field/id %) #uuid "b9a2c9ea-2647-48d3-ab26-4c2a115d7b6f"))
]
[{:new :field}]
appdb)
Will add {:new field}
before the field with the matching id. so good there. However, had to do a bit of hacking because not all :group/*
maps have group/fields
, This was initially blowing up the before-index..
function as specter would dutifully provide a nil. So I added the some?
check. That works, in terms of the field getting inserted, though I’m sure it’s not the best way, but the other thing is that the newly returned data structure adds a {:group/fields nil}
to groups that didn’t have one, which surprised me as I thought the some? check would prevent that. So I’m thinking the recursive path function should weed out groups that don’t have :group/fields?@eoliphant ah you just need before-index-dynamic
to navigate nowhere if there's no match
this does the trick:
(defn ^:direct-nav before-index-dynamic [p]
(path
(srange-dynamic
(fn [aseq]
(if-let [i (first (keep-indexed (fn [i e] (if (p e) i)) aseq))]
i
(count aseq)
))
(end-fn [aseq s]
(if (= s (count aseq)) s (inc s))))
(complement empty?)
BEFORE-ELEM
))
if you only want to navigate to a value in a map if the key exists, then do (must :somekey)