hyperfiddle

braai engineer 2025-02-25T16:35:54.502519Z

Last night I tried to make a nested tree picker component using v3 that returns the id of the most recently clicked child node by passing back its id when the text is clicked. I am trying to use the return node values instead of passing down atoms or callbacks that update the parent node's value (this seems more electrical?), but I can't quite figure out how to deal with the nested return values and only extract the latest value. (edit: posted snippet in thread โ€“ could not add snippet to edited message) When I click on a node, I get back a top-level value like [nil [nil nil] nil [nil [:child3-a nil] nil nil]], but I only want the latest value. I tried a variety of conditional returns and e/When, (which returns (e/amb) on nil) as well as forms/LatestEdit, but I can't quite figure out how to deal with "nested value streams." Maybe Form! is the right thing here, but Form! emits a <form> element which messes with my layout. Is this the right way to approach a tree picker in v3?

xificurC 2025-02-25T16:42:37.953549Z

I just skimmed through, but if you โ€ข drop the (when (seq children)) conditional and put the e/for-by only โ€ข change the when-let on click to use an e/When then you are close. The problem is clicks need to return a value until consumed. I.e. if you click on 2 nodes you still only want 1 value. Which implies state. Tokens match the "return value until acknowledged" pattern

braai engineer 2025-02-25T16:43:39.226729Z

braai engineer 2025-02-25T16:49:37.147509Z

@xifi thx. I only want dom/ul to render when a node has children, otherwise childless nodes have a nested <ul>, which can affect layout (although does not with my current CSS). Ah, so I need to return an e/Token from TreeNode* along with id, e.g. [t id] for consumption at the caller?

Dustin Getz (Hyperfiddle) 2025-02-25T16:52:21.911709Z

e/Token is really meant for forms that transact to the server, i.e. there are busy, success, failure, retry affordances

Dustin Getz (Hyperfiddle) 2025-02-25T16:52:52.746839Z

I would start with a client-only picker, which can emit it's current state as a value

Dustin Getz (Hyperfiddle) 2025-02-25T16:53:55.611649Z

So what you want is to return the most recently clicked thing as a value, one easy way to model that is an atom, have each of your dom/On things write to a shared atom

Dustin Getz (Hyperfiddle) 2025-02-25T16:54:44.967429Z

example of a dom/On which writes to an atom - https://electric.hyperfiddle.net/tutorial/system_properties

Dustin Getz (Hyperfiddle) 2025-02-25T16:55:33.148419Z

example of what NOT to do - https://electric.hyperfiddle.net/tutorial/temperature2 - this demo collects multiple values in superposition using e/amb, that is not what a picker does, a picker returns only one

Dustin Getz (Hyperfiddle) 2025-02-25T16:57:55.921699Z

i think you've seen the typeahead from the tutorial before, note the reset! on L28 which is inside the e/for

Dustin Getz (Hyperfiddle) 2025-02-25T16:58:27.499269Z

that typeahead picker is very nearly the structure of a treepicker, just flattened, right? pick from a list of options vs a tree of options

Dustin Getz (Hyperfiddle) 2025-02-25T16:58:53.256849Z

it even has the ul/li structure, just not recursive

Dustin Getz (Hyperfiddle) 2025-02-25T16:59:24.037379Z

i recommend you type that in and master it, before moving on to the recursive case (which will be quite straightforward once you have the flat version)

braai engineer 2025-02-25T17:08:54.168089Z

Thanks ๐Ÿ™‚ So that's actually what I was doing before (I had a working tree picker I ported from my accounting system from v2), but I figured the signal flow might be more "idiomatic".

Dustin Getz (Hyperfiddle) 2025-02-25T17:10:33.422829Z

you did well to consider, really the essence of this problem is how to encode "most recent selection" and the best answer that comes to mind is racing writes into an atom

Dustin Getz (Hyperfiddle) 2025-02-25T17:10:49.560899Z

there may be a better encoding

Dustin Getz (Hyperfiddle) 2025-02-25T17:11:45.221679Z

in fact, in missionary "most recent" is the discard operation, so i would look into racing a set of discrete flows into a single continuous flow with discard as the merge operator

๐Ÿ‘ 1
Dustin Getz (Hyperfiddle) 2025-02-25T17:12:18.987079Z

I think the atom is perfectly idiomatic though, electric-level solutions are definitely preferred

2025-02-25T17:36:29.116229Z

Iโ€™m seeing a new problem with electric-fiddle (commit 115f20b). For both the index page and a couple of example pages that I have tried, the UI comes up and works, but after about 10 seconds the UI is replaced with a blank page and I get an error message in the console. See thread for details.

2025-02-25T17:37:51.002789Z

This is the console error message.

Dustin Getz (Hyperfiddle) 2025-02-25T18:22:49.704529Z

that's a new one, hmm

Dustin Getz (Hyperfiddle) 2025-02-25T18:26:04.405539Z

just to be clear, you have not made any local changes to electric-fiddle?

2025-02-25T18:26:32.826609Z

Thatโ€™s right โ€” no local changes

Dustin Getz (Hyperfiddle) 2025-02-25T18:29:34.730059Z

ok, can repro, i bet it's the datomic thing

Dustin Getz (Hyperfiddle) 2025-02-25T18:29:46.097139Z

i can deal with it now

๐Ÿ™ 1
Dustin Getz (Hyperfiddle) 2025-02-25T18:52:24.023299Z

pull latest, i think its fixed

Dustin Getz (Hyperfiddle) 2025-02-25T18:52:28.325359Z

sorry

2025-02-25T18:57:27.779529Z

Yes, thatโ€™s fixed it โ€” thanks