This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2018-08-16
Channels
- # announcements (1)
- # beginners (83)
- # boot (10)
- # cider (23)
- # cljdoc (24)
- # cljs-dev (3)
- # clojure (138)
- # clojure-finland (1)
- # clojure-italy (12)
- # clojure-losangeles (2)
- # clojure-mexico (1)
- # clojure-nl (18)
- # clojure-russia (23)
- # clojure-sg (1)
- # clojure-spec (15)
- # clojure-uk (126)
- # clojurescript (94)
- # cloverage (2)
- # core-async (1)
- # cursive (98)
- # datomic (54)
- # figwheel-main (19)
- # hyperfiddle (21)
- # jobs (1)
- # jobs-rus (4)
- # leiningen (4)
- # liberator (4)
- # off-topic (15)
- # parinfer (9)
- # re-frame (23)
- # reagent (19)
- # reitit (2)
- # ring-swagger (3)
- # rum (3)
- # shadow-cljs (244)
- # sql (4)
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!
So the cache key used for subscribe
is [::subs/generic-subscription :bar]
and [::subs/generic-subscription :foo]
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)]
[:div.he-text-editor
[:> 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.
This may provide inspiration: https://github.com/Day8/re-frame/blob/master/docs/Using-Stateful-JS-Components.md
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.