Fork me on GitHub
#re-frame
<
2017-11-22
>
kah0ona09:11:58

is it possible to dispatch to multiple other handlers ? ie. {:dispatch [[:handler1] [:handler2]] }

kah0ona09:11:36

I need to do 3 http requests from the click of one button, basically

kah0ona09:11:10

of course i could do it in ugly ways or do 3 dispatches in the click handler of the button, but i was looking for an idiomatic way

danielneal09:11:35

@kah0ona If you use a reg-event-fx you can use :dispatch-n

kah0ona09:11:42

aah dispatch-n

kah0ona09:11:49

didn’t know about that (or forgot about it:-))

curlyfry19:11:55

Hmm, I find this question a bit hard to answer without more code. I think I need to see the actual subscriptions (and maybe components) in order to understand it properly. However, https://github.com/Day8/re-frame-trace is pretty nice for measuring performance of you subscriptions and event handlers.

mikethompson23:11:07

What kinds of performance considerations you are concerned about? I'm only seeing a couple of map lookups -- all seems pretty benign.

borkdude10:11:50

@mikethompson Are you saying a subscription the entire db isn’t that ‘wrong’ if all it involves is a map lookup? That’s what I wanted to know, because I would only refactor this if it really mattered for performance.

borkdude10:11:16

@U0J30HBRS Going to check out re-frame-trace, thanks

mikethompson10:11:52

@U04V15CAJ any subscription which depends directly on app-db will rerun every time app-db changes. So make them trivial. Map lookups are trivial.

mikethompson10:11:48

@U04V15CAJ if you use the latest version of re-frame-trace you'll ALSO have to be using re-frame v0.10.3-alpha1

borkdude10:11:08

@mikethompson Another consideration would be how often a subscription would run. If I can refactor the structure of the db so that the subscription will run less often, this will be better I guess. But if it’s worth it, I can check with re-frame-trace.

borkdude10:11:06

E.g. in my Stackoverflow question, if I would move the routes to [:widget/base :routes] each page would have a subscription on [:widget/base :routes page-id] and the wrapping widget would have a subscription on [:widget/base :routes cur-page-id], avoiding subscriptions on the entire db

borkdude10:11:47

@mikethompson What happens when the db changes? The entire state has to be compared to the previous state. Is this a cheap operation?

mikethompson10:11:52

No, you misunderstand the process

borkdude10:11:15

I mean within a subscription

mikethompson10:11:16

The Layer 2 subscriptions WILl run each time app-db changes.

mikethompson10:11:32

No question. They will run. So we make them trivial

mikethompson10:11:04

If the values they extract (from app-db) test =` to "last time", then no further propogation though the signal graph will occur

mikethompson10:11:00

So all Layer 2 subscription will run when app-db changes in any way.

mikethompson10:11:12

But we put serious computation in layer 3

mikethompson10:11:39

And layer 3 subsciptions never run unless the value of their (layer 2) input signals change.

borkdude11:11:23

Ah, so layer 2 subscription will always run. That makes sense, because the db will have changed anyway. But they select a subtree of the db that are used in level 3 and this has to be compared to the previous selection. Which can still be a quite large map.

mikethompson11:11:07

Although = is used to test if "this time" is the same as "last time", you'll note that the implementation of = shortcuts of the two are identical?

mikethompson11:11:22

Making the = test trivial

mikethompson11:11:00

So the rules are simple: 1. make layer 2 subscriptions trivial extractors. 2. Realise that layer 2 subscriptions run every time app-db changes 3. know that "propogation" of values through the signal graph will stop the moment that a value tests = to last time (ie. nothing has changed). 4. Know that an = test is shortcut to true when its two operands are identical?. So if "this time" is identical? to "last time", the test to stop propagation is really fast.

mikethompson11:11:16

Are we there :-)

borkdude11:11:15

@mikethompson One more question: who triggers the subscriptions. Is it level 2 saying: my content changed, so I trigger who are subscribed to me? If that is true, they must check themselves against their previous state, no?

borkdude11:11:27

This can still be cheap because if identical?, just wondering

mikethompson11:11:05

If the input signals (subscriptions) are the same as last time, a node doesn't recalculate. A "node" can be either a layer in the signal graph OR the eventual view fucntion.

mikethompson11:11:28

its all more than efficient enough.

borkdude11:11:18

Thanks for the patience 🙂

borkdude20:11:56

I installed re-frame-trace and all subscriptions show 0.0-0.2 ms. Guess it’s fine.

borkdude20:11:54

@mikethompson We’re stuck at D3 3.5 but it still seems to work with that 🙂

danielcompton21:11:01

re-frame trace 0.1.13 is out with a new subscriptions panel. https://github.com/Day8/re-frame-trace/releases/tag/0.1.13. Note that you'll need to update to re-frame 0.10.3-alpha1 to make the best use of the subscriptions panel

mikerod21:11:21

This looks nice. I’m going to have to check it out

mikerod21:11:48

I wonder what the behavior is on dynamic subs (I believe that is the terms for a sub that takes args?)

danielcompton23:11:09

@mikerod dynamic subs are subscriptions that take reactions as parameters. They're not really recommended anymore as there are better ways of doing it with subscription dependencies

danielcompton23:11:21

They will work, but might have slightly unusual behaviour

mikerod23:11:23

Ok, wrong word

mikerod23:11:00

@danielcompton I meant

(rf/reg-sub :my/thing
(fn [db [_ x y]]
   (do-something db x y)))

mikethompson23:11:43

@mikerod that's a pretty standard kind of subscription and it will be displayed just fine.

mikerod23:11:21

@mikethompson I’ll have to mess around with it to see

mikerod23:11:26

Sounds cool though

mikethompson23:11:45

It is WIP but it does work well enough.

mikerod23:11:42

Is the plan to overthrow re-frisk ? 😛

mikerod23:11:57

or compliment or just be an alternative

mikethompson23:11:50

Alternative. We've already had a few goes at this space, including Abra, an approach based on clairvoyant, debug interceptors, etc. We're still experimenting and scratching various itches. :-)

mikerod23:11:22

sounds good