This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2016-01-13
Channels
- # admin-announcements (6)
- # beginners (51)
- # boot (164)
- # braid-chat (49)
- # cider (10)
- # clara (17)
- # cljs-dev (13)
- # cljsjs (51)
- # cljsrn (10)
- # clojars (42)
- # clojure (195)
- # clojure-bangladesh (102)
- # clojure-berlin (8)
- # clojure-canada (1)
- # clojure-chicago (19)
- # clojure-colombia (4)
- # clojure-denmark (6)
- # clojure-russia (15)
- # clojure-ukraine (7)
- # clojurescript (257)
- # code-reviews (10)
- # community-development (292)
- # core-async (13)
- # datomic (26)
- # dirac (4)
- # dunaj (5)
- # dysphemism (5)
- # events (21)
- # funcool (15)
- # hoplon (115)
- # instaparse (31)
- # ldnclj (15)
- # mori-fork (43)
- # mount (5)
- # off-topic (18)
- # om (195)
- # onyx (13)
- # proton (9)
- # re-frame (11)
- # reagent (44)
- # slack-help (14)
- # slackpocalypse (1)
- # spacemacs (10)
- # yada (23)
I have a schema like this:
(def schema {:greeting s/Str
:data [{:title s/Str
:images [{:url s/Str}]
:latitude s/Num
:longitude s/Num}]
:loading? s/Bool
:last-lat s/Num
:last-long s/Num})
Now I want to tell it that a empty version of :data
is ok too. Right now it throws invalid when I try to validate it(s/maybe [{:title s/Str
:images [{:url s/Str}]
:latitude s/Num
:longitude s/Num}])
That is weird because the docs of that func say "A value that must either be nil or satisfy schema"
hey people, anyone got a schema
for reagent component?
what dyu mean @hugobessaa ? i have tonnes of components with schema for their inputs, but there's nothing special about those schema relating to reagent
Yeah, reagent components are just functions, so you can just use the usual schema function validation stuff for it.
maybe hugo means a schema that is hiccup-shaped? so it could validate
[:div]
[:div "hi"]
[:div {:style {:width "10px"} "hi"]
[:div [:div "hi"]]
[:div>span "hi"]
etc
I did:
(s/defschema ComponentForm1
[(s/one (s/conditional keyword? s/Keyword
:else js/Function) "comp")
(s/maybe (s/conditional keyword? s/Keyword
string? s/Str
vector? (s/pred vector?)
map? (s/pred map?)
:else js/Function))])
;; TODO: validate if function uses schema Component
;; (s/defschema ComponentForm2
;; js/Function)
;; TODO: validate if object is indeed a ReactElement
;; (s/defschema ComponentForm3
;; js/Object)
(s/defschema Component
(s/conditional vector? ComponentForm1
:else js/Function))
Don't know how to correctly implement ComponentForm2 nor ComponentForm3
This might help you - https://github.com/Day8/re-frame/wiki/Creating%20Reagent%20Components
But why not just:
(schema/defn some-component [prop :- PropSchema other-prop :- OtherPropSchema]
...)
?I want to
(schema.core/defn some-component :- Component [prop :-PropSchema] ,,,)
And sometimes
(schema.core/defn container :- Component [child :- Component])
@jaen thanks, I will take a look at =>
Form1 is of type props -> hiccup-vector
, form2 is of type initial-props -> props -> hiccup-vector
(a function returning a Form1 that is), Form3 is of type initial-props -> react-component
, where hiccup-vector
is possibly nested vectors that start with a symbol or any of those forms.
If you get it working then do share, I'll be interested to know how it ended up looking.
I'll improve my first solution as soon as I need form2 and form3
probably later today or tomorrow
I'll post here any improvements
I now need something for the output of reagent.core/reaction
. Any ideas?
:- reagent.ratom/Reaction
works just fine
how are you testing reagent components?
this looks like a start
but I'm interested into examples of specter being used to test hiccup syntax
@hugobessaa: I test reagent components like this: https://github.com/reagent-project/reagent-cookbook/tree/master/recipes/test-example-with-ReactTestUtils
@gadfly361: thanks!
this one includes rendering the component to the DOM. I'm suspecting I will have to do that anyway…
Yeah, i think a lot of the time you can get away without it, but it's really nice to have it in the toolbelt IMO (especially bc it runs super fast)
@gadfly361: after some fiddling, I'm convinced this approach is better. Checking hiccup isn't as nice. Would need some tooling I don't have time to write now. Thanks for the link again.