inject-sub-cofx helper from https://github.com/den1k/re-frame-utils/blob/master/src/vimsical/re_frame/cofx/inject.cljc which is also mentioned in the https://cljdoc.org/d/re-frame/re-frame/1.0.0-rc6/doc/faqs/how-can-i-use-a-subscription-in-an-event-handler#solutions.
We think there is an issue exist:
If you deref reagent atom outside of reagent rendering context, dependent subscription are not updated inside a
watching list of parent subscription. So when you
dispose! it, dependent subs are not getting disposed.
Instead of using
deref, should https://github.com/reagent-project/reagent/blob/4f40516b0b1e90aac7b35800b34c769f48986ac6/src/reagent/ratom.cljs#L426 be used which properly updates ratom
I’ve put up example code demonstrating the issue https://gist.github.com/dmitryn/eff1ac30948913490f6feff396f26b9f
Can you add relevant usages of
dispose! to your gist, so it's more clear?
Yes, updated the comment there
No clue what's going on there. Frankly, no clue what exactly
run is doing as well. That's an incredibly densely packed part of Reagent with barely any documentation.
Also, no clue why the second
(.-watching sub) returns two items instead of one.
But it seems like you could get rid of all the re-frame specific stuff and ask a similar question in #reagent.
Yes, it’s more a reagent.ratom question, rather than re-fame. The reason i asked because inject-sub-cofx is a re-frame utility and it also mentioned in re-frame docs so people probably use it
Hi everybody, I am trying to internationalize my re-frame app. First question. I try tempura, is it what you advice to use with re-frame? Then I was originally trying to link it to a subscribe.
(def tr (partial tempura/tr opts [(rf/subscribe [::subs/language])])). But it seems not working. I'm not sure to understand why. my language is a keyword, like
:en and the usage
(tr [:example]). The following error occurs
Uncaught Error: Doesn't support name: [object Object] at Object.cljs$core$name [as name] (core.cljs:9524) at Function.eval (impl.cljc:314) at Function.eval [as cljs$core$IFn$_invoke$arity$3] (core.cljs:3918) at Function.eval [as cljs$core$IFn$_invoke$arity$2] (core.cljs:3913) at Function.eval [as cljs$core$IFn$_invoke$arity$2] (core.cljs:3948) at G__48897__delegate (encore.cljs:1655) at G__48897 (encore.cljs:1636) at eval (impl.cljc:325) at eval (core.cljs:5648) at eval (core.cljs:5648)
I'm not sure to understand what is happening there.
tempura as well, I find it quite nice.
In your code, you're feeding
tr the ratom returned by
subscribe. You want to deref that ratom first.
tr within a
:tr sub. And then I have my own version of
tr that's basically
#(deref (subscribe [:tr %])). Of course, that
tr must be used only in views and only during rendering.
ouch, I feel a little bit embarrassed, so obvious.... I definitely need to improve my use of cljs repl for a better debugging. Thx it works1👍
I expect cljs side for my subscribe, but I see functionnalities in tempura using resources on disk
CLJS, of course. But you can use tempura on CLJ side - e.g. for SSR or for some data coming from the server.
I don't like
:__load-resource for two reasons:
- It's pretty much undocumented
- Inlining l10n resources makes it harder to implement language switching in runtime without inflating the bundle size. I prefer to serve the l10n data from the server - only the language that's currently selected.
Ah, also judging by the code, you will see the
"Runtime resource loading not possible for cljs dictionaries. See tempura/load-resource-at-compile-time` as an alternative."` error if you use it with CLJS.