Fork me on GitHub
#fulcro
<
2018-02-05
>
tony.kay05:02:18

@pontus.colliander The built-in parser on the client is written to use db->tree for you.

tony.kay05:02:43

There is nothing manual about it. You can use initial state to build an initial co-located state tree (which is auto-normalized on startup), and the queries are processed by the internal parser for you. Loading is a separate mechanism. So basically you can plug in an alternate network component/layer if you want, but other than that there is not much to write to make things work.

roklenarcic16:02:39

Hm I am trying to write a spec with generator for fulcro id/tempid and I'm failing: (s/def :db/id (s/or :tempid (s/with-gen prim/tempid? (gen/fmap tempid/->TempId (gen/uuid))) :id (s/and integer? pos?)))

roklenarcic16:02:03

where s is spec.alpha, gen is spec.gen.alpha

roklenarcic16:02:48

After running (gen/sample (s/gen :db/id)) I get ClassCastException clojure.test.check.generators.Generator cannot be cast to clojure.lang.IFn clojure.spec.alpha/spec-impl/reify--1987 (alpha.clj:888) which is weird, as I cannot see how there is anything wrong.

wilkerlucio17:02:44

@roklenarcic the generator needs to be a function of zero arguments that returns the generator, looks like you are returning the generator directly

wilkerlucio17:02:24

this might work: (s/def :db/id (s/or :tempid (s/with-gen prim/tempid? #(gen/fmap tempid/->TempId (gen/uuid))) :id (s/and integer? pos?)))

wilkerlucio17:02:00

and extra tip: you can replace (s/and integer? pos?) with pos-int?

roklenarcic17:02:57

it can be a bit confusing

roklenarcic17:02:16

when the arg is a generator and when a generator constructing fn

wilkerlucio17:02:55

for spec, AFAIK it's always a constructing fn, directly generators are used on more inside levels (like when composing generators)

wilkerlucio17:02:40

but it's easy to mess up, and over time we tend to remember better when to use what 🙂