Fork me on GitHub
#fulcro
<
2022-04-17
>
rayat06:04:27

Hi, is the right place to ask a noob question about guardrails? I'm trying to use it for #helix react components (`defnc`). My specific question is how to use >defn for describing a function that takes a map, whose entries I'd like to spec inline. Ie: (defn component-name [{:keys some-key some-other-key] :as props] ( <function body...>)` , where props might accept {:some-key "some string" :some-other-key true} What would the gspec look like for this? Thanks, and lmk if this is better asked elsewhere

sheluchin10:04:53

To spec a map you would use s/keys. https://clojure.org/guides/spec#_entity_maps With Guardrails it'd be something like (>def ::x (s/keys :req [::some-key ::some-other-key])). The Spec component of this is probably better suited as a question in #beginners as it's not really Guardrails-specific.

rayat15:04:02

Yeah, fair enough. Is it possible to describe the above within the inline gspec syntax, ie within a >defn, perhaps via some destructuring? If not, and I can only refer to the s/def or >`def`'d symbols within the >`defn`, then yeah, I'll look into that approach. Thanks!

sheluchin16:04:00

I'm not sure what you mean, but you should try to use registered specs wherever you are composing specs. So spec out the map keys, compose them into a registered entity map, and then use that map's spec's key in the >defn argspec like (>defn [props] [:some-ns/map-key => any?] ...). https://clojure.org/guides/spec#_registry > You will see later that registered specs can (and should) be used anywhere we compose specs.

1
thanks3 1