This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2018-11-21
Channels
- # 100-days-of-code (1)
- # announcements (2)
- # beginners (164)
- # cider (23)
- # cljs-dev (30)
- # cljsjs (11)
- # cljsrn (7)
- # clojure (116)
- # clojure-boston (1)
- # clojure-dev (20)
- # clojure-finland (2)
- # clojure-italy (4)
- # clojure-nl (1)
- # clojure-uk (10)
- # clojurescript (39)
- # core-async (19)
- # cursive (43)
- # data-science (2)
- # datomic (24)
- # emacs (10)
- # figwheel-main (20)
- # fulcro (63)
- # hoplon (7)
- # hyperfiddle (7)
- # instaparse (3)
- # kaocha (1)
- # nrepl (3)
- # off-topic (170)
- # onyx (13)
- # other-languages (3)
- # parinfer (13)
- # re-frame (39)
- # reagent (5)
- # reitit (22)
- # ring-swagger (4)
- # shadow-cljs (284)
- # spacemacs (2)
- # sql (27)
- # testing (28)
- # unrepl (2)
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.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?
@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.
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.
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
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.
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?
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
mmm ok cool, I guess I should have spent more time looking at the template! Thanks š
I think my mistake was to make the template with nodemo
so I didn't see all this example code
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
hmm š the're two templates https://github.com/fulcrologic š fulcro-lein-template & fulcro-template (this one is just a demo app)
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
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?
Initial state is called when you mount the app, and basically traverses all the tree and generates the app "intial state"
For the query stuff it helps to check out this š http://book.fulcrologic.com/#_automatic_normalization
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
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...
I am trying to do a remote mutation with tempids. The response from remote is #:fulcro.client.primitives{:tempids {"tempid" 17592186045446}}
and the mutation was transacted on {:db/id "tempid" :morekey 3}
Where the ident is [:material/by-id :db/id]
Why isn't "tempid" updated in {:material/by-id}
?
shot in the dark... Did you use transact! with the component that has the indent [:material/by-id :db/id]
?
yup, (prim/transact! this
[(save-material ~props)])` where this
is component with ident
I did not, trying to use it now
Having a problem with the representation though, prim/tempid does not like datomic
@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.
it works with (prim/tempid)
Thank you
Requires a bit of remapping though. Got dropdowns using :db/id
as :value
but tempids are not legal as value
Hm according to the book (input :.ui.input {:type "text"})
should work
But it somehow creates a text field that can't be edited
but (input :.ui.input #js {:type "text"})
works
what am I missing?
@roklenarcic input from what?
it's dom/input
, html5 component
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?
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)
@U3MG3NJCC What is you're use-case ? Is this what you're looking for http://book.fulcrologic.com/#_factories ?
is it an anti-pattern to query for the active state of a particular state machine, in a UI component?
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.
sounds good
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
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?
Was getting an error attempting to use
{:css (fn [props] [[:.foo {:color (-> props :theme :color)}]])}
due to the function being the wrong arityYou cannot use props. Dynamic generation of css causes all sorts of complications and performance hits.