This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2017-09-08
Channels
- # aws (21)
- # beginners (62)
- # boot (29)
- # chestnut (1)
- # cider (110)
- # cljs-dev (37)
- # clojure (93)
- # clojure-berlin (1)
- # clojure-dev (10)
- # clojure-greece (4)
- # clojure-italy (5)
- # clojure-new-zealand (1)
- # clojure-spec (6)
- # clojure-uk (46)
- # clojurebridge (1)
- # clojurescript (54)
- # cryogen (1)
- # cursive (22)
- # datomic (72)
- # emacs (2)
- # events (3)
- # flambo (1)
- # hoplon (88)
- # jobs (6)
- # juxt (51)
- # lein-figwheel (1)
- # leiningen (3)
- # lumo (12)
- # mount (4)
- # off-topic (3)
- # onyx (3)
- # pedestal (4)
- # portkey (27)
- # re-frame (13)
- # reagent (1)
- # ring (4)
- # rum (2)
- # uncomplicate (1)
- # unrepl (3)
Is it considered bad to use component local state in re-frame? Should everything go into the app-db?
My (limited) experience has been that every time I think I’ve got a valid use case for local component state, I think of something I want to do with that data outside the local component.
Though that’s also led to the experience of finding it remarkably easy to refactor from local state to app-db state.
Makes sense. If others have thoughts on that topic, I would be curious to hear more, too.
I like managing state through events, so it feels like the intended way with re-frame is to use the app-db. However, it ends up a kitchen-sink 🙂
I think I did have a few use cases where local state made sense, like if you click on an “info” icon and it pops open a small text snippet in-line with the field it’s describing. Purely visual effect, no real mutable state to manage other than visibility on/off, so I went ahead and just used a local.
The way I manage the “exploding app-db” problem is by breaking it up into what I’ll call sub-db’s (for want of a better term). Like in app-db, I’ve got a key called :user-profile-editor that holds the data for editing a user profile form, any validation errors, and anything else I need for editing.
To edit a profile, I copy the data out of a different area of the app-db, and then when we’re done editing, copy it back. That way it’s easy to discard changes if the user clicks “Cancel”
But as far as the main app-db is concerned, all of that data is just an opaque block under the :user-profile-editor key, and all the code that manipulates that block is off in its own namespace.
Thank you for your input @manutter51
@vinai as a general rule, any state that can go in app-db
should go in app-db
. That's the enduring goal we should all be pursuing.
Having said that, there are certainly cases, involving reusable components, where it makes sense for view-only-related state to be local.