-
-
Notifications
You must be signed in to change notification settings - Fork 718
Closed
Description
Should re-frame now allow subscribe
within a renderer?
In concrete terms, can this (current approach):
(defn my-view ;; Form-2
[]
(let [a (subscribe [:a])] ;; subscribe is put in the Form-2 setup
(fn []
[:div @a])))
... to become this (proposed):
(defn my-view ;; Form-1
[]
[:div @(subscribe [:a])])))
Notes:
- Previously this worked <= v 0.7.0 but it caused a new subscription to be created on each rerender, which meant it was a sufficiently bad idea that it effectively didn't work.
- As of v0.8.0, it now may work (theory untested) but it is still in the realm of implementation detail - it may work because now subscriptions are cached and de-duplicated.
- Is this something we want re-frame to guarantee in a future release? It looks like it could be very convenient.
I probably won't struggle too much to make this happen BUT if it naturally falls out of the current implementation it could be a good idea to officially guarantee the behavior. Just so everyone knows where they stand.
Someone needs to test if this works already ... does the new cache ensure that subscriptions are reused and not constantly created and destroyed on each rerender. Actually, in the time it has taken to write this ticket, I've gone from being 80% sure this will work to about 99% sure it will work. But a test needs to be done. And some more thinking about possible edge cases.
Metadata
Metadata
Assignees
Labels
No labels