-
-
Notifications
You must be signed in to change notification settings - Fork 715
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Allow subscribe to be safely called from any context #754
base: master
Are you sure you want to change the base?
Conversation
The `warn-when-not-reactive` warnings are no longer valid if we bypass the subscription cache when not in a reagent component, so they've been removed. This should address issue day8#753 This change probably requires some documentation cleanup
I love this. It seems to be an easy way – API-wise – to make values from the subscription calculation available in event and effect handlers. What seems a bit problematic, or at least questionable (in the literal sense), is: what It seems to me that the API that one would want in that situation is |
There is only one db state in existence at a time, it will not be changed out from under running code in a single threaded environment. If you call a subscription in an event then the db value will be the same as the db being used in the event. If we want something like |
Yeah. What I mean is that you might want to get the result of a calculation captured in a subscription based on the db that you're currently building a new version of in the event handler. Some pseudo code demonstrating the mechanics I have in mind, not an actual use case: (reg-sub :count-foo [db] (-> db :foos count))
(reg-event-handler :button-clicked [db new-foo]
(let [db (-> db (update :foos conj new-foo)]
(if (> 10 (get-sub-value db :count-foo))
(assoc db :big? true)
db)))
Well, not "just" because you have do extract all input subscriptions as well and compose everything together, and that might not be trivial, and/or impose significant boilerplate code when all subscriptions are written in a way that allows for that.
Sounds like a challenge! :) |
f8b5e1d
to
9dee549
Compare
69d0aa1
to
f196eee
Compare
The
warn-when-not-reactive
warnings are no longer valid if we bypassthe subscription cache when not in a reagent component, so they've been
removed.
This should address issue #753
This change probably requires some documentation cleanup