Fork me on GitHub
#fulcro
<
2018-03-05
>
myguidingstar02:03:16

@wilkerlucio placeholder plugin is a read wrapper whose position in the plugin chain is after walkable, so I guess I should just assoc ::p/placeholder-prefixes or something to env from the beginning. Otherwise we need two parts of such placeholder plugins, one for read, the other for manipulating the env

myguidingstar02:03:32

I guess we should update placeholder plugin to something like this:

myguidingstar02:03:44

(defn placeholder-reader
  "Produces a reader that will respond to any keyword whose namespace
  is in the set `(::placeholder-prefixes env)`. The join node logical
  level stays the same as the parent where the placeholder node is
  requested."
  (fn [{::keys [placeholder-prefixes] :as env}]
    (if (contains? placeholder-prefixes (namespace (:dispatch-key ast)))
      (join env)
      ::continue)))

wilkerlucio14:03:01

I agree this implementation is better, but this would be a breaking change, and breaking changes are not good... so my suggestion is to deprecate the current placeholder-reader but keep it as is, and I can add a new env-placeholder-reader (name subject to change, suggestions are welcome), then you can suggest your users to use the new one, and we don't break the current usages

myguidingstar15:03:26

I agree. I'll make a PR later today

tony.kay19:03:38

@jzhu5121 That is true, you will see that warning because in that video we have yet to add queries. As a result transactions result in a root level refresh, which is less efficient that a localized UI refresh…but a localized refresh cannot happen unless there are queries and idents on the component. In the video series I’m trying to build things up one at a time 🙂

tony.kay19:03:12

So, no point in mentioning the missing queries and idents yet, since you don’t even know what they are at that early stage 😉

piotrek21:03:47

Hello, a quick question - I tried to search through the docstrings and in the book but can’t find it: does defcard-fulcro run normalization of the supplied initial state map? I guess it’s not - if that’s the case how can I get the normalization applied to my initial state map?

(defcard-fulcro ContactList
  ContactList
  (prim/get-initial-state
    ContactList
    {:id 1000
     :contacts [{:id 1 :name "Bob" :email ""}
                {:id 2 :name "Alice" :email "alice@examplecom"}]})
  {:inspect-data true})

piotrek21:03:53

And question 2: I have the following example component:

(defsc ContactForm [this {:keys [:db/id :contact/name :contact/email]}]
  {:ident [:db/id :db/id]
   :query [:db/id :contact/name :contact/email]
   :initial-state {:db/id :param/id
                   :contact/name :param/name
                   :contact/email :param/email}}
  (dom/div nil
    (dom/input #js {:value name :onChange (partial m/set-string! this :contact/name :event)})))
and I play with it in the following devcard:
(defcard-fulcro ContactForm
  ContactForm
  (prim/get-initial-state
    ContactForm
    {:id 1
     :name "Alice"
     :email ""})
  {:inspect-data true})
but the mutation fails with: > Mutation fulcro.client.mutations/set-props failed with exception Error: No protocol method IAssociative.-assoc defined for type number: 1 I guess it is caused by lack of the normalization applied to my card initial state map but I would like to confirm that’s the case

tony.kay21:03:24

So, if you put initial state on the component, then it will find them and normalize it. If you supply the initial state through the card, then it has to be a pre-normalized database

tony.kay21:03:48

You can, however, use tree->db to normalize it yourself if you like

tony.kay21:03:09

in other words : Leave that map empty

tony.kay21:03:16

you’re doing work you don’t have to 🙂

piotrek21:03:24

The issue is that my initial state is parametrised and I am not sure it’s possible to pass params that should be used by the fulcro card to call get-initial-state on the root compoennt

tony.kay21:03:40

Just create a mock root for the card

piotrek21:03:56

I just wanted to avoid that 🙂

tony.kay21:03:01

or use tree->db

piotrek21:03:03

I will try tree->db

tony.kay21:03:08

but also realize that a component with an ident isn’t quite right for a root, either

tony.kay21:03:23

root is root…an ident indicates it should go in a table

piotrek21:03:07

I guess I will just have to use root

tony.kay21:03:17

Wilker points out a utility he uses to generate roots

tony.kay21:03:45

it’s a function you can pass your component to, and it’ll wrap it in a boilerplate root

tony.kay21:03:44

You have to use the prim/ui tool instead of defsc/defui…and you no longer need react-key…but that would save you the typing

piotrek21:03:00

Thank you - I will try to come up with that utility using the latest api

tony.kay21:03:26

that is pretty much it, other than the alias the docs prefer now is prim

tony.kay21:03:38

and you may not be using co-located css

tony.kay21:03:28

I imagine you could close over params from outside of initial state and get what you’re looking for

piotrek21:03:20

And if I got with just defining the root manually instead of the util fn, should I got with defsc or defui?

tony.kay21:03:45

defui is legacy at this point

donmullen21:03:41

For an easy-server, is the :handler object stored in the system component the ring handler - or is it [:handler :middleware]? Planning to test deploying to aws elasticbeanstalk with lein-elastic-beanstalk - unless anyone has other suggestion (want to access datomic cloud).

tony.kay21:03:13

the latter. handler is the component that contains the middleware

piotrek21:03:03

Thanks @tony.kay, I think a small root with sample data is simpler:

(defsc ContactListRoot [this {:keys [:root/contact-list]}]
  {:query [{:root/contact-list (prim/get-query ContactList)}]
   :initial-state (fn [_params]
                    {:root/contact-list
                     (prim/get-initial-state
                       ContactList
                       {:id 1000
                        :contacts [{:id 1 :name "Bob" :email ""}
                                   {:id 2 :name "Alice" :email "alice@examplecom"}]})})}
  (ui-contact-list contact-list))

(defcard-fulcro ContactList
  ContactListRoot
  {}
  {:inspect-data true})

tony.kay21:03:40

I just have an IntelliJ live template that lets me tab to the significant bits.

piotrek22:03:25

Good idea - I use IntelliJ too

tony.kay22:03:37

@piotrek I added make-root to fulcro.client-cards and pushed it in 2.3.1-SNAPSHOT. I meets this need, and I’d be glad to expand it for other devcard convenience. It does come up a decent amount.

tony.kay23:03:44

Released 2.3.1. Contains a patch to DOM inputs so that :ref works with functions now. Also contains new i18n support in alpha (opt-in).