This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2016-07-31
Channels
- # admin-announcements (1)
- # beginners (1)
- # boot (91)
- # cljs-dev (11)
- # cljsjs (8)
- # cljsrn (38)
- # clojure (89)
- # clojure-dusseldorf (1)
- # clojure-russia (6)
- # clojure-spec (14)
- # clojure-uk (4)
- # clojurescript (25)
- # data-science (1)
- # datascript (3)
- # datavis (4)
- # emacs (25)
- # events (1)
- # jobs-rus (3)
- # off-topic (1)
- # proton (3)
- # re-frame (19)
- # reagent (5)
- # specter (10)
- # yada (1)
Is there a good way to replace a re-frame (reagent) type 3 component entirely when the relevant ratoms change
Context is, I have component-did-mount things that are bound to the original state created
@bpicolo: you can use this to convert underscores: https://github.com/qerub/camel-snake-kebab
@bpicolo: for the other question an example snippet might be helpful, not sure I understood 🙂
@bpicolo: you may be able to add a custom handler/format in cljs-ajax that does that for you
@bpicolo: as for your other question, you should bind both to component-did-update and component-did-mount
another trick is to separate the component into inner-component and outer-component , where the latter passes the data (get-in @global-state [:foo :bar]) to the inner component as a prop
then the inner component will be independent of the ratom changes and can take care of reacting to props changes through lifecycle methods
@bpicolo: personally I've found that underscores are OK-ish, one of the reasons being that they make it cleaner which fields came from the server
@mikethompson: I've found myself doing joins like this regularly: https://gist.github.com/si14/db0ed40123c14a28b6f5808e3a824c1d is it a bad thing/code smell? Am I right that the second style (`packages-better`) is more efficient, though more boilerplate-ish? I've looked hard at this https://github.com/yatesco/re-frame-stitching-together/blob/master/src/cljs/demo/views.cljs and this https://github.com/Day8/re-frame/blob/be6c53131d5a457b641bb657ac2935c6f1489969/examples/todomvc/src/todomvc/subs.cljs , but it seems that the particular problem of data normalisation isn't covered there
@si14
1. :packages
will re-run on every single change to app-db
. Even if it has changed in an unrelated way. So :packages-better
will potentially be more efficient. It's mapv
computation will only run if package-by-id
or package-ids
changes.
2. I can't see much joining going on. I see mapv
, but not much clojure.set/join
? Not sure what to make of that.
3. You are right, this issue isn't covered in any of my cods because, in my apps, I don't run into this join problem. I query the database for the data I want, joining at that level, and that gives me the data in the client app already in the (joined) form I need. But obviously requirements vary, so that strategy may not work in your case.
Hi Mike, I'm really liking the changes to fx handlers from a philosophical perspective, but I'm having a bit of troubling with a bug that's making me think my implementation is whacky. I have a little test case set up for a textbox with typeahead . On its change event it fires an event-fx which does some ajaxy stuff. But after 2 to 10 keystrokes (it's seems random) the whole app resets itself to initial app state.
Here's how my handlers are set up:
(reg-event
:handle-suggestions
(fn [world [_ results]]
(assoc (:db world) :suggestion-results results)))
(reg-fx
:suggest
(fn [val]
; This used to grab some server side stuff in a go block
; but I removed that for simplicity. Fake it till you make it.
(dispatch [:handle-suggestions (str "Fake Ajax Response from" val)])))
(reg-event-fx
:bounce-search
(fn [db [_ term]]
{:db (assoc db :search-term term)
:suggest term}))