Fork me on GitHub
#re-frame
<
2017-03-28
>
burke14:03:00

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?

burke14:03:23

okay. problem solved.. My component was defined with (defn component [] (fn [copy] .... )) instead of (defn component [copy] (fn [] .... )) 😬

mccraigmccraig14:03:30

@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

burke14:03:04

where would you initialize the component-state copy-object? Is the router the right place?

mccraigmccraig14:03:30

what dyu mean by router @burke ? the re-frame router or something else ?

burke15:03:59

@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?

mccraigmccraig15:03:52

sounds roughly reasonable

burke15:03:35

I will try that. Thanks for your help. 🍀

danielcompton19:03:23

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

kenny23:03:07

@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])])

kenny23:03:54

And of course you’d do the same for init-tracing! 🙂

danielcompton23:03:00

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

danielcompton23:03:57

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

danielcompton23:03:25

@kenny i.e. there's two separate things here, the re-frame-trace visualiser, and the tracing code in re-frame