Fork me on GitHub
#fulcro
<
2019-02-11
>
Mark Addleman01:02:43

I'm new to fulcro (and React). I am creating a todo list app as a learning exercise. I want to write a fulcro component that accepts text from the user and adds that text as a new item in the todo list. I'm having trouble setting the properties on this component:

(defsc NewTodoItem [this {:todo/keys [id label]}]
  {:query [:todo/id :todo/label]
   :ident :todo/id}
  (dom/form {:onSubmit (fn [x]
                         (.preventDefault x)
                         (prim/transact! this [(new-item! {:todo/label label})]))}
            (dom/fieldset :.field-group
                          (dom/input {:type     "text" :value label
                                      :onChange #(m/set-string! this :todo/label :event %)
                                      :onBlur   #(prim/transact! this [(new-item! {:todo/label label})])}))))
When a change occurs, I get the following error message in the console: [fulcro.client.mutations] ui/set-props requires component to have an ident. I'm invoking the component from the Root component with the following call (new-todo-item {:todo/id :new :todo/label ""}) What am I doing wrong?

Mark Addleman01:02:44

Correction: I fixed the ident. Now I don't get the error message but the set-string! doesn't seem to do anything.

(defsc NewTodoItem [this {:todo/keys [id label]}]
  {:query [:todo/id :todo/label]
   :ident [:todo/by-id :todo/id]}
  (dom/form {:onSubmit (fn [x]
                         (.preventDefault x)
                         (prim/transact! this [(new-item! {:todo/label label})]))}
            (dom/fieldset :.field-group
                          (dom/input {:type     "text" :value label
                                      :onChange #(m/set-string! this :todo/label :event %)
                                      :onBlur   #(prim/transact! this [(new-item! {:todo/label label})])}))))

hmaurer02:02:07

@mark340 Hi! Could you elaborate a little bit on the “doesn’t seem to do anything”? Did you inspect the database (using the inspect Chrome extension) and saw no value there?

hmaurer02:02:16

ah actually nevermind; your issue is due to how you are invoking the new todo item component

hmaurer02:02:35

(new-todo-item {:todo/id :new :todo/label ""}) if you do this the prop :todo/label will always be ""

hmaurer02:02:47

it will never update with the set-string! mutation

Mark Addleman02:02:16

what's the right way to call it?

hmaurer02:02:14

try something like this:

defsc NewTodoItem [this {:todo/keys [id label]}]
  {:query [:todo/id :todo/label]
   :ident [:todo/by-id :todo/id]
   :initial-state {:todo/id :new :todo/label ""}}
...)

(defsc Root [this {:keys [new-todo]}]
  {:query [{:new-todo (prim/get-query NewTodoItem)}]
   :initial-state {:new-todo {}}}
  (ui-new-todo-item new-todo))

Mark Addleman02:02:12

One step forward. One step back. The mutation is getting the value that I input but on a fresh load of the page, I get an warning Warning: value` prop on input should not be null.`

hmaurer02:02:43

@mark340 try

:initial-state (fn [_] {:new-todo (prim/get-initial-state NewTodoItem {})})
on Root

Mark Addleman02:02:18

Thanks. I'm trying that now

timeyyy10:02:02

I just booted a fresh fulcro template with lein. It seems the workspaces doesn't work when running it from the server. . The main.js seems to be loaded correctly, but the other resources are 404 even though they exist in the resources folder. -> 404 Not found

hmaurer12:02:26

@timeyyy_da_man if you don’t need full stack cards, try instead

hmaurer12:02:39

(make sure the workspaces build is running on shadow)

timeyyy15:02:36

I want full stack cards 🙂

tony.kay15:02:51

There is nothing preventing you from using full stack cards…it looks like the shadown-cljs resource path in the dev section might be wrong path @timeyyy_da_man

tony.kay15:02:21

:workspaces {:target     nubank.workspaces.shadow-cljs.target
                       :ns-regexp  "-(test|ws)$"
                       :output-dir "resources/public/workspaces"
                       :asset-path "/workspaces"
                       :devtools   {:preloads           [fulcro.inspect.preload]
                                    :http-root          "resources/public"
                                    :http-port          8023
                                    :http-resource-root "."}
is what it should be I think

tony.kay15:02:29

if that works let me know and I’ll fix the template

tony.kay15:02:34

just get http root and asset path to align, and it’ll work

tony.kay15:02:31

that’s not quite right 😕

thheller15:02:35

:http-root "resources/public"

thheller15:02:45

:asset-path "/workspaces"

thheller15:02:11

btw you don't need to run a separate webserver for the workspaces stuff

thheller15:02:40

its just serving files so if you have something serving resources/public already you can just use that

tony.kay15:02:55

cool…I’ll tune that up

tony.kay15:02:04

I didn’t know if it affected dev preloads

tony.kay15:02:17

guess that is just compile now that I think about it

thheller15:02:53

I only mean the :http-root :http-port stuff. those servers ONLY serve static files. they don't do anything themselves

thheller15:02:56

so any webserver will do

tony.kay15:02:11

yeah, on careful thought that is obvious

thheller15:02:24

I will be moving that config stuff soon to make things a bit cleaner I hope

tony.kay15:02:33

I think when I initially set this up I thought maybe if you ran shadow-cljs watch workspaces it would only start that dev tool

tony.kay15:02:51

but I’ve seen that it pretty much starts them all no matter what

thheller15:02:15

http servers are always started as you may want to use them to test a release build

thheller15:02:26

would suck if they only run with watch

thheller15:02:40

AFAICT the only thing wrong is the resources/public/workspaces/index.html

thheller15:02:51

<script src="/js/main.js" type="text/javascript"></script>

thheller15:02:14

hmm no actually that is fine

thheller15:02:32

(given the current generated default config)

timeyyy19:02:18

@thheller /src/main/wslive/server_components/middleware.clj in the wslive function is what gets served when running from the backend server. @tony.kay PR sent

tony.kay19:02:35

I already released a new template…was it still not right? @timeyyy_da_man

timeyyy19:02:06

i didn't pull it yet, i will try it out

timeyyy19:02:16

it says the last commit was 24 days ago?

timeyyy19:02:55

mm ok, now i see the changes, github was a bit delayed.. will test

tony.kay19:02:42

@timeyyy_da_man don’t bother…I’m testing.

tony.kay19:02:45

it wasn’t right

tony.kay19:02:59

README also needed an update in order for both to work with same build…with figwheel they were diff builds

tony.kay19:02:09

in shadow they are the same, so inconsistencies mattered

tony.kay20:02:20

re-pushed the new template…that should make it work for both…updated readme with instruction changes as well

eoliphant21:02:35

quick question. I’ve created a custom remote with Pathom, etc per the example to execute a few rest calls. Everything works fine, but I need to grab a security token from an auth lib, I’ve stored in the app db, from ‘inside’ the resolver. Not sure of the best way to approach this, and wondering if this kind of stuff belongs there or just in local storage or something.

tony.kay22:02:50

@eoliphant it’s fine to use app state from within a resolver, if you’ve put it in the env…or from anywhere for that matter. Saving off the reconciler to you can get app state for arbitrary uses is fine.

eoliphant22:02:36

Ok, cool. I was having some weird problems accessing it When I say just referenced the app atom directly in the parser setup call Going to look at it again when I get home