Fork me on GitHub
#re-frame
<
2023-11-21
>
Kimo03:11:16

Flow news: • Removed :init, since we couldn't think of a strong enough use-case • https://day8.github.io/re-frame/FAQs/UseASubscriptionInAnEventHandler/: ◦ Consolidated the other js/event faq page ◦ Wrote a more thorough problem description ◦ Added more solutions (like flows and polymorphic subs) • Tweaked naming - flow<-, get-flow • Lots of code refactoring & docs proofreading

👀 1
Nundrum19:11:08

Can someone explain to me the use of :: keywords, or point me to documentation about their use in re-frame? I keep getting a warning that I don't have a subscription handler. In my subs namespace I have (reg-sub :server) and in views that is getting referenced as (subscribe ::sub/server). Is that correct?

seancorfield19:11:16

See https://clojure.org/reference/reader#_literals -- "A keyword that begins with two colons is auto-resolved in the current namespace to a qualified keyword"

seancorfield19:11:05

Or are you asking a different question? ::sub/server will resolve sub to its namespace alias, so you'll have :

seancorfield19:11:54

(so :server is not a qualified keyword and therefore not the same as ::sub/server)

Nundrum19:11:02

Ahhh I thought it was a re-frame specific thing.

Nundrum19:11:36

If I change the subscription to just :server or the reg-sub to ::server the console spits out a ton of errors.

Nundrum19:11:16

Somehow I've broken the template project 😆

seancorfield19:11:10

::server means "resolve in the current ns" -- so it also produces a qualified keyword.

seancorfield19:11:38

You need to be consistent and use ::sub/server everywhere and have the same require :as sub alias everywhere you need to use it.

👍 1
Nundrum19:11:32

I got it going again. Needed to properly deref the subscription. Took me a minute to figure out where the error was in the stack trace.

Kimo22:11:19

One good reason to namespace your handler keys is to avoid collisions. There are a bunch of https://day8.github.io/re-frame/External-Resources/ providing handlers, and explicit ownership of names allows for seamless integration. Also, once you get used to it, namespacing adds a https://github.com/matthiasn/talk-transcripts/blob/master/Hickey_Rich/MaybeNot.md?plain=1#L425 https://github.com/matthiasn/talk-transcripts/blob/master/Hickey_Rich/MaybeNot.md?plain=1#L1026 https://github.com/matthiasn/talk-transcripts/blob/master/Hickey_Rich/MaybeNot.md?plain=1#L1202 to problem solving. Once you start being explicit about what things are, a lot of the code you thought you needed to validate, interpret and conform these things can just go away.

Kimo22:11:16

IMO the crucial DX arrived in clojure 1.11 with https://clojuredocs.org/clojure.core/require#example-653bbcc569fbcc0c226173f6. This lets you decouple ownership of names from code execution dependencies. That's how you can articulate re-frame's global virtual machine very conveniently & concisely.

👍 1