This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2019-02-11
Channels
- # adventofcode (8)
- # announcements (1)
- # arachne (23)
- # beginners (146)
- # boot (4)
- # calva (2)
- # cider (48)
- # cljs-dev (17)
- # clojure (214)
- # clojure-austin (2)
- # clojure-berlin (1)
- # clojure-europe (9)
- # clojure-italy (5)
- # clojure-nl (2)
- # clojure-sanfrancisco (2)
- # clojure-spec (124)
- # clojure-uk (67)
- # clojured (3)
- # clojurescript (95)
- # community-development (7)
- # cursive (68)
- # data-science (1)
- # datomic (80)
- # emacs (19)
- # figwheel (3)
- # figwheel-main (5)
- # fulcro (61)
- # javascript (2)
- # kaocha (1)
- # off-topic (25)
- # pathom (21)
- # pedestal (1)
- # perun (4)
- # reitit (11)
- # ring-swagger (2)
- # shadow-cljs (55)
- # spacemacs (4)
- # sql (8)
- # test-check (16)
- # tools-deps (2)
- # vim (13)
- # yada (4)
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?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})])}))))
@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?
ah actually nevermind; your issue is due to how you are invoking the new todo item component
(new-todo-item {:todo/id :new :todo/label ""})
if you do this the prop :todo/label
will always be ""
what's the right way to call it?
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))
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.`
@mark340 try
:initial-state (fn [_] {:new-todo (prim/get-initial-state NewTodoItem {})})
on Rootbingo!
Thanks
Thanks. I'm trying that now
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
@timeyyy_da_man if you don’t need full stack cards, try
instead
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
: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 thinkits just serving files so if you have something serving resources/public
already you can just use that
I only mean the :http-root
:http-port
stuff. those servers ONLY serve static files. they don't do anything themselves
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
@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
I already released a new template…was it still not right? @timeyyy_da_man
@timeyyy_da_man don’t bother…I’m testing.
README also needed an update in order for both to work with same build…with figwheel they were diff builds
re-pushed the new template…that should make it work for both…updated readme with instruction changes as well
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.
@timeyyy_da_man Thanks for checking
@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.