Fork me on GitHub
#fulcro
<
2018-10-26
>
tony.kay00:10:29

Pushed 0.0.8 of Incubator to clojars with some improvements on pmutate!. Makes sure mutation refresh declarations are honored, and adds a mutation response during the loading phase to a declared target. Might not work with advanced targeting, though…

tony.kay00:10:17

Fulcro 2.6.10 on Clojars. Some bug fixes around unhappy paths of networking. This also adds network activity support in app state, and as an app-accessible thing. The app state allows you to see mutation and load activity, and a new defer functions allows you to schedule a callback for the next time the network is idle. The last one is part of the server-render namespace, and is meant for doing server-side rendering using a headless client and loopback rendering with node. Contributed by @claudiu

tony.kay00:10:42

Updated developers guide to cover that

pserrano02:10:45

I'm having a bad time trying to apply CSS to any component within fulcro I've already tried all exemples of fulcro's guide. Colocated CSS, injected CSS, CSS Localized DOM. It just doesn't apply .

(defsc Component [this props comp {:keys [a]}]
  {:css [[:.a {:color :red}]]}
  (dom/div {:className a} "Hi!"))
Should be enought to render a nice, red Hi!, shouldn't it?

wilkerlucio03:10:37

@patrickcms hello, had you injected the css in the page?

pserrano14:10:03

@wilkerlucio Hello! Yes, I tried doing it with injection, but since I'm not sure about how to do this, I can't tell if my exemple would work. Do you have an exemple of a simple component with injected css?

tony.kay14:10:04

use a style-element or upsert-css

pserrano14:10:12

Hello @tony.kay ! I did read the guide, but I still don't understand how to do it. If you have an simple-exemple-component, it will help me a lot!

tony.kay14:10:54

what about the “Show/Hide” source on the live demo in the book can I expand on? It is all right there

tony.kay14:10:24

If you’re using the new stuff: (cssi/style-element {:component Component}), which can be done inside of the component, or at the root…if you use the new stuff, you can just use Root, assuming things are composed with queries

claudiu14:10:22

Hi, case anyone is interested I made a small example app with fulcro+shadow-cljs that has nodejs SSR (including network data fetch) https://github.com/claudiu-apetrei/fulcro-nodejs-ssr-example

👍 8
pvillegas1214:10:34

Are there functions to convert a form’s data diff into a datomic datom? Specially handling the nested forms case (I can handle that myself, just wondering if it exists somewhere)

tony.kay15:10:00

nope…the form diff is meant to be an easy-to-use thing for any db…I have not written general utils from there for any specific db

👍 4
magra15:10:57

Hi, I am trying to use the bootstrap3/Dropdown component. The component I want to have the Dropdown on is not Root but inside nested routers as per the examples in the Routing Examples. If I have some static Dropdown in initial-state of the Page as in the Dev Guide examples it works. But the Options on my dropdown are not static and not part of the Query (from the Serve). I populate them using fulcro.ui.bootstrap3/dropdown. I can not figure out, how to get this into app-state so it normalizes correctly. Where would be an idiomatic place to calculate/trigger merge/transact into app-state? As a follow up to the load or on the UI inside the nested Router? Which of the merge or transact functions would be idiomatic and where do I get the query to go with the merge?

pvillegas1215:10:06

@magra you can use a post-mutation after a load to populate the dropdown

magra15:10:45

@pvillegas12 which function would you use to normalize?

pvillegas1215:10:45

Normalization is achieved with idents on components

pvillegas1215:10:55

you can define a component that normalizes your dropdown options

magra15:10:20

would you use fulcro.client.mutations/merge! for that? How do I use the component in the post-mutation?

pvillegas1215:10:41

Use prim/merge-component within the post-mutation passing the component responsible for the normalization

pvillegas1215:10:11

you pass in the component as arguments to the post mutation with post-mutation-params

magra15:10:12

@pvillegas12 Thanks! I will keep trying in that direction!

👍 4
Pontus15:10:57

