Fork me on GitHub
#fulcro
<
2017-09-30
>
wilkerlucio02:09:56

@tony.kay I'm trying out the defsc macro now, is there a way to use the params of initial-state there?

wilkerlucio02:09:39

humm, I noticed you validate the props vs query, can we disable the validation when there is no query? I'm having an UI component that I only need the CSS part, no query or ident

tony.kay02:09:21

So, defsc = “define stateful component”

tony.kay02:09:45

The point of the macro is to error check the combo of props + query + ident

tony.kay02:09:00

use defui for more simple needs

tony.kay02:09:21

the initial state params does look to be an oversight, though

tony.kay02:09:15

oh wait…:param/x

tony.kay02:09:11

See M05 of the devguide

wilkerlucio02:09:45

but I would actually just want to use the params attribute as my params (pass though)

tony.kay02:09:54

Hm. Had not considered that necessary.

tony.kay02:09:11

you’re supposed to compose them like a tree, just like the queries

wilkerlucio02:09:00

yeah, it's just for flexibility, I like to enable the parent to set the params of children as it likes

wilkerlucio02:09:15

so I can do chances from a higher place

wilkerlucio02:09:42

doing the map seems kind of a filter, I prefer to let it flow

tony.kay02:09:43

so, are you using this for true initial state, or as general constructors?

tony.kay02:09:43

The main goal of defsc was to reduce accidental common errors: forgetting to destructure something from props, or forgetting to query for it…or not giving an ident.

wilkerlucio02:09:52

it's like this:

tony.kay02:09:31

Yeah, it’s just not meant to work that way. If you want to use defui you can use it that way, but defsc is trying to error check things

wilkerlucio03:09:12

gotcha, ok, but can we consider that other use case? I loved it to being a sugar to define layout components that only need CSS

wilkerlucio03:09:25

you think would be an issue to ignore validations in case there is no query?

tony.kay03:09:03

spell it out a bit more for me. You’re wanting a layout component that sits in the tree, provides CSS, but does not participate in the query. Why don’t you just go around it with the initial state, like you do with the query?

tony.kay03:09:20

no query, no state, no initial state

wilkerlucio03:09:00

because I like to use css classes with it, and have those namespaced

tony.kay03:09:23

I’m not able to understand why you need initial state for that…

wilkerlucio03:09:38

no initial state here, hehe, I'm talking for a different one 🙂

wilkerlucio03:09:42

this is the case:

wilkerlucio03:09:43

(fulcro/defsc Box
  [_ {:keys [title]} _ children]
  {:css [[:.container box-container]
         [:.header box-head-title]
         [:.hr box-hr]]}
  (let [css (css/get-classnames Box)]
    (apply dom/div #js {:className (:container css)}
      (if title (dom/div #js {:className (:header css)} title))
      (if title (dom/hr #js {:className (:hr css)}))
      children)))

tony.kay03:09:02

ok, so what’s the problem…I don’t remember the boundaries of the macro to be honest

wilkerlucio03:09:25

the problem is that it's trying to validate the title prop, trying to match with the query

wilkerlucio03:09:32

and raising an exception, because it's not there

wilkerlucio03:09:56

then comes my question: can we ignore the prop validation when there is no query?

tony.kay03:09:25

probably. again, it then makes it a misnomer, since it was really meant for building error-checked stateful components

tony.kay03:09:29

not just saving typing

tony.kay03:09:51

I’d rather add a defc that does not accept a query

wilkerlucio03:09:59

humm, ok, maybe I'm looking it wrong, I was thinking it as a sugar for common cases, but maybe this is not one of those

tony.kay03:09:32

no, I was getting tired of forgetting of querying for something that I destructured, or making a typo, etc. Happens all the time with defui

tony.kay03:09:07

defsc is about making it possible to destructure and error check the props against query + props destructure + initial state

wilkerlucio03:09:12

cool, in one of my components I used it, quite cool, the others I can just still doing the old fashion

tony.kay03:09:52

yep…that’s it’s job. You are destructuring title, but you didn’t query for it. Non-queried things should come through computed in a stateful component

tony.kay03:09:37

so, technically you wrote something that had an error (for a stateful component)

tony.kay03:09:59

again, fine exploring a sugar macro defc that drops query and computed

tony.kay03:09:10

but disallows query and initial state

wilkerlucio03:09:09

why not having one that deals with all, just being smart about it?

tony.kay03:09:44

because swiss army knives like that are unstable. We already have defui which is completely general

wilkerlucio03:09:55

yeah, makes sense

tony.kay03:09:10

and the syntax of defui is good for the general use case, I think

wilkerlucio03:09:25

yeah, I have some snippets that make using it pretty fast and ease

tony.kay03:09:32

but for the very common case of a stateful component, defsc helps ease errors because it eliminates duplication and error checks the common problems

tony.kay03:09:52

I don’t love that it creates two ways of doing things. I would love a single thing that just works…but in my judgement defui is the better general-purpose syntax. It looks like defrecord et al.

tony.kay03:09:39

one (I think you did in fact) could argue that creating defsc is not the best of ideas in a library because it is special purpose sugar

tony.kay03:09:23

but in practice, I think it brings a benefit that outweighs the feature creep feel of it

tony.kay03:09:56

as soon as we start making it “morph” how it works based on what is supplied, it loses a lot of that value and I no longer want it in the lib 😜

tony.kay03:09:34

Ideally, we’d write a defui parser that would error-check the way defsc does. But that is a hard problem. Some people don’t destructure props, they just access them, often through an intermediate binding. Etc.

tony.kay04:09:07

I’m releasing beta11 now. I plan on checking for issues over the weekend, and cutting 1.0.0 officially on Monday

nha22:09:20

just noticed css-merge has been removed in https://github.com/fulcrologic/fulcro-css/commit/f99228ba88d7bdb4bae7089d7977a32fa369c5a5 what is the thinking behind that?

nha22:09:15

And what is the preferred way of composing css now?