Fork me on GitHub
#fulcro
<
2018-11-21
>
miridius08:11:03

noob question: I want my footer to become visible when the window is scrolled past a certain distance (let's say 1000px), and become invisible again when the window is scrolled back above that distance. The implementation of the visibility is pretty straightforward, on the footer I have:

(defsc Footer [this {:keys [ui/visible?]}]
  (dom/footer {:classes [(when visible? :.visble)]}
    ...content...))
then I've registered a listener function on js/window for "scroll" events. I assume what I should be doing is calling prim/transact! (or perhaps mut/toggle!) from within this listener function but I'm not sure what to pass as the component.

miridius08:11:57

I'm also not sure about whether I need ident, query, and initial state on the Footer component for storing :ui/visible? in the db, or whether that should all be on Root, or perhaps both?

claudiu08:11:10

@miridius For this sort of stuff I usually init the listener in new-fulcro-client and pass it the reconciler (transact! works with reconciler). You can add follow-on reads to the transaction for targeted refresh.

claudiu08:11:11

The ident should be up to you, how you structure you're app. If you store the :ui/visible? in the root and just pass it to the dumb footer (no query, ident), should work. If footer has query & ident, the operation might be cheaper since you could add a follow-on read to target the refresh.

miridius09:11:40

ah ok, then I think it makes the most sense to give the footer a query and ident so that I'm not refreshing Root every time the user scrolls

claudiu09:11:30

Something like https://github.com/fulcrologic/fulcro-template/blob/develop/src/main/fulcro_template/client.cljs#L29 I usually pass the reconciler . Here I see the start-routing gets the root and the load gets app šŸ˜„ Think app and reconciler are interchangeable in this context.

miridius09:11:05

one more question: is it normal to give Root an ident, or is it more idiomatic to store its keys at the top level prefixed with :root? And if the latter, do you put the :ui prefix first or second, i.e. :root.ui/footer-visible? vs :ui.root/footer-visible?

tony.kay16:11:03

Never give root an identā€¦that causes weirdness on your normalization.

claudiu09:11:14

Root like in this one https://github.com/fulcrologic/fulcro-template/blob/develop/src/main/fulcro_template/ui/root.cljc#L87 does not have an ident. I you need stuff that's in the top level in you're components you do the '_ stuff http://book.fulcrologic.com/#_using_data_from_root

miridius09:11:38

mmm ok cool, I guess I should have spent more time looking at the template! Thanks šŸ™‚

miridius09:11:54

I think my mistake was to make the template with nodemo so I didn't see all this example code

claudiu09:11:18

these are just convetions so it's up to you http://book.fulcrologic.com/#_client_database_naming_conventions . The only one I know that has a meaning in fulcro is :ui/something. Since fulcro will elide it from the query sent to the server. But in the case of root you don't do df/load on it so adding :ui/root-prop1 has no special value there

claudiu09:11:56

hmm šŸ™‚ the're two templates https://github.com/fulcrologic šŸ˜„ fulcro-lein-template & fulcro-template (this one is just a demo app)

miridius09:11:13

ahh! šŸ˜„

claudiu09:11:09

nodemo was removed from fulcro-lein-template along with figwheel recently šŸ™‚ it's just lein new fulcro project-name now, and you get the full setup with shadow-cljs

miridius09:11:26

Is it always mandatory that any component initial state and component query has to be composed into the root initial state and root query for it to work?

claudiu10:11:58

do you have a use-case where it seems like there's something not ok ?

miridius10:11:02

no not really, I think I'm just still wrapping my head around core concepts

claudiu10:11:07

Not much magic, but yep takes a while to get used to šŸ™‚

claudiu10:11:58

Initial state is called when you mount the app, and basically traverses all the tree and generates the app "intial state"

claudiu10:11:12

For the query stuff it helps to check out this šŸ™‚ http://book.fulcrologic.com/#_automatic_normalization

claudiu11:11:25

it's mostly about (fulcro.client.primitives/db->tree root-query current-db current-db) The query is annotated with metadata about components, and that's how the state gets normalized

claudiu10:11:56

the queries need to compose all the way up to the root.

claudiu10:11:36

inital-state is optional but if you want it there when you start the app then yep you have to compose it in the parent, and parent to it's parent etc...

Andreas Liljeqvist13:11:54

I am trying to do a remote mutation with tempids. The response from remote is #:fulcro.client.primitives{:tempids {"tempid" 17592186045446}}

Andreas Liljeqvist13:11:44

and the mutation was transacted on {:db/id "tempid" :morekey 3}

Andreas Liljeqvist13:11:17

Where the ident is [:material/by-id :db/id]

Andreas Liljeqvist13:11:56

Why isn't "tempid" updated in {:material/by-id}?

claudiu14:11:18

shot in the dark... Did you use transact! with the component that has the indent [:material/by-id :db/id] ?

Andreas Liljeqvist14:11:56

yup, (prim/transact! this [(save-material ~props)])` where this is component with ident

claudiu14:11:15

how did you generate the temp-id. did you use prim/tempid ?

Andreas Liljeqvist14:11:22

I did not, trying to use it now

Andreas Liljeqvist14:11:48

Having a problem with the representation though, prim/tempid does not like datomic

claudiu14:11:53

@U7YG6TEKW prim/tempid is needed you can pass it you're value like (prim/tempid "myid") don't know about datomic, but I know it is used with fulcro so should work.

Andreas Liljeqvist15:11:02

it works with (prim/tempid)

Andreas Liljeqvist15:11:30

Requires a bit of remapping though. Got dropdowns using :db/id as :value but tempids are not legal as value

roklenarcic16:11:28

Hm according to the book (input :.ui.input {:type "text"})should work

roklenarcic16:11:39

But it somehow creates a text field that can't be edited

roklenarcic16:11:43

but (input :.ui.input #js {:type "text"}) works

roklenarcic16:11:21

what am I missing?

exit217:11:18

Has anyone used to the stripe elements stuff with Fulcro yet?

roklenarcic18:11:04

it's dom/input, html5 component

roklenarcic18:11:11

better question would be, when I use shorthand for classes in components, if I have additional attributes, do I pass them as js object or cljs map?

tony.kay20:11:36

you can do either. it should not matter. The macro detects which you do, and does the right thing (including converting the map at compile time, if possible)

exit218:11:59

is there an equivalent to reagentā€™s adapt-react-class in Fulcro?

exit218:11:39

would that be similar to factory-apply?

claudiu08:11:21

@U3MG3NJCC What is you're use-case ? Is this what you're looking for http://book.fulcrologic.com/#_factories ?

currentoor19:11:19

is it an anti-pattern to query for the active state of a particular state machine, in a UI component?

tony.kay20:11:41

That is fineā€¦donā€™t remember if I made a helper yet.

tony.kay21:11:38

doesnā€™t look like I did. There are a number of these kinds of things that still need refinement. perfectly valid to look at the state machine state. Technically you would normally query for it via an ident query so that UI refresh would be consistent with the data model, but since the state machine system updates all actors on changes it would be safe to use prim/component->state-map to pull the state map and look in the active state machine table.

currentoor19:11:50

i know i have the ability to modify an actors state however i like, so if i canā€™t query the actual active state i can put markers in app state in event handlers

devo20:11:28

The example for theming in the fulcro book uses an atom for pulling theme state. Can css-local-rules pull data for theming out of props somehow, or is the css generated at a point that would make that difficult?

devo20:11:14

Was getting an error attempting to use

{:css (fn [props] [[:.foo {:color (-> props :theme :color)}]])}
due to the function being the wrong arity

tony.kay20:11:22

You cannot use props. Dynamic generation of css causes all sorts of complications and performance hits.

tony.kay20:11:11

ā€œthemingā€, it seems to me, is a global concern, not something that should be component local. If you want to change how a component looks, change which classes it uses, donā€™t change the CSS.

tony.kay20:11:31

browser recomputing the css cascading rules is waaaay more expensive.

šŸ‘ 8