Fork me on GitHub
#re-frame
<
2021-09-12
>
jkrasnay17:09:42

Hi folks. Based on comment here a few days ago by @emccue I was inspired to try a pattern of wrappers around Re-frame subscriptions. I’ve written it up here: https://gist.github.com/jkrasnay/12ed298d1058d47ef6714618753a081f

emccue14:09:29

I mean, I do appreciate the focus on having a symbol that will throw a compiler warning, not just anger a linter

emccue14:09:28

but i'm still not sure about how best to tie "domain model function" to "registered subscription"

jkrasnay17:09:34

I didn’t think it was possible to have the linter detect typos in subscription keywords. That would certainly help avoid this wrapping stuff.

jkrasnay17:09:39

Can you elaborate on “domain model function”? I posted here because I’m unsure myself whether my wrapper is a good idea, so I’d appreciate hearing about your experience.

isak18:09:48

We did something similar (really for item 1) and it works ok, but an issue can be subscriptions that are more nested/complex. The symbol names get kind of goofy in such cases with -- separators for nesting, etc, to the point where it seems better to just use a vector with a keyword.

emccue20:09:04

> Can you elaborate on “domain model function”? Well, i'm still hung up on how to take the "entire state of the world" and divide it into managable chunks

emccue20:09:26

if you have a single structure - your "domain model" - you can make functions that work with that structure

emccue20:09:36

subscriptions are magic lookup into the global scope and i don't know if the same things you write for a subscription would be good functions for working with a "nested" scope

jkrasnay12:09:06

After using this for a few days I’ve decided that the downsides outweigh the advantages, e.g. I can’t use LSP to find all references, which I can actually do with the plain subscription keyword. I can always pull out an accessor function in the few cases where some event could use the access pattern as the subscription.

jkrasnay12:09:44

Seems this is a common pattern for me. I start thinking “maybe a macro would help here” and I usually end up reverting it!

emccue14:09:36

yeah - at least with what i described earlier with the defevent - the symbol we use the most is the one the linter can pick up

emccue14:09:01

the handler:event-name and event:event-name are more rare to use in the codebase proper and mostly get seen in tests

jkrasnay17:09:57

Any feedback would be greatly appreciated!