Skip to content

Make it okay to use subscribe in Form-1 components #218

@mike-thompson-day8

Description

@mike-thompson-day8

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:

  1. 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.
  2. 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.
  3. 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

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions