fulcro

Book: http://book.fulcrologic.com, Community Resources: https://fulcro-community.github.io/, RAD book at http://book.fulcrologic.com/RAD.html
Mr. Savy 2020-09-19T01:31:52.017300Z

is there a way to set up a return map in the initial state that has a to many relationship? I'm thinking something like

(fn [{:keys [name] :as params}] 
{:component/name name
 :component/list [(comp/get-initial-state Item {:id 1 :name "A"}) (comp/get-initial-state Item {:id 2 :name "B"})]})

Mr. Savy 2020-09-19T01:39:59.017500Z

oh snap that works. it looks like I just need to apply the ui-item factory to every component in the vector. yay!

nivekuil 2020-09-19T03:29:45.017700Z

people who do the #?(:clj (pc/defmutation {::pc/output ...}) :cljs (m/defmutation ...)) pattern: as you have to (:require-macros [com.wsscode.pathom.connect :as pc]) in cljs for shadow to compile this file, how do you tell clj-kondo/clj-refactor to leave you alone with the com.wsscode.pathom.connect is required but never used warning?

Jakub Holý 2020-09-19T15:02:11.021700Z

I don't have the code here but I believe I just have #?(:clj (:require [com.wsscode.pathom.connect :as pc]), ie no require-macros

lgessler 2020-09-19T16:13:32.022700Z

I use this pattern and just import pc without a cljc reader macro: https://github.com/lgessler/glam/blob/master/src/main/glam/models/project.cljc#L3

nivekuil 2020-09-19T16:25:31.023Z

hm, and you have a ::pc somewhere in that file? I don't think that compiles

nivekuil 2020-09-19T16:26:07.023200Z

yeah but cider still gives me a warning since it's apparently not used if you #?(:clj) the pc/defresolver too. I guess your IDE is ok with it?

lgessler 2020-09-19T16:38:39.023600Z

I only have ::pc under :clj sections, which keeps me from getting an error

lgessler 2020-09-19T16:38:49.023800Z

from shadow i mean

nivekuil 2020-09-19T16:39:48.024200Z

cider still complains unfortunately. I figured that the kw expansion needs to see the require at read time, same as the reader conditional

nivekuil 2020-09-19T16:40:38.024400Z

but cider seems to be unaware of that. Alas

nivekuil 2020-09-20T22:03:39.037200Z

I just noticed that if I include pathom in the (:require ...) without a reader conditional, it gets included in the cljs build, adding about 67kb to my shadow-cljs report. but if I just #?(:cljs (:require-macros [com.wsscode.pathom.connect :as pc])) it isn't there, saving me that bit of space since I don't actually use pathom from cljs

nivekuil 2020-09-19T06:04:03.018Z

I ran into some surprising behavior with the synchronous comp/transact!! stuff: #(m/set-value!! this :field value) will actually clobber any props passed from the parent in the process of setting :field to value. to work around this I do

#(comp/transact!! this ￱￱[(m/set-props ￱~￱(assoc props :field value))] {:compressible? true})

nivekuil 2020-09-19T06:06:26.018800Z

but the async version, set-value!, behaves as expected.

nivekuil 2020-09-19T06:19:59.018900Z

specifically the prop being passed in is used as the ident in the child and it gets set to nil after the first character is typed into an input which calls that onChange

tony.kay 2020-09-19T06:34:02.019800Z

You're changing an id in a mounted component???

nivekuil 2020-09-19T16:36:25.023400Z

Oh, to clarify the ID changing to nil is the behavior I am seeing with the sync transact, not the behavior I want.

tony.kay 2020-09-19T19:51:16.024600Z

If you can put up a minimal repro case of what you’re seeing go wrong I can take a look. You’re claiming that a call to a sync transact is working differently in terms of what ends up in the state atom than an async one. Could be a bug, but I’m not seeing how.

nivekuil 2020-09-20T17:47:48.034900Z

sure. I can repro it with a workspace card forked from fulcro-template: https://github.com/nivekuil/fulcro-template/commit/be807f9588d03f188365f5c835fcb5bc3915f3d3

nivekuil 2020-09-20T17:49:04.035100Z

screenshots show what the state looks like after typing one character into the input, and after two -- it seems the ident gets set to nil upon typing the second "a"

nivekuil 2020-09-20T17:50:19.035800Z

tony.kay 2020-09-20T18:56:51.036600Z

Your form has to have an ID, otherwise the ident has nil for an id. There is nothing wrong with Fulcro here. It’s your code. Add an ID into intiial state for the form.

nivekuil 2020-09-20T18:59:32.036800Z

is this expected to happen only with synchronous transactions? the nil ident does not show up if I use set-value! instead of set-value!!, and the existing ident gets modified as expected

nivekuil 2020-09-20T19:05:15.037Z

adding :form/id :bar to initial-state doesn't visibly change anything. ident is still [:form/by-id :my-form] on the first char, then [:form/by-id nil] on subsequent chars.

nivekuil 2020-09-19T06:38:29.019900Z

well, I don't think my intent is anything weird like that.. but I could be totally mistaken. say you have a Person with a child PersonForm, I want the PersonForm to have an ident [:person-form/id :person/id]

tony.kay 2020-09-19T19:52:50.024800Z

a person form should have the exact same ident as a person. That is the whole point of normalization…changing the table name denormalizes the database…why would you want to do that?

nivekuil 2020-09-19T06:39:58.020Z

I don't want PersonForm to be always visible (say only if the user can edit Person), so I conditionally mount the PersonForm in Person's render().. is that weird?

tony.kay 2020-09-19T19:55:19.025Z

if you mean: I want to toggle between an editable and non-editable version of a person, then no, that isn’t weird…but you should not be rendering one within the other, there should be some kind of container above with logic that manages that particular desire by choose which to render. I personally would make that one stateful component for Person that has perhaps two different plain functions that can be used to render the different styles of view. It’s the same data…really, what I do is make it a form and only a form, and play with the css and such to tune how it looks in non-edit mode.

Adrian Smith 2020-09-19T10:53:32.021Z

in https://youtu.be/F7QzFpo8pA0 it seems like indexes can be loaded using Fulcro inspect without a resolver for :com.wsscode.pathom.viz.index-explorer/index how is that working?

Adrian Smith 2020-09-19T12:16:40.021100Z

ah I reloaded some things and it started working

lgessler 2020-09-19T16:38:56.024Z

yeah I use cursive so idk what cider might say

➕ 1