Fork me on GitHub
#re-frame
<
2017-11-01
>
joshkh09:11:40

@mikethompson that's the one, thanks.

cmal09:11:08

Hi, can I use reagent's r/track method in a re-frame project? I got an error when I try to do this:

cmal09:11:25

The error messages are:

mikethompson09:11:31

you con't seem to have clj-devtools installed ?

cmal09:11:25

You mean the error messages are not formatted?

cmal09:11:58

I run this code in a wechat simulator and the simulator blocks the formatter of the devtools.

danielneal09:11:48

what is a wechat simulator?

cmal09:11:36

wechat is a app like line used mainly in China.

danielneal09:11:22

yes! I used wechat when I was in china 🙂 I was wondering what the simulator is. Are you developing a wechat application?

cmal09:11:57

it is called wechat develper tool

danielneal09:11:29

It seems like you can do Everything in we chat

mikethompson09:11:53

The first message is this re-frame: no handler registered for effect:

mikethompson09:11:13

But then we don't get to see which effect keyword is unregistered

cmal09:11:43

cljs.core.Keyword {ns: null, name: "target", fqn: "target", hash: 253001721, cljs$lang$protocolmask$partition0$: 2153775105, …} ". Ignoring.

cmal09:11:50

after the :

cmal09:11:03

it refers to the target(the first is exist)

cmal09:11:10

I define it using r/track

cmal09:11:34

(defn exist []
  (:exist @logger-state))

mikethompson09:11:03

effects are returned by event handlers

cmal09:11:25

Because I want to decompose the component to in another place. I do not want to define the app-state globally.

cmal09:11:29

So I use r/track to track the local state.

danielneal09:11:12

(reg-event-fx
 :logger-iframe-dispose
 (fn [_ _]
   (swap! logger-state assoc :exist false)))

cmal09:11:17

Should I use r/track? If not, how to define a local state in a component in re-frame?

danielneal09:11:25

The error is from the lines above

danielneal09:11:33

you are returning a map with {:exist false} in it from the swap!

danielneal09:11:51

so reframe is looking for an effect defined for :exist

danielneal09:11:31

as if you'd typed

(reg-event-fx
 :logger-iframe-dispose
 (fn [_ _]
  {:exist false})))

danielneal09:11:19

(swap doesn't return nil, it returns the new value)

cmal09:11:01

When I call (rf/dispatch [...]) is the global state the one being modified? Does the swap! statement make the logger-state my global-state?

danielneal09:11:22

what's happening is this

danielneal09:11:35

* you call (rf/dispatch [:logger-iframe-dispose])

danielneal09:11:52

* the handler

(reg-event-fx
 :logger-iframe-dispose
 (fn [_ _]
   (swap! logger-state assoc :exist false))) 
is run

danielneal10:11:12

* that handler swaps the local state atom as you'd imagine

danielneal10:11:21

* however it is also returning the new logger state from the swap

danielneal10:11:28

* {:exist false ...}

danielneal10:11:56

* reframe interprets this as you wanting to dispatch the :exist effect with args false

cmal10:11:58

So I cannot do rf/dispatch if what I want is just change the local state, leave the global state untouched.

danielneal10:11:03

* the :exist effect hasn't been dispatched

danielneal10:11:26

the quickest way to make the error go away would be to do this

danielneal10:11:37

(reg-event-fx
 :logger-iframe-dispose
 (fn [_ _]
   (swap! logger-state assoc :exist false) 
   nil)) 

danielneal10:11:47

but it might be better if you're dealing with local state like this to call functions directly

cmal10:11:56

I got your idea. Thanks.

danielneal10:11:57

reframe handlers tend to be pure

danielneal10:11:14

but I hope this helps understand why you got the error and what is going on

danielneal10:11:27

yeah that is probably clearer

cmal10:11:43

I've changed that code. Sorry for the error.

eoliphant20:11:42

hi, i was just curious to see if anyone has any thoughts regarding posh vs (or even with) re-frame. It’s obviously not as mature as re-frame, but i’m also doing datomic on the server, so the relative consistency between the two is attractive

mccraigmccraig20:11:41

i saw https://github.com/denistakeda/re-posh a while back... never tried it though

eoliphant20:11:06

yeah saw that too

eoliphant20:11:00

I’m messing around with an interactive form builder, and it’s underlying data structure can get a bit complex. So I was using specter to do that stuff in the event handlers, but in just my few hours of playing around, it seems a bit nicer in terms of being able interact with it as datomic-lite.. at least for my use case

jeaye23:11:35

I'm looking to force re-frame to run through its entire queue before I background. In looking through the source, I haven't found such a function. Any tips?

jeaye23:11:36

I can see the issue with such a function, since it may never exit, but I don't quite see how I'm supposed to ensure some events are executed before I background without just doing a bunch of serial dispatch-sync calls outside of an event handler... which isn't very idiomatic re-frame usage.