This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2022-03-11
Channels
- # announcements (15)
- # aws (11)
- # babashka (13)
- # babashka-sci-dev (2)
- # beginners (63)
- # calva (20)
- # cider (9)
- # clj-kondo (27)
- # clojars (3)
- # clojure (34)
- # clojure-art (4)
- # clojure-europe (21)
- # clojure-filipino (1)
- # clojure-indonesia (1)
- # clojure-my (1)
- # clojure-nl (11)
- # clojure-norway (10)
- # clojure-sg (1)
- # clojure-spec (4)
- # clojure-uk (4)
- # clojurescript (5)
- # cursive (8)
- # deps-new (2)
- # events (1)
- # exercism (2)
- # fulcro (44)
- # graphql (6)
- # gratitude (1)
- # introduce-yourself (1)
- # jobs (3)
- # leiningen (5)
- # lsp (26)
- # membrane (18)
- # missionary (9)
- # off-topic (1)
- # pedestal (5)
- # portal (1)
- # quil (24)
- # re-frame (17)
- # reagent (5)
- # remote-jobs (2)
- # reveal (3)
- # spacemacs (4)
- # tools-build (1)
- # tools-deps (12)
;; run the ui
(backend/run
(fn []
(with-effect-handler my-counter-effect-handler
(counter-ui (my-counter-effect-handler [:get-count])))))
The app doesn't react to change at this point, right? counter-ui
is initialized with a number and the count atom will increment when the button is clicked but the change wouldn't show up on the ui unless you re-run the app.
The next section introduces references to solve the problem "that it doesn't say which counter should be incremented". Don't references also enable the app to be reactive without re-running the whole app? In the snippet above, with-effect-handler
gets a ui element , counter-ui, that has already curried a number for the count. There's no way to change the count in counter-ui; you must construct a new counter-ui. Using a reference instead would allow the value to change as is epitomized in the quote: "By identity I mean a stable logical entity associated with a series of different values over time."
If I have the right idea then I'd like to see the blog mention whether the pseudocode example is enough to give us an app that updates the count on button click or if that is currently missing and gained by using references. The gif shows the count update on button click which makes me think I just don't understand how it's currently reactive.https://blog.phronemophobic.com/reusable-ui-components.html https://blog.phronemophobic.com/ui-state/counter.gif
It should change at that point in the blog post
The function
(fn []
(with-effect-handler my-counter-effect-handler
(counter-ui (my-counter-effect-handler [:get-count]))))
Will be called to rerender the view whenever an event occursYea, I just double checked.
It makes sense. I convinced myself that there must be more to it since it would need to re-build the ui for every change; I assumed that there was a reason that wasn't doable. Performance or something idk; I was hand waving... Thanks.
defui
does some caching, but you can get pretty far rebuilding the UI on every change.
You do eventually want some sort of caching just so you're not wasting CPU or run into issues as your app gets bigger, but building a view is usually pretty fast
If I recall correctly, even React usually rebuilds the full vdom on every change unless you override stuff like componentDidUpdate
Thanks. I'm re-reading the third blog post since I couldn't take it all in the first time. I just finished the first five chapters of fulcro's developer guide. I like the co-located query and initial state. I can imagine how that makes for reusable components. I also really like that membrane components return the intents instead of effectfully dispatching in the :on-click, :on-changed thing.
Yea, I liked fulcro when I looked into it. I learned a lot when I gave it a try. I think the biggest differences between how membrane and fulcro are: • membrane components are pure functions • membrane components return values • I remember fulcro's story for dynamic queries was awkward. For example, implementing a tabbed pane component is tricky. • I remember it being awkward handling incidental component state and contextual state. For example, implementing a textarea where the cursor, text, selection, and focus state are incidental is tricky. It's been a while and I never became a fulcro expert, so ymmv.
I'm wondering why the effectful way is ubiquitous; is it a concern that you can't return the value? e.g. :on-change #(swap! assoc :thing (.. % -target -value))
If I try to return the thing, the real value might go out of scope since it's interop with the browser... Wait no, it's the same as swapping it into a db. Never mind.
I guess it's just easy...
Do any other framework return the "I'm clicked" events?
I think the number one reason most frameworks use effectful events is that the general approach is trying to layer functional code on top of OO code.
Basically, they try to bolt on functional approach on top of HTML,Swing,GTK, etc
Before talking about it today, I thought the java2d backend was using java2d stuff. I see now that it's all in graphics2d. That makes sense.
I thought that graphics2d was part of the java2d API, https://docs.oracle.com/javase/tutorial/2d/overview/index.html