Fork me on GitHub
#re-frame
<
2017-08-29
>
souenzzo00:08:37

I'm trying to use re-frame-test, but having throuble in a small/simple test. When I run this

(deftest login
  (rf-test/run-test-async
    (let [username "souenzzo"
          password "123456"
          authed? (rf/subscribe [:auth/authed?])]
      (rf/dispatch-sync [::db/init db])
      (fact "I'm not in!" @authed? => false)
      (rf/dispatch [:app/login username password])
      (rf-test/wait-for [:app.login/set-token]
                        (fact "I'm in!" @authed? => true)))))
I get Error handling response - class java.lang.IllegalArgumentException: Argument for @NotNull parameter 'path' of com/intellij/openapi/vfs/impl/local/LocalFileSystemBase.findFileByPath must not be null

danielcompton02:08:11

I've seen that error recently too, but not with ref-rame test

danielcompton02:08:18

Are you running this on the JVM?

danielcompton03:08:38

What happens with lein test?

danielcompton03:08:51

I think it might be an IntelliJ error?

plexus09:08:21

Sanity checking myself here because of discussion with a coworker. is doing a (re-frame/dispatch ) inside a (re-frame/reg-sub ) a terrible idea or not?

plexus09:08:09

my response was that subscriptions should be free of side effects, but apparently it's an established pattern in this code base to use this for side-loading missing resources

sandbags09:08:11

@plexus i guess as long as the subscription function is being called deterministically w.r.t. your use case it doesn't sound insane but distateful and prone to later problems

sandbags09:08:35

that said, it is actually written somewhere that sub functions should be free of side effects?

sandbags09:08:07

and couldn't you dispatch the event from the same place the subscription is being invoked from and be a bit less surprising?

plexus09:08:35

it was my impression that subscriptions being pure functions is a key part of the architecture. You're right we could do it in the component.

sandbags09:08:06

well i am sure that is the intention and it sounds pretty icky

sandbags09:08:47

if this was something that was somehow impossible any other way then... perhaps... but I struggle to see how it could be better than firing the event from same site as the subscription

sandbags09:08:31

i'd maybe write a helper reg-sub-with-side-load or something like that

danielneal09:08:20

There's a track effect which will automatically dispatch events when subscriptions update

mkvlr10:08:08

@plexus @sandbags why is doing it in the component better or preferred?

sandbags10:08:55

I would say it's two-fold. (1) it's more intentional, (2) you don't have a lot of control or expectation about if & when the subscription code may be run

mkvlr10:08:18

our use case is we want to perform an effect (evaluate code via a web worker) when a view is scrolled into the view but also cache that result so we only evaluate it once.

mkvlr10:08:34

and we want to reevaluate when any arguments change

mkvlr10:08:02

re-frame subscriptions cache does this for us

sandbags10:08:10

perhaps i misunderstand, but subscriptions IIRC handle caching automatically

mkvlr10:08:30

yes they do

sandbags10:08:49

and again IIRC the cache is argument sensitive

sandbags10:08:43

so the only real question is about when & where the event is fired?

sandbags10:08:27

to me it seems more intensional and in the spirit of re-frame to expose it at the point of use, rather than burying it in the subscription where it is depending on the current behaviour of the subscription framework code

mkvlr10:08:06

and do the caching ourselves?

sandbags10:08:46

are you talking about caching whether the event has been fired for some set of arguments?

sandbags10:08:15

surely that can be derived from the db state, i.e. if you've already side-loaded a particular resource you can ignore the event

mkvlr10:08:08

yeah, then we end up dispatching a lot of events that never do anything

mkvlr10:08:31

that felt wrong to me

sandbags10:08:44

i suspect that's pretty cheap depending on the actual value of "a lot" but you'd need to profile it yourself to be sure

sandbags10:08:46

look if it were me I would do 'the right' way and see how it worked in practice. the attach-to-sub thing feels like a hack. I'd fall back to that if in practice the other way didn't work out

sandbags10:08:59

ymmv of course

mkvlr10:08:06

alright, thanks

sb14:08:14

(re-frame/register-handler
  :state/msgs
  (fn [db [_ msgs]]
    (debugf "state/msgs handler: %s" msgs)
    ; (update db :pers #(conj % (vector (js.Date.))))
    (assoc db :wsmsg msgs))
    ))
`

sb14:08:44

Hello, I would like to run 2 function from a re-frame handler.. but in every case, just run one.. what I did wrong?

sb14:08:19

(first the logger and second the real db action)

sb14:08:36

(I commented in this code the first function)

kasuko14:08:27

@sb The statement (update db :pers #(conj % (vector (js.Date.)))) does not change db as db is immutable. That line returns a new representation of the map

kasuko14:08:43

Which you promptly discard and use the old immutable db in the second line

kasuko14:08:02

What you want to do is use the result of the first statement as the input to the second statement

sb14:08:42

Ok thanks the info

kasuko14:08:47

(assoc (update db :pers #(conj % (vector (js.Date.)))) :wsmsg msgs)

kasuko14:08:03

however that’s super hard to read so a thread-first macro is your friend

kasuko14:08:35

(-> db
    (update :pers #(conj % (vector (js.Date.))))
    (assoc :wsmsg msgs))

sb14:08:36

that is work now, I changed the order of the functions.

sb14:08:54

thanks the advice!

kasuko14:08:38

No problem

kah0ona17:08:53

If I want to implement drag-n-drop, what is the general strategy? Are there some examples of this? Or even libraries?

kah0ona17:08:16

I basically want a re-ordereable stack of divs

kah0ona17:08:53

but i want to do it idiomatically, so i prefer not to directly touch the dom in some dirty way 🙂

kah0ona18:08:41

and probably let the mouse coords be injected as cofx

kah0ona18:08:03

as well as the position of the ‘drop area’ to see ifthere is any overlap so that it can highlight or whatever

kah0ona18:08:19

any thoughts/pointers are welcome