Fork me on GitHub
#re-frame
<
2021-09-13
>
Ryan13:09:21

I'm having some re-frame woes today

Ryan13:09:14

(rf/reg-event-db
  ::toggle-starred
  (fn-traced [db [_ person-id]]
    (let [val (get-in db [:tracker :person-list :people person-id :starred])
          x (util/console-log val)]
      (assoc-in db [:tracker :person-list :people person-id :starred] (not val))
      )))
I have this event reg

Ryan13:09:20

I run it first time, it's null

Ryan13:09:26

second time: true

Ryan13:09:31

third time: false

Ryan13:09:35

every other time: still false

Ryan13:09:49

The subscription and app-db in 10x never updates

Ryan13:09:17

if I remove the last key just to see what the get-in is returning, its just the starred property even if I never specify it -_-

Ryan13:09:21

I have code ghosts

p-himik13:09:05

To weed out the obvious thing - are you 100% sure person-id is always the same one and is always correct? Do you have any global interceptors registered?

p-himik13:09:57

Also, just in case - no need for get-in + assoc-in when you have update-in.

(update-in db [...] not)

lsenjov13:09:02

Question: any particular reason it’s not

(rf/reg-event-db ::toggle-starred
  (fn-traced [db [_ person-id]]
    (update-in db [:tracker :person-list :people person-id :starred] not)))

lsenjov13:09:20

Beat me to it

😛 2
Ryan13:09:44

No reason in particular! 🙂 I started with that and broke it out to try and see what was failing but let me try it again that way

p-himik13:09:12

It won't change anything, the problem is elsewhere.

p-himik13:09:14

If you're sure about person-id and you're sure about there not being any global interceptors that might influence that value, then I'd try to come up with a minimal reproducible example. Otherwise, it's just crystal gazing.

Ryan13:09:49

Understood, there are no global incerceptors

Ryan14:09:38

Right, so now the event itself is not throwing any console errors, but the app-db inspector does not show the value updating

Ryan14:09:14

I can use the path inspector to get to :tracker :person-list :people 32 :starred]

Ryan14:09:24

32 is the person-id

Ryan14:09:35

(hand coded sample data)

p-himik14:09:41

fn-traced is something that doesn't change the result, right?

Ryan14:09:02

I was under the impression it was just to support re-frame 10x event tracing

p-himik14:09:45

I try not to assume too much when the namespace declaration is not provided. :)

Ryan14:09:38

I mean, wise 🙂

Ryan14:09:53

(ns pnx-web.events
  (:require
    [re-frame.core :as rf]
    [re-pressed.core :as rp]
    [pnx-web.db :as db]
    [day8.re-frame.tracing :refer-macros [fn-traced]]
    [pnx-web.util.core :as util]))

p-himik14:09:07

If it's a small public project available somewhere along with instructions or an obvious way to run it, I can take a look.

Ryan14:09:39

It is none of those things, unfortunately. 😕 It appears the db is not getting updated and nothing is obviously erroring, Am getting some warnings about seqs not having keys, but I don't think that would manifest this way

lsenjov14:09:44

The part that gets me about this is you saying the first time you run it it’s still null

lsenjov14:09:03

Oh right, that’s expected, since it’s logging before you’ve changed the value

Ryan14:09:35

ok yeah that makes sense

lsenjov14:09:07

How are you reading the value? Through simple sub or through tooling?

lsenjov14:09:35

(Or just through what the bit of debug outputs?)

Ryan14:09:47

10x, but Im messing with it in repl now and making some headway

Ryan14:09:09

I think one of the items in the db. is in an extra vector I didn't mean for it to be in and that's confounding some things

Ryan14:09:24

my people list is a vector of maps that are keyed by the id.. trying to use the indexed entity pattern

Ryan14:09:16

Oh maybe its the event is firing with strings, and the keys are numbers

Ryan14:09:33

That seems like its a problem thinking-face

p-himik14:09:27

Which was the very first question I asked. :D

Ryan14:09:35

32 and "32", looks the same to me 😳 😞

p-himik14:09:45

Happens.

👆 2
Ryan14:09:54

My hubris leads me to believe the problem is always more complicated than it ends up being! Learning clj is a humbling experience for sure, haha!

Ryan14:09:11

Thanks as always!

👍 2
Ryan14:09:36

annnd of course it works now! 🙂

🎉 2
kennytilton22:09:34

Clojure has different print statements. print and println produce output for human consumption. I learned early on not to use that ^^^, for this very reason. Better:

By default, pr and prn print in a way that objects
can be read by the reader
"The reader" means the Clojure reader. This is the one that will print strings showing the quotation marks.

👍 2
p-himik22:09:17

And FWIW, when in the browser, I always use js/console.log. "1" and 1 will be printed slightly differently, enough for me to notice, but there will be a benefit of being able to interactively study the printed objects, both CLJS and JS ones.

Ryan14:09:04

Thats great advice, I need to use console.log and println 🙂

p-himik14:09:11

I think kennytilton meant the opposite - not using println and instead using prn because it clearly shows the actual type.

👍 2