This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2017-03-28
Channels
- # beginners (8)
- # boot (49)
- # cljs-dev (29)
- # cljsrn (9)
- # clojure (238)
- # clojure-dev (3)
- # clojure-gamedev (1)
- # clojure-italy (7)
- # clojure-norway (11)
- # clojure-russia (39)
- # clojure-sanfrancisco (3)
- # clojure-spec (116)
- # clojure-sweden (2)
- # clojure-uk (53)
- # clojurescript (90)
- # cursive (13)
- # datomic (12)
- # defnpodcast (2)
- # dirac (1)
- # emacs (11)
- # figwheel (2)
- # hoplon (15)
- # jobs (3)
- # jobs-discuss (48)
- # keechma (1)
- # klipse (4)
- # leiningen (16)
- # luminus (4)
- # lumo (49)
- # mount (10)
- # off-topic (1)
- # om (13)
- # onyx (15)
- # pedestal (67)
- # perun (1)
- # planck (16)
- # powderkeg (33)
- # proton (1)
- # protorepl (2)
- # re-frame (16)
- # reagent (4)
- # ring (9)
- # ring-swagger (10)
- # rum (5)
- # slack-help (1)
- # spacemacs (1)
- # uncomplicate (15)
- # untangled (19)
- # yada (58)
Hello everyone, in my application I have a a panel where the user should be able to edit the parts of an object (a "container" with following attributes {:id "string", :title "string", :tags #{set}, :elements [vector] } ). This object is stored in the app-db but should not be changed unless the user clicks on a save button. My idea was to use a copy from the object in the db ( Let [copy-obj (reagent/atom @(subscribe [:get-object]))] ...)
to render the view and allow to make temporary changes and then finally save changes via an on-click dispatch-event on the save button.
So with another button the user can conj elements (swap! copy-obj update :elements conj new-element)
into the :elements vector of the object-copy, but this changing of the copy causes a reload of the page-panel and therefore a re-initialization of my copy object.
Isn't this the right way to use temporary atoms or is there any way to prohibit reloading the whole panel?
okay. problem solved.. My component was defined with (defn component [] (fn [copy] .... ))
instead of (defn component [copy] (fn [] .... ))
😬
@burke i tend to use a 'component-state' in app-db for such purposes - everything is easier to reason about when it's in the app-db
where would you initialize the component-state copy-object? Is the router the right place?
what dyu mean by router @burke ? the re-frame router or something else ?
@mccraigmccraig I mean the re-frame router. Use case would be, that the user opens page /edit-object/id1234/, then the router calls the :create-object-copy dispatcher and the :set-active-panel dispatcher The view would get the obj-copy via subscribe. Changes would be made via dispatchers, and save would also be an dispatcher which overrides the original obj with the modified copy. Or is there a better way?
sounds roughly reasonable
I've put some more details about re-frame-trace on the Github page for it. It's still in a very rough state, but anyone feeling intrepid might be interested in trying it out. https://github.com/Day8/re-frame-trace
that looks great @danielcompton
Thanks 😀
@danielcompton Out of curiosity, why do you have the :closure-defines
var at all? Why can’t I surround the call to trace/devtools
with a conditional statement on goog.DEBUG
(or your own env var) and the devtools call would be DCE. e.g.
(defn main []
[:div
[re-com/v-box
;; your app here
]
(when ^boolean goog.DEBUG
[trace/devtools])])
the :closure-defines
is for re-frame, to compile out the tracing calls that re-frame makes: https://github.com/Day8/re-frame/blob/master/src/re_frame/trace.cljc#L44
You can also do
(when ^boolean goog.DEBUG
[trace/devtools])
to DCE trace/devtools, but it will still have to be in your production dependencies for the compile to succeed@kenny i.e. there's two separate things here, the re-frame-trace visualiser, and the tracing code in re-frame