Fork me on GitHub

Are subscriptions memoized / optimized based on their parameters?


I.E. say I have 2 components, component-a and component-b


component-a has:

(let [some-db-value @(subscribe [::subs/generic-subscription :foo])]


and component-b has: (note the only difference is the param to the subscription)

(let [some-db-value @(subscribe [::subs/generic-subscription :bar])]


Because they share a subscription, is a change to either sub going to cause a re-render for both? Or only for components that use the same sub, and the same sub params?


@samueldev you could put a println or similar in the ::subs/generic-subscription to find out probably


haha youre right @mikerod , will be trivial for me to find out myself, i only just stepped out and im on the bus right now 😛 i pondered it as i left my pc and thought id ask. will try in a bit!


However, the subscription is cached on the whole query vec


So the cache key used for subscribe is [::subs/generic-subscription :bar] and [::subs/generic-subscription :foo]


oh, your question was a bit different


you were asking if both would be re-rendered due to being reactive to the same underlying registered subscription


So I believe to answer that, each deref will register separate watchers on the underlying reaction


If the change to the subscription input signals does not cause a change in value from one of the deref, then I do not believe there will be any re-render triggered - because no watchers of the reaction (underlying the subscription) are triggered on a no change event


@twashing in case you’re still looking into that problem with OPTIONS, you’re probably looking at CORS preflight requests. Your http server should be set up to handle CORS. Alternatively you can serve the frontend code from the exact same server (ip and port) as the /my/endpooint, though in my experience setting up CORS is less hassle down the road.


I'm using re-frame with draftjs, but it seems to be a problem:

(let [editor-state          (reagent/atom (raw-content->editor-state-or-empty
                                             @(re-frame/subscribe [:some-key])))
        static-toolbar-plugin (create-toolbar-plugin)
        toolbar               (.-Toolbar static-toolbar-plugin)]
     [:> editor {:editorState @editor-state
                 :onChange    #(println %)
                 :plugins     [static-toolbar-plugin]}]
     [:> toolbar]])
This shows the right value. However, whenever I add an onChange method, dispatching an event to change the value (of :some-key), it doesn't work anymore. The problem is: re-frame (react?) is doing 2 calls. The first call still has the old value, the second one has the new value. On the first call, the component gets the state from re-frame and sets this state. The second call, with the new value, seems to be omitted. This results in this behaviour: on changing :some-key (selecting another item in a list of items each having draftjs-box), the previous value is set, not the current value)


any ideas how to solve this?


@kurt-o-sys I didn't really understand your explanation but looking at the code ... you are using a ratom .... so my guess is you should be using a Form-2 component


right, have done that as well. I'll recap the problem: I have plain js component (draftjs) and I want it to update when some re-frame state changes. When I run the code, it seems react (or reframe, or reagent) renders the component twice. The first time, the state is set, but also the onChange method of that component is called (that's some internal thing of draftjs). During the first call, reframe is still in the 'old' state. The second call, the reframe db has a new state, but the component (draftjs) is not updated, and still shows the old state.


thx, will check


I just realised that draftjs is a React component, not just a js component. Maybe that link I gave is not so much for this situation.


right... it doesn't seem to work out fine for now. Still trying to see how to make it work properly.


Hello. Has anyone used a react template with re-frame? Is that something that is easy to integrate with? Total newb with front-end.