This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2021-12-10
Channels
- # adventofcode (54)
- # announcements (30)
- # asami (13)
- # aws (10)
- # babashka (16)
- # babashka-sci-dev (44)
- # beginners (95)
- # calva (63)
- # clara (10)
- # clj-kondo (3)
- # cljfx (6)
- # cljs-dev (7)
- # cljsrn (1)
- # clojure (68)
- # clojure-europe (59)
- # clojure-nl (7)
- # clojure-norway (12)
- # clojure-spec (6)
- # clojure-uk (6)
- # clojurescript (4)
- # component (4)
- # conjure (5)
- # datomic (3)
- # deps-new (1)
- # events (4)
- # exercism (1)
- # figwheel-main (1)
- # fulcro (33)
- # gratitude (1)
- # improve-getting-started (3)
- # jobs (3)
- # lsp (5)
- # malli (10)
- # membrane (5)
- # music (3)
- # nextjournal (6)
- # off-topic (42)
- # pedestal (2)
- # polylith (14)
- # portal (11)
- # re-frame (42)
- # releases (3)
- # reveal (4)
- # shadow-cljs (62)
- # tools-build (1)
- # tools-deps (3)
- # web-security (1)
- # xtdb (3)
Why do I noit see the changed text
(defn main-panel []
(let [text (re-frame/subscribe [::subs/read-text])]
[:section.hero.is-fullheight
[:div.hero-body.has-text-centered
[:div.container
[:div.box
[:div.columns
[:div.column.is-two-fifths
[:textarea.textarea {:on-change #(re-frame/dispatch [::events/update-text (-> % .-target .-value)])}]]
[:div.column.is-one-fifths]
[:div.column.is-two-fifths
[:p text]]]]]]]))
re-frame: no subscription handler registered for: :re-frame.subs/read-text. Returning a nil subscription.
@U0EGWJE3E I think the problem is related to the way you named your sub and the way you are calling it. If you are using a namespaced keyword in the subscribe call (re-frame/subscribe [::subs/read-text])
then the name of your subscription should also be with namespace and because you are already in the subs namespace the only thing missing is another pair of :
like this (re-frame/reg-sub ::read-text ....
also the name is expecting that the namespace :re-frame.subs exists and this is another error
Hello, could there be any issues with using rf/subscribe
in a function that is not tied to a view component? I saw the mention https://cljdoc.org/d/re-frame/re-frame/1.0.0-rc6/doc/faqs/how-can-i-use-a-subscription-in-an-event-handler of avoiding that practice within an event handler, but in my case I'm not using the subscription in an event handler fn, just a 'standalone' cljs fn that needs the subscription's current value as a on-off thing (i.e., it's immediately deref'd).
As far as I understand subscriptions trigger re-renderings. So, since the function isn't a view function this might be problematic. I'd say, if you need the value if the sub, why not just deref it in the view before passing it to the function?
We have a handy subscription to determine if a certain feature is enabled, based on a value stored in the re-frame app-db. E.g., [:feature-enabled? :coffee-maker]
And I'd like to find out if a certain feature is enabled... but in a bit of code that's far removed from the view layer and re-frame in general. It's a service that gets initialized with plain-old cljs and does some communication with a web worker.
That sounds like it should be done in an effect handler because it's a side effect. If it's very far removed then use the side effect to pass it on.
The service's lifecycle is managed as a stuartsierra.component
and we just need the feature-enabled?
value upon initialize of that component. Do you think it would be safer to go ahead with the subscription usage, or to 'manually' deref the re-frame app-db atom and check the value directly (rewriting some of the work that the subscription is doing)?
You shouldn't use subscriptions anywhere but in reactive contexts. Or rather, you can call subscribe
anywhere, but you should deref the resulting reaction at least once in a reactive context (view functions, other reactions).
The relevant issue: https://github.com/day8/re-frame/issues/740
@U0HJJF9A4 Do you trigger the features at run time, without reloading the page?
Yes, depending on the value of the :feature-enabled?
subscription, as it is checked shortly after pageload, the particular service would be initialized.
Let me rephrase - do you change the features after the services have already been initialized?
Only initial state (though it is not hard coded either (retrieved from LaunchDarkly))
Then personally, I wouldn't even consider the features state to be a part of the application's state. Hence, I wouldn't put it in app-db.
We have a lot of view components (living in a re-frame land) that show/hide based on the :feature-enabled?
subscription value. That's why we store the results from LaunchDarkly in the app-db.
So it is also in a reactive context, so this is probably fine? (though it may depend on which page the user is on, whether there are currently any reactive contexts)
Yeah, but you don't need app-db for that. There's nothing to react to here, it's static data. Compare
(def feature-enabled? (atom true))
(def feature-view []
(when @feature-enabled?
[...]))
to all you have to do with registering subs and populating the relevant fields in app-db via some special events, and then thinking about where you can/should or can't/shouldn't use them.
For similar things, if they are backend-driven, I either put them in <meta>
tags if they can be fetched right then with index.html
(or into some <script type="application/transit+json">
if it's complex) or into some regular atom in some separate namespace that would be populated with an AJAX call.(in my code above, the assumption is that the rendering is delayed till feature-enabled?
is set to the right value)
Thanks for the response, btw. So the thing is, a feature's enabled value can change over time (websockets w/ LaunchDarkly). However, in the case of the service I was referring to above, that one only checks once (during init). There are some others that show/hide view components that we want to use the most recent feature flag value for (hence the existence of the re-frame subscription).
Alright. And where do you do your components initialization? Is it in an effect handler or some other place?
It's a Stuart Sierra component, and the feature flag value is checked in the start
component/Lifecycle method
If you call it in an effect that's triggered by an event, you will be able to pass it the relevant information from app-db from the event handler and down to the effect arguments.
That would be better, but unfortunately it would require significant refactoring. I think I'm leaning towards keeping the subscription misuse. Hmm... going off of what you mentioned above (meta tags), could be interesting to have a view component that just renders meta tags with all the feature flags, and then retrieve them from the DOM when needed outside of a reactive context. Would that be crazy?
you could store the initial state of the feature flag someplace else, then initialize both the app-db and the component from that shared place
re-frame should really add a tap
or some other kind of fn that allows one to look at a sub w/o caching it though
Are their any breaking changes i should be aware of if i'm upgrading from 0.10.6 to latest? I would also be interested in hearing experience reports. I have read the changelog myself and didn't see anything (that wasn't reverted). Here is 0.10.6 in the change log https://day8.github.io/re-frame/releases/2018/#0106-2018-09-03 . I see not
Thanks. That helps.