Fork me on GitHub
#fulcro
<
2020-09-19
>
AJ Snow01:09:52

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"})]})

AJ Snow01:09:59

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

nivekuil03:09:45

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ý (HolyJak)15:09:11

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

lgessler16:09:32

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

nivekuil16:09:31

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

nivekuil16:09:07

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?

lgessler16:09:39

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

lgessler16:09:49

from shadow i mean

lgessler16:09:56

yeah I use cursive so idk what cider might say

3
nivekuil16:09:48

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

nivekuil16:09:38

but cider seems to be unaware of that. Alas

nivekuil22:09:39

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

nivekuil06:09:03

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})

nivekuil06:09:26

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

nivekuil06:09:59

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.kay06:09:02

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

nivekuil16:09:25

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

tony.kay19:09:16

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.

nivekuil17:09:48

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

nivekuil17:09:04

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"

tony.kay18:09:51

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.

nivekuil18:09:32

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

nivekuil19:09:15

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.

nivekuil06:09:29

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.kay19:09:50

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?

nivekuil06:09:58

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.kay19:09:19

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 Smith10:09:32

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 Smith12:09:40

ah I reloaded some things and it started working