This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2016-10-24
Channels
- # arachne (1)
- # aws (1)
- # beginners (43)
- # boot (67)
- # cider (7)
- # cljs-dev (14)
- # cljsjs (6)
- # clojure (215)
- # clojure-czech (2)
- # clojure-dev (12)
- # clojure-dusseldorf (2)
- # clojure-italy (1)
- # clojure-russia (22)
- # clojure-spec (2)
- # clojure-uk (33)
- # clojurescript (85)
- # cryogen (2)
- # cursive (1)
- # datascript (22)
- # datomic (18)
- # dirac (8)
- # hoplon (9)
- # klipse (1)
- # lein-figwheel (5)
- # leiningen (126)
- # off-topic (1)
- # om (57)
- # onyx (159)
- # pedestal (33)
- # planck (2)
- # re-frame (52)
- # reagent (3)
- # ring (2)
- # ring-swagger (16)
- # test-check (12)
- # testing (5)
- # untangled (86)
- # vim (6)
I just released version 0.4.0 of my form building library: https://clojars.org/com.pupeno/free-form/versions/0.4.0 tested with re-frame 0.8.0 🙂
in my app state, there are two part of the data, one change should trigger the other part to change, is there a way to do it or am I modeling sth wrong?
@rui.yang you can use an :after
interceptor to 'listen' for changes to app-db https://github.com/Day8/re-frame/blob/master/docs/Interceptors.md#the-links-of-the-chain, or you can dispatch another event from your event handlers
@mccraigmccraig thanks. I havent studied 8.0’s doc. had a look at inceptor, still dont know how to solve my scenario nicely
my scenario is like: in UI: a client list drop down -> a list of client delivery addresses drop down -> a form with address details
a change in client list drop down will set selected_client_id in app-db, which will reset address list drop down
ideally, once selected_address_id change, a function should re-calculate the according fields of 'address form’ data in app db
@rui.yang which bit is causing you problems - sounds like wherever you have used the word 'change' above you should have an event handler, maybe with further event-handlers to deal with responses to async api calls if the UI is a client for a remote API ?
@mccraigmccraig I guess I’ll have to dispatch two events on every change event above. eg. for changing address, I will dispatch an event to update selected_address_id, and a second event to reset ‘address form’ data in app-db
@rui.yang if you have the address form data readily available you can update both the selected_address_id
and address form
data in app-db in a single event handler, otherwise you may have to make an api call and dispatch on receipt of the response
I have all the address data available in app-db. the problem is that I have built an unified way to handle general form change to app-db, that’s an :update-model event, triggered by on-blur of every form element. so I’ll have to dispatch another event to reset address details related field in app db
hmm - could :update-model
be split into an event-handler which calls a db-update fn (which does all the work), and then you can re-use the fn in the event-handler which handles a :selected-address-id-change
event ?
handler for :update-model is pretty generic. it accepts a keys to locate part which needs to be updated in the app-db map, and a value. all it does is to set the value in app-db. I am not sure if I understand how to re-use
more abstractly, i'm suggesting that it will be easier if your re-frame events relate to things which are happening in your UI, rather than things you would like to do to your view-model, and to use regular fns to abstract mutations on your view-model - event-handlers are then free to re-use and mix view-model mutation fns as required
@mccraigmccraig thanks for the tips.
With the new reg-sub syntax (`:<- [:some-subscription]`) https://github.com/Day8/re-frame/blob/master/examples/todomvc/src/todomvc/subs.cljs#L130-L147, is there any way of getting the parameter of a subscription?
@curlyfry: I've not tried it, but if you look at https://github.com/Day8/re-frame/blob/master/src/re_frame/subs.cljc#L97-L127 that syntax is just sugar on top of the 2nd variation. Maybe try writing your subscription as the 2nd variation, and then if you attach re-frisk you can take a look at the q-vec
and d-vec
that you are passing in and see how you would need to destructure them to pass them in to to your subscribe
calls. If you run into a dead-end let me know and I might have some time today to look into it.
@shaun-mahood: Cool, just tried using the 2nd version but totally missed that i get the d-vec in the second fn!
@curlyfry: Does it all work then?
@shaun-mahood: Not yet, trying to figure out exactly how the q-vec and d-vec work!
because something things can’t be set as properties of a component such as focus
and indeterminate
@shaun-mahood: Is there any documentation anywhere on what q-vec and d-vec contain?
@curlyfry: No docs that I know of, subscriptions are one of the areas where the docs are still pretty lacking since 0.8 unfortunately. What you could do to find out - add re-frisk
to your project, and in the code for your subscription put in
something like (re-frisk/add-data :sub-testing {:q-vec q-vec :d-vec d-vec})
and then pass different values in to see how what goes where. Alternatively you should be able to do the same with print statements.
@curlyfry: Have you looked into dynamic subscriptions at all? I haven't yet, but I expect that's what the d-vec is for based on the comments in the code.
Yeah, that works too 🙂
@shyambalu :component-did-mount (fn [ref] (reagent/dom-node ref))
https://github.com/reagent-project/reagent/blob/master/src/reagent/core.cljs#L196
i'm using it plenty on desktop and mobile browsers @shyambalu - it definitely works (reagent 0.6.0)
@mikethompson I think I'm gonna need your expertise in figuring out how q-vec and d-vec work in subscriptions (if/when you have the time)! Slightly confused now, especially about when using a subscription that takes parameters.
@curlyfry how can i help?
Oh, right, reading back in the stream
So this doesn't work:
(reg-sub
:derived-from-thing
:<- [:thing here-i-want-an-id] ;; <-- can't add here-i-want-an-id
(fn [thing [_ the-same-id]]
(derive-value-from thing the-same-id))
The :<-
is meant only for the simple case that you don't need query params
So when you do have them, you need to drop the use of the sugar and go back to the long form way ...
(reg-sub
:derived-from-thing
(fn [[_ id] _] ;; supply signal function - destructure q-vec to obtain id
(subscribe [:thing id])) ;; now you can supply id to further subscription
(fn [thing [_ the-same-id]]
(derive-value-from thing the-same-id))
I'm not sure you need d-vars. In fact, given this proclamation https://github.com/Day8/re-frame/issues/218 I'm not sure that anyone ever needs d-vars again
Some explanation around d-vars here: in corner case #1 here: https://github.com/Day8/re-frame/issues/218#issuecomment-252470445
has anyone done a write-up / how-to for getting re-frame and devcards playing nice with each other?
@mattly: Not really, best resource I'm aware of right now is https://github.com/nberger/devcards/blob/iframe/example_src/devdemos/re_frame.cljs