membrane

zimablue 2023-09-25T18:45:03.195699Z

what is contextual actually doing differently? the references are in a part I find hard to read in the macros, something like -> don't look in 'default', or 'extra', look in 'context', so that contextuals (just focus?) are available anywhere in the component tree? How does this interact with the caching?

phronmophobic 2023-09-25T18:50:09.577019Z

There's a longer answer at https://blog.phronemophobic.com/reusable-ui-components.html But the short answer is that :contextual data is implicitly passed down the whole tree. > How does this interact with the caching? As you might expect, putting lots of data that changes frequently in context is bad for caching. It's best for state that doesn't change frequently. Focus is the most common kind of contextual state, but I think it can make sense for other global state like drag&drop, modals, app-wide styling info, etc.

zimablue 2023-09-25T18:50:47.330909Z

so if focus changes, does a component need an explicit reference to that focus to trigger a redraw? or everything redraws?

zimablue 2023-09-25T18:51:05.065659Z

thanks for the link, I'll reread it

phronmophobic 2023-09-25T18:53:11.627099Z

There's two steps that happens when state changes: 1. Creating a new view 2. Drawing the new view Right now, there's only a few optimizations to save repainting (mostly, because it hasn't been necessary). If the state changes, then it probably triggers both #1 and #2.

phronmophobic 2023-09-25T18:53:52.613889Z

phronmophobic 2023-09-25T18:54:11.953599Z

Basically, when the state changes, the view function gets called again and the repaint function gets called again.

phronmophobic 2023-09-25T18:54:45.266969Z

There's quite a bit of caching done in the view function when using defui components and a little bit of caching done in the repaint function.

zimablue 2023-09-25T18:55:32.444989Z

I think my question related to the interaction with the caching of the view function using defui components

zimablue 2023-09-25T18:57:51.441549Z

I shouldn't have said redraw, you're right "view" vs "repaint" is the distinction

phronmophobic 2023-09-25T18:58:13.525719Z

Yea, there's a cache that memoizes the building of components. Right now, there's not really any special way for a component to say which data it cares about (including contextual data). Part of the problem is that even if a component doesn't care about contextual state, a child component might.

phronmophobic 2023-09-25T18:58:59.479409Z

I think there's some really cool optimizations that can be done, but I haven't spent much time on it because it hasn't been a bottleneck for me.

phronmophobic 2023-09-25T18:59:27.247639Z

The neat thing is that these optimizations are generic and could be applied to any similar clojure program.

zimablue 2023-09-25T18:59:29.919079Z

it's not a bottleneck for me, it's more trying to understand the motivations/constraints for the code

👍 1
zimablue 2023-09-25T18:59:31.788089Z

thanks for explaining

phronmophobic 2023-09-25T18:59:38.389129Z

Yea, no problem.

phronmophobic 2023-09-25T19:01:07.242469Z

I actually wish I could spend more time on these optimization problems because they're interesting, but there's a lot of other work that's probably more impactful.