Fork me on GitHub
#fulcro
<
2019-03-29
>
souenzzo14:03:59

I need something like "on every state change, call my function". It can be "on every transaction, call my function" too

souenzzo14:03:29

I will use :reconciler-options {:tx-listen tx-listen}

adamfeldman14:03:30

Fulcro is at the top of Hacker News right now: https://news.ycombinator.com/item?id=19520272

💯 8
🎉 20
fulcro 24
currentoor16:03:20

Thanks for answering all those questions and providing resources in the comments!

👍 4
adamfeldman17:03:46

Thank you, I hope I was accurate!

currentoor22:03:00

I thought so simple_smile

🙂 4
exit218:03:11

Anyone have any ideas how to fix this? [fulcro.ui.form-state] FORM NOT NORMALIZED: [:update-booking :tab :booking]

tony.kay19:03:23

normalize your form config?

tony.kay19:03:50

it either means you didn’t add form config, or it is in app state nested as a map (instead of normalized to an ident)

tony.kay19:03:58

or you’re calling something incorrectly

exit219:03:59

(defsc BookingForm [this {:keys [_id rate] :as props}]
  {:query       [:_id
                 :rate
                 fs/form-config-join]
   :form-fields #{:rate}
   :ident       [:booking/by-id :_id]}
  (dom/div
   {:style {:padding         "35px 27px"
            :backgroundColor "#fff"
            :border          "1px solid #DBDBDB"}}
   (input-with-label this :rate "Rate")))

exit219:03:34

@tony.kay I’m going based off the form examples, all this appears correct - I must be missing something

tony.kay19:03:56

that’s all fine

tony.kay19:03:01

it’s your database state

tony.kay19:03:12

you have to add form config, and make sure it normalizes

exit219:03:47

ok, so to the query of the parent component thats passing booking down, I need to add fs/form-config-join?

mss19:03:04

wondering what the best way to accomplish the following would be: I have a component that needs to attach a non-react-supported event handler to an element. that event handler needs the component’s this to be in scope so I can call transact! and do something with the event data. right now I’m just using a ref callback on the element and set!ing the handler along with a ref on the component instance. I’m actually instantiating and cleaning up the event handler in my componentDidMount and componentWillUnmount. is there an easier way to add a method to an instance so it’s available with this in scope in my componentDidMount and componentWillUnmount calls?

mss19:03:08

@njj afaik fulcro.ui.form-state/form-config-join goes in the form’s query, and fulcro.ui.form-state/add-form-config goes in the parent’s initial state creation call like {:my-form-data (fulcro.ui.form-state/add-form-config MyForm (fulcro.client.primitives/get-initial-state MyForm {}))

👍 4
exit220:03:20

Is that the same as prim/get-initial-state?

mss20:03:27

yep same thing. sorry, pulled that from a form of mine and my naming convention is a little different from what’s prob in the book

mss20:03:54

changed the comment so the full namespaces are there 😜

😄 4
exit220:03:30

Weird, getting this error now: [fulcro.client.primitives] get-ident returned an invalid ident for class

exit220:03:41

its a warning actually, but pretty ugly

mss21:03:36

sounds like you might not have a proper ident on your form component? I use something like :ident [:forms/by-id :form/id] and then in my initial state will add :form/id :my-form. you’ll want to make sure you add :form/id to your query

exit214:04:58

ok cool, this works w/ your example

exit214:04:17

my ident for my form is [:update-booking :tab :booking] though, how would I make that work?

mss15:04:58

sorry for the late reply – I think of idents as having two pieces: 1) the table name in your app state. this could be :bookings/by-id and then 2) the index/id/primary key within that table like :booking/id. so your ident would look like [:bookings/by-id :booking/id]

mss15:04:25

it seems like you might be doing this in a top-level page? if so why not make a separate component with the ident you want to actually house this form/ui

mss15:04:15

for the form I’d do something like I mentioned above with the [:forms/by-id :form/id] so that every form across your app is stored in the forms table in your app state

mss15:04:02

if you need to reference specific bookings you could have a ui of cards within the form that each have the ident of [:bookings/by-id :booking/id]. just an example of how I might flesh this out

mss15:04:26

that way your router/page state, your form state, and your indiivudal booking state are all decomposed and placed in different parts of your app db for use elsewhere in the application

winkywooster21:03:39

I created an app with lein new fulcro fapp1

winkywooster21:03:14

When I start it, it pauses for a little over 3 minutes…

$ npx shadow-cljs server

shadow-cljs - config: /Users/eblood/tmp/fapp1/shadow-cljs.edn  cli version: 2.8.25  node: v11.12.0
shadow-cljs - starting via "clojure"

[ 3:21 pause ]

19-03-29 21:26:05 2-3754.local DEBUG [fapp1.server-components.pathom-wrappers:11] - Registering resolver  fapp1.model.user/all-users-resolver
19-03-29 21:26:05 2-3754.local DEBUG [fapp1.server-components.pathom-wrappers:11] - Registering resolver  fapp1.model.user/user-resolver
19-03-29 21:26:05 2-3754.local DEBUG [fapp1.server-components.pathom-wrappers:11] - Registering resolver  fapp1.model.user/user-address-resolver
19-03-29 21:26:06 2-3754.local DEBUG [fapp1.server-components.pathom-wrappers:11] - Registering resolver  fapp1.model.user/upsert-user
shadow-cljs - HTTP server available at 
shadow-cljs - HTTP server available at 
shadow-cljs - server version: 2.8.25 running at 
shadow-cljs - nREPL server started on port 9000

winkywooster21:03:28

How would I determine what the pause is?

winkywooster21:03:25

Also:

$ lein repl
If there are a lot of uncached dependencies this might take a while ...
REPL server launch timed out.
lein repl  66.67s user 1.38s system 105% cpu 1:04.49 total
$

thheller21:03:12

@winkywooster what java version do you have? might be running into the user.clj related thing fixed in https://groups.google.com/d/msg/clojure/0YFGUdzCZ5U/bUW5SRO5BwAJ

winkywooster21:03:10

Thanks @thheller, updating deps.edn with org.clojure/clojure {:mvn/version "1.10.1-beta1"} fixed the issue.