Fork me on GitHub
#fulcro
<
2017-11-29
>
tony.kay02:11:11

Fulcro 1.2.2-SNAPSHOT on clojars. It has a much improved defsc that should work for 99% of your component defining needs! See the docstring on it…it’s long…here’s a sample:

(defsc Root [this {:keys [ui/react-key child] computed children]
  {:query [:ui/react-key {:child (om/get-query Child)}]
   :initial-state (fn [c params] {:child (fc/get-initial-state Child)})
   :css [[:.my-css {:color :red}]]}
  (dom/div #js {:key react-key} 
     (ui-child child)))
You can now mix and match lambdas and the original data-based values in the options. Say you want to use a theme from some global atoms, just use {:css (fn [this] [[:.my-class {:color @theme-color-1}]])}!

tony.kay02:11:42

short, concise, props/computed destructuring, If you use the data-template style, it even validates you’ve not got a type:

(defsc Root [this {:keys [ui/react-key child] computed children]
  {:query [:ui/react-key {:chil (om/get-query Child)}]}
  (dom/div #js {:key react-key} 
     (ui-child child)))
Will warn you that you’ve destructured :child but you joined :chil

tony.kay02:11:03

If you use the lambda forms, I cannot interpret your code, since it is arbitrary, so you lose the error-checking.

tony.kay02:11:06

NOTE: for those newbies lurking…the CSS requires you actually add the fulcro-css dependency 🙂

tony.kay02:11:48

FULCRO 2.0 RC1 Nearly complete Any More Input??? The last task on my list is to finish renaming things. There have been some votes for various naming in this issue. I am leaning towards moving a few more things, if possible. The new primitives namespace (rename of next.cljc) doesn’t have to stick with that name. It was the best I came up with at the time. Please see issue https://github.com/fulcrologic/fulcro/issues/75 I plan on taking most of tomorrow off. Thursday I’ll do the renaming and clean-up, and some fancy git footwork. If that all goes well, I’ll cut RC1 sometime Thursday.

devo03:11:15

Is there a way to grab a vector of components used in a router? i.e. for getting the value of include-children for a Root component for fulcro-css. Example here https://gist.github.com/Devereux-Henley/5d179ac9fc8bfff4d5f7d424b18899be#file-root-cljc-L19

tony.kay04:11:17

There isn’t some global registry of components, no.

tony.kay04:11:53

If they were related via query, you could pull the query and scan it for things that have css

tony.kay04:11:06

The query is annotated with metadata of the components

tony.kay04:11:50

so you could technically find all of the components in the (static) query scan for metadata with :component in it, and pull things programattically that way. But, why not just include them into Root by hand?

tony.kay04:11:23

so, yeah, for a router, that would work

tony.kay04:11:55

you know Clojure well enough to know how to do that easily? @devo

tony.kay04:11:18

for just a router, I think this would work:

(->> (om/get-query RootRouer) vals (keep (comp :component meta)) vec)

tony.kay04:11:36

The values of the query are the things that you can route to (it is a union query)

devo04:11:45

Just didn't want to maintain the vector of components in both the router and the root component.

tony.kay04:11:02

yeah…but you might need to also filter by the ones that have css

tony.kay04:11:37

see the source code of fc/get-initial-state to see how to do that in a cljc-compatible way if you’re doing SSR

tony.kay04:11:50

basically the clj version has static methods in metadata, and the cljs side works with implements?

tony.kay04:11:46

This might get just the ones that have CSS

(->> (om/get-query RootRouer) vals (keep (comp :component meta))
      (filter #(implements? css/CSS %)) vec)

tony.kay04:11:08

I should probably add that to routing.cljc

tony.kay04:11:22

oh wait…can’t…hard dep on css.

devo05:11:36

Had to make a couple tweaks to the snippet to get it working, but seems good now.

devo05:11:43

(om/get-query RootRouter) was yielding [:id {:current-route {:index {...} :about {...}}], so vals was breaking.

wilkerlucio11:11:13

@tony.kay hey, about the new syntax, there is one thing that would be cool but might be a bit harder to implement is that, instead of: :initial-state (fn [this, params]), :initial-state (fn [params]), but then, pull the this from the defsc params declaration I think it's about getting the name for the this (first arg of defsc) and add that as the first param of any internal function would be kind like records makes sense?

mitchelkuijpers16:11:25

@wilkerlucio Is it already possible to use pathom with fulcro 2.0? Not sure if you have to do special stuff for that or if it will just work

wilkerlucio16:11:13

@mitchelkuijpers didn't checked yet, but I guess it should mostly work, the tx-listen might break because Fulcro 2.0 sends new types of events, but otherwise I guess it might work, please let me know if you try 🙂

mitchelkuijpers16:11:33

I will try it tomorrow, mostly for the server-part

mitchelkuijpers16:11:54

And I want to add placeholders to the client

mitchelkuijpers16:11:59

We will find out tommorow I guess ^^

tony.kay17:11:48

@devo….oh right…the union is a generated component one level down. The router has tracking props

tony.kay17:11:59

@wilkerlucio oh, I see…so treat this from the outer scope…the downside is the signatures then look odd. It is easy to do, I’m not sure I like it.

tony.kay17:11:22

because in defrecord methods you still have to say this

tony.kay17:11:14

what I like about it at the moment is that it is full consistent in the body. I you add extra protocols, those have to say this, and that would be a littler harder change (and you could argue even less desirable)

tony.kay17:11:31

(defsc Boo [this ...]
   {:query (fn [] ...)
    ...}
vs
(defsc Boo [this ...]
   {:query (fn [this] ...)
    ...})

tony.kay17:11:56

hm…now that I type it I might agree with you 😜

tony.kay17:11:16

yours looks more like a functions closing over things

tony.kay17:11:38

anyone else have an opinion? I’ll give it a few hours to percolate on the channel

currentoor17:11:07

@tony.kay I tend to agree with @wilkerlucio, this represents the same thing so why have it show up twice?

wilkerlucio19:11:18

@tony.kay another feature that came to my mind here, on regarding the the load

wilkerlucio19:11:43

the docs says that load ignores the :target when the query is for an ident

wilkerlucio19:11:13

one case that I often need is to load from an ident, and then I want that ident injected in some root key (usually something like :ui/root)

wilkerlucio19:11:01

because the root is clean, and my actual root has an ident, if the :target worked properly, we could load from the ident, and then create a reference to that ident somewhere on the app db root

tony.kay21:11:30

@wilkerlucio That’s another good observation, and esp now that target supports append/prepend/etc, it makes even more sense

tony.kay21:11:46

I’ll both changes to my TODO list