Fork me on GitHub
#membrane
<
2022-03-11
>
Richie18:03:29

;; 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.

phronmophobic18:03:02

It should change at that point in the blog post

phronmophobic18:03:04

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 occurs

phronmophobic18:03:40

Yea, I just double checked.

Richie18:03:35

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.

phronmophobic18:03:42

defui does some caching, but you can get pretty far rebuilding the UI on every change.

phronmophobic18:03:41

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

phronmophobic18:03:19

If I recall correctly, even React usually rebuilds the full vdom on every change unless you override stuff like componentDidUpdate

Richie18:03:18

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.

phronmophobic19:03:17

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.

Richie19:03:24

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?

phronmophobic19:03:00

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.

phronmophobic19:03:59

Basically, they try to bolt on functional approach on top of HTML,Swing,GTK, etc

Richie19:03:22

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.

Richie21:03:25

Sorry, what I said doesn't make any sense. I assumed that the java2d backend was using awt stuff. Like a java Button component for a button. I see now that it's just rectangles and text.

👍 1