Fork me on GitHub
#malli
<
2020-10-12
>
Lucy Wang03:10:02

@love.lagerkvist I'm using re-frame.core/reg-global-interceptor to verify the app-db matches my schema in every change, and prints an console warning if it doesn't conform. But re-frame.app-db is just a normal map (live inside an reagent.atom), so it's nothing special when using it with malli IMO.

👍 3
ikitommi05:10:49

merged #277, non-breaking disabling & configuration of sci. Will make a 1.0.0 issue with suggestion to make swappable & explicit evaluator. Thanks @borkdude @steveb8n

borkdude07:10:12

@ikitommi note that termination safe does have impact on performance of realizing seqs (since it’s checked). I’m not sure if the issue about execution time is fundamentally solvable.

ikitommi08:10:29

It is one of the harder problems in comp.sci ;) With Malli & sci, I concider safety as more important. Following the issue & pr on sci-side, happy to incorporate anything that is found for this.

borkdude08:10:02

I think the fundamental solution would be to run the sci expression in a thread on the JVM and kill it if it takes too long or in a webworker in the browser and do the same.

borkdude08:10:20

Maybe I should drop the termination-safe option as well - not sure.

motform07:10:40

@wxitb2017 that sounds about right, I’ll do that. However, I was also thinking if it was possible to co-locate/generate/properly infer an inital app-db directly from malli. It would be really nice to have a single source of truth, kind of like a reitit router with views, coercion and controllers. (it’s probably super possible and I have to dig more into malli or a very bad idea)

ikitommi15:10:59

You could have a Malli schema defined for the app-db, with default and create the initial state from those, e.g.

(defn create [?schema]
  {:validator (m/validator ?schema)
   :explainer (m/explainer ?schema)
   :initial (m/decode ?schema nil (mt/default-value-transformer))})

(create [:map {:default {}}
         [:user [:map {:default {}}
                 [:first-name [:string {:min 1, :default ""}]]
                 [:last-name [:string {:min 1, :default ""}]]]]])
;{:validator #object[...],
; :explainer #object[...],
; :initial {:user {:first-name "", :last-name ""}}}
inferring is powerful, but not fully accurate, e.g. is something a vector of things of a tuple of always 2.

ikitommi15:10:27

(the mt/default-transformer could have an option to create empty maps by default…)