Fork me on GitHub
Александр Стоянов05:12:01

Hello! How can i work with r/atom db in re-frame without this: #<Atom: []> ?


Deref them:

(let [a (r/atom 1)]
  ;; Either like this
  ;; Or like this
  (deref a))


And you shouldn't directly access app-db - you should rely on subscriptions.

Александр Стоянов06:12:51

That's whole chain: (def records (r/atom [])) --- (rf/reg-sub ::get-data (fn [_] db/records)) --- (def recs (rf/subscribe [::subs/records])) [:p "" @recs]

Александр Стоянов06:12:43

So it comes like #<Atom:[ *data* ]>


Derefing a sub returns the value that the sub function returns. Your sub function returns a ratom, so derefing that sub returns that very same ratom. If you want to get the value within the ratom, just deref it inside the sub function. But you shouldn't be using external ratoms in your subs. You either should just directly use ratoms, without any subs, or put the relevant value in the re-frame's app-db via some event.

Александр Стоянов06:12:34

And if i deref if subs it returns me #<Reaction*some number*: [data]>


If you removed the @ in front of recs then add it back. If you didn't, them I can't really add anything to my previous message. Just don't use regular ratoms in subs.


Hello, i don’t know how to redirect to different SPA, after login. Anyone have an example? Thanks.

Dmytro Bunin10:12:49

Maybe something like

(aset (.-location js/window) "href" url)

Dmytro Bunin10:12:58

you can put it in reg-fx


Depends on what "different SPA" means exactly. If you mean the same page within the same application, then ideally you would use some routing library like e.g. bidi or reitit that integrate well with HTML5 history. They have all the necessary facilities to redirect from one page to another. If you mean an entirely different app, then the answer above is the correct one. Except that you should not use aset. It should be

(.assign js/location url)
I think.

👍 6