Fork me on GitHub
#malli
<
2020-11-26
>
Hankstenberg11:11:26

The more I look at it the more I want to use malli schemas as a single source of truth for everything. Are there any resources about generating ui models from malli schemas? I think the idea to integrate it with Domino was floating around once, but the current version doesn't mention malli. How else could it be done? My go-to framework for UI stuff is usually re-frame. Malli could be integrated so that re-frame's db is generated from it. And to validate state changes, of course. It could also be bound to visual representations of actual components I guess. Would be grateful for any reference to existing work in this area.

rutledgepaulv14:11:34

I have played with this a bit. I eventually came to a realization that I should first transform malli into an intermediate representation prior to generating the UI state because there are additional things you'll want to know about each node, like whether the field is "dirty" and has been "visited", etc. So in other words.. first I would go through the work of figuring out a sensible IR and generating forms from that, and then work backwards and generate that initial IR from malli.

👍 3
rutledgepaulv14:11:13

That said, my initial attempt of using malli directly (and still struggling with how to do the reagent cursors) is here: https://rutledgepaulv.github.io/ui-kit/#!/ui_kit.forms https://github.com/RutledgePaulV/ui-kit/blob/master/src/cljs/ui_kit/visitors.cljs

👍 3
ikitommi18:11:19

Have seen multiple prototypes. Did also a demo into on of our projects. There is malli.util/subschemas helper which takes a Schema and returns an ordered list of all the schema paths and Schemas in those, handling also collection schemas. One place to start. Also, one can post-walk the Schemas and wrap all schmas into something that can be used to strore the form state (dirty, pristine, etc). hope this helps.

👍 3
Hankstenberg06:11:51

Thanks a lot for the input! I'm still trying to wrap my head around everything. I think Datascript (re-posh)+datasync are the right tools to connect front-end state and back-end state, I think I will try to find a way to make this stack (malli-)schema-driven.

ikitommi18:11:19

Have seen multiple prototypes. Did also a demo into on of our projects. There is malli.util/subschemas helper which takes a Schema and returns an ordered list of all the schema paths and Schemas in those, handling also collection schemas. One place to start. Also, one can post-walk the Schemas and wrap all schmas into something that can be used to strore the form state (dirty, pristine, etc). hope this helps.

👍 3
rutledgepaulv19:11:45

Wonder if there's an opportunity to improve error messages here:

rutledgepaulv19:11:51

(def stream
  (logs client
        {:operation "readCoreV1NamespacedPodLog"}
        {}))
Execution error (ExceptionInfo) at kube-api.utils/validation-error (utils.clj:87).
Invalid request.
{:path-params ["missing required key"]}

(def stream
  (logs client
        {:operation "readCoreV1NamespacedPodLog"}
        {:path-params {}}))
Execution error (ExceptionInfo) at kube-api.utils/validation-error (utils.clj:87).
Invalid request.
{:path-params
 {:name ["missing required key"], :namespace ["missing required key"]}}

rutledgepaulv19:11:36

if there's a missing key, insert the key with an empty value and run validation on that empty value too so you can report not only the missing collection but also what needs to be in the collection?

rutledgepaulv19:11:52

probably breaks down in some edge cases.. thinking

ikitommi19:11:23

you could run default-value-transformer to add empty maps first.

👍 3
ikitommi19:11:28

(m/decode
  [:map
   [:path-params [:map
                  [:name :string]
                  [:description :string]]]]
  nil
  (mt/default-value-transformer
    {:defaults {:map (constantly {})
                :string (constantly "")}}))
; => {:path-params {:name "", :description ""}}

rutledgepaulv19:11:38

thanks! yes, that's working for me