Fork me on GitHub
#re-frame
<
2023-11-28
>
mikerod15:11:14

Regarding the new “flow” concept https://day8.github.io/re-frame/Flows/#cleanup Mentions that the default cleanup dissoc’s the path. This seems like a destructive default to me if I’m reading it correctly. If you’re path is nested a bit, dissoc of the whole thing could take out a lot of the db you didn’t intend. Or does dissoc only happen on the last segment of the path?

mikerod15:11:31

I know this can be overridden either way. Just pointing out I’d have to be defensive against the default in typical usages depending on what “dissoc the path” means.

isak15:11:32

I don't think that makes sense. If someone says I'm going to delete this path on your disk: /archive/foo/bar/baz , would you think they are deleting /archive as well? I think if it says they are dissocing that path, they are dissocing that path - not the parent, grandparent, etc of that path.

isak15:11:19

So then I was wrong (sorry mike), because it cleans up other paths than the one specified going up to the root (but only if they would be empty). I could see how it would be useful, but still seems dangerous as a default. What if someone has a sorted map or something that would not get automatically re-initialized correctly with assoc-in, update-in, etc.

👍 1
isak15:11:27

I'd also say it isn't doing what it says in the docs (it is doing more)

mikerod15:11:02

Part of why I didn’t just read the source was to point out the ambiguity of it in the docs. Forgot to mention that. But thanks for the input. I think this “deep merge” is better than blindly removing the whole path. I agree with @U08JKUHA9 that it’s still a bit more aggressive than I’d expect from a default. The sorted collection situation is a good example of why

Kimo16:11:16

Yeah, I'm not satisfied with how it is in the docs. I haven't thought of a description that's both specific and concise enough. Maybe I'll just link to the https://github.com/day8/re-frame/blob/master/src/re_frame/utils.cljc#L85C50-L85C50. What do yall think of the https://github.com/day8/re-frame/blob/master/src/re_frame/utils.cljc#L85C50-L85C50?

isak16:11:00

Yea the docstring seemed too verbose, that is better. I also think the name is wrong - it isn't deep. If anything, it is shallow, but that is probably confusing.

isak17:11:26

At the top that same file we also have a dissoc-in function: https://github.com/day8/re-frame/blob/master/src/re_frame/utils.cljc#L5-L18

p-himik17:11:06

Good catch.

Kimo22:11:13

I remember looking at dissoc-in and passing it up for some reason. It passes the same tests, though. Maybe that reason is gone.

😮 1
Nundrum20:11:39

I'm missing something about the startup of re-frame. The template app I started with has this:

(defn dev-setup []                                  
  (when config/debug?                               
    (println "dev mode")))                          
                                                    
(defn ^:dev/after-load mount-root []                
  (re-frame/clear-subscription-cache!)              
  (let [root-el (.getElementById js/document "app")]
    (rdom/unmount-component-at-node root-el)        
    (rdom/render [views/starter] root-el)))         
                                                    
(defn init []                                       
  (re-frame/dispatch-sync [::events/initialize-db]) 
  (dev-setup)                                       
  (mount-root))                                     
But when I reload the app page, it seems ::events/initialize-db isn't fired. I don't see it in the re-frame-10x interface, and the db there also shows empty. My app shows an empty page as a result. I would kind of expect the event to fire, or else for the db to be left as-is after the page reload. What am I missing?

p-himik20:11:51

Does anything call init?

Nundrum20:11:31

Looks like the init-fn in shadow-cljs.edn does

p-himik20:11:04

How does that look?

Nundrum20:11:47

:builds
 {:app
  {:target     :browser
   :output-dir "resources/public/js/compiled"
   :asset-path "/js/compiled"
   :modules
   {:app {:init-fn heedyapp.core/init}}
   :devtools
   {:preloads [day8.re-frame-10x.preload
               ;re-frisk.preload
               ]}

p-himik20:11:15

Just to double-check: • Are you building the :app build? • Is that namespace in the first message indeed heedyapp.core? If the answers are "yes", then two things to do: • Check the JS console for errors, see what's in there • Print something in the init and make sure it's printed in the console

Nundrum20:11:14

Yes and yes.

Nundrum20:11:24

I added the console message.

Nundrum20:11:10

Yet 10x still has no content.

Nundrum20:11:56

And just to show the println

(defn init []                                      
  (re-frame/dispatch-sync [::events/initialize-db])
  (println "you've called INIT!")                  
  (dev-setup)                                      
  (mount-root))                                    

Ben Lieberman20:11:47

if you have a separate events ns that contains that event, is it required in your core ns?

Nundrum20:11:10

I guess I've done something to break 10x. This was working before.

Nundrum20:11:58

The page acts as if the db is there.

p-himik20:11:49

Ah, wait. IIRC, re-frame-10x will start showing any content only after you open it and initiate some event (any event) after that.

1
Ben Lieberman20:11:39

oh good thinking that is true

Nundrum20:11:08

This bug looks very similar to what I see. I tried the "pop out" button and everything populates. https://github.com/day8/re-frame-10x/issues/264

Nundrum20:11:21

Ah, well, I guess that solves the mystery for now.

Kimo12:11:57

That's a difficult thing to fix. I'm just thinking of a workaround, though. Maybe 10x could optionally dispatch a no-op event to the client re-frame at this time.

Kimo10:12:18

Okay, you can try including the closure-define day8.re-frame-10x.init-event? true to try out this workaround. See how the example project does it: https://github.com/day8/re-frame-10x/blob/071448858cc9a4e22ac2a1adf8e2e1b48d2ec775/examples/todomvc/shadow-cljs.edn#L32

Nundrum15:12:06

I'd like to say that fixed it. It helped a little - I see the ::intialize-db in 10x when I reload the page now. But I'm noticing that 10x doesn't "see" any events unless they happen while the 10x panel is open. FWIW I upgraded to 1.9.0 yesterday.

Kimo16:12:42

maybe the event should dispatch when the panel opens, instead of at init time

p-himik19:12:49

Seems that that change has made re-frame-10x panel appear on every page reload.