Fork me on GitHub
#re-frame
<
2020-12-02
>
Александр Стоянов05:12:01

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

p-himik06:12:49

Deref them:

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

p-himik06:12:10

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* ]>

p-himik06:12:29

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

p-himik06:12:52

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.

kimim09:12:49

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

p-himik11:12:45

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