Hi, is there a way to get access to children in functional components like in js react? When using fulcro I've only managed to get children to work with defsc. What I'm looking for is to be able to do the equivalent of this javascript in cljs:

export default Button({ onClick, children }) {
  return (
    <button onClick={onClick}>children</button>
   );
}

and call it like this:
<Button onClick={onClick}>do something></Button> // do something passed as `children`.
Is that somehow possible when defining a function like (defn Button [props] (dom/button)) ?

pvillegas1216:10:58

yes @pontus.colliander

(defn button [onClick yield]
  (dom/button {:onClick onClick} yield))
(button on-click (dom/p "do something"))

Pontus16:10:20

I tried that but called the second argument "children" but then it didn't work. Thanks 🙂

magra16:10:31

@pvillegas12 Just to be sure: prim/merge-component or prim/merge-component!? Bang or no bang?

pvillegas1216:10:44

depends, if called within a mutation, without the !

pvillegas1216:10:01

(convention which holds in general)

magra16:10:48

So write a mutation which calls prim/merge-domponent! and feed that as a postmutation to load?

pvillegas1216:10:10

write a mutation which calls prim/merge-component within it as post-mutation to the load

magra16:10:33

Thanks!

👍 4
tony.kay18:10:43

is that not in the book?

Pontus19:10:00

Yeah, but was looking for a way to use children with (defn component [props]) syntax, not defsc. Got it working with the tip from pvillegas12

tony.kay18:10:29

And a note on conventions to all…early versions of Untangled (which preceeded Fulcro) were evolving the conventions. Some of us were rather new to Clojure. The “normal” convention of ! means side-effecting, and the lack of it loosely implies not…but that isn’t guaranteed. The * suffix is my convention for a “mutation helper”…that is: a function (fn [state-map …] state-map) that can be used to compose operations within a mutation.

tony.kay18:10:20

merge-component (without the !) should therefore have a * on it…but it was a very early one. We’re slowly trying to deprecate the old names and create versions that follow this convention.

tony.kay18:10:00

I feel the suffix is really helpful because there is a whole class of code you write in Fulcro in mutations, and those particular functions apply there, so having them show up in things like intellisense is nice.

tony.kay18:10:14

Fulcro Incubator 0.0.9 released. After yesterday’s discussion about flicker-free io progress (and Reacts new craziness to try to get it) I felt it might be a good time to create some helpers, docs, and demos to show how to do it in Fulcro…the new pmutate! and pre-existing load markers combine nicely to get a single unified thing, which is in this release.

tony.kay18:10:34

The result needs about 4 lines added to your component:

(defsc TodoItem [this {:keys [item/label item/done?]}]
  {:query              [:db/id :item/label :item/done?
                        ::pm/mutation-response]     ; THIS: make sure the mutation response is in props
   :ident              [:todo-item/by-id :db/id]
   :componentDidUpdate (fn [pp _] (ip/update-loading-visible! this pp)) ; THIS: does the timeout magic
   :initial-state      {:db/id :param/id :item/label :param/label :item/done? false}}
  ;; THESE TWO: pull the indicators (first one is "delayed", latter is "immeidate")
  (let [delayed?  (prim/get-state this :loading-visible?)
        disabled? (ip/busy? this)]
    (dom/li
      (dom/input {:type     "checkbox"
                  :disabled disabled?
                  :checked  done?
                  :onChange (fn [] (pm/pmutate! this `pretend-to-mark {:new-value (not done?)}))})
      (when delayed?
        (dom/span "..."))
      label)))

tony.kay18:10:22

flicker-free-ws…the card is a bit hard to resize…I should fix the starting size 😕

tony.kay18:10:41

it has two simulated remotes. Mutations go to the slow one, and loads you can choose

bananadance 4
magra21:10:31

Thanks! Once I get how to think about it prim/merge-component called from the post-mutation works like a charm.

tony.kay23:10:19

Pushed 0.0.10 of incubator to clojars with update-io-progress!, an improved function that works the same as above, but gives you separate indications for load vs mutation