Fork me on GitHub
#rewrite-clj
<
2023-07-23
>
zimablue15:07:44

What would be the best way to add data to the rewrite-clj zipper tree (eg. a flag per-node)?

borkdude15:07:19

Just use assoc?

zimablue16:07:28

Will the zipper then maintain all that information "correctly" though ? At the bottom there must be operations constructing nodes, this will only work if they're doing a merge or something?

borkdude16:07:20

don't know about zipper tree

borkdude16:07:17

why use zippers in this case and not just postwalk the rewrite-clj nodes?

lread16:07:30

@U63D7UXJB if you maybe describe your end goal, i.e. why you feel you need to flag, then maybe we could come up with more ideas. I tend to reach for the zip API, @U04V15CAJ tends to walk the nodes directly.

zimablue16:07:32

Basically I was writing a specialized edn editor (all the way back to formatted text), so theres extra state, and I want it to be "stable" under moving nodes, deleting them etc. Rewrite-clj helps me map changes in edn back to changes in (a whitespace-preserving string), but I want my UI state tagged back and stable too. One way I thought was to annotate each node with an ID, then I have two relationship (str->edn) (edn->id) and it's all good, but that will only work if rewrite-clj is happy to maintain e,tea I formation per zipper node

zimablue16:07:12

I could also try not using the zipper, I haven't thought it through, I don't think I need to accumulate multiple changes so that efficiency element of zippers is irrelevant

zimablue16:07:40

*extra information

lread16:07:10

I have some time later today to play around. I can't remember if assoc on a node would be problematic when using the zip api.

zimablue16:07:54

A concrete example: I have an edn list of strings, in my app runtime that corresponds to a UI component for each string, with state like text-cursor, I perform an operation like deleting one of the strings, now those strings all have different indexes in their parent list, but on my rerender pass I need to tie back to component state per-string the paths are broken so I need IDs

zimablue16:07:16

Please don't, I thought someone might just know the answer I'd hate for someone to spend time on it

zimablue16:07:33

I can just test it / read the code if noone knows offhand

lread16:07:31

Happy to try to help if you remain stuck. If you get unstuck, please do share what you came up with so we can all learn from your experience.