Allow subscribe to be safely called from any context#754
Allow subscribe to be safely called from any context#754dannyfreeman wants to merge 1 commit intoday8:masterfrom
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
4b3c142 to
a9d7e79
Compare
9b2dee6 to
492838f
Compare
The
warn-when-not-reactivewarnings 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