This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2017-11-22
Channels
- # aws (1)
- # beginners (102)
- # boot (5)
- # cljs-dev (59)
- # cljsjs (1)
- # clojure (154)
- # clojure-australia (1)
- # clojure-brasil (1)
- # clojure-dusseldorf (4)
- # clojure-greece (36)
- # clojure-italy (10)
- # clojure-poland (5)
- # clojure-romania (1)
- # clojure-russia (7)
- # clojure-spec (32)
- # clojure-uk (113)
- # clojure-ukraine (3)
- # clojurescript (107)
- # cursive (13)
- # data-science (25)
- # datomic (23)
- # emacs (3)
- # events (1)
- # fulcro (72)
- # funcool (10)
- # graphql (1)
- # leiningen (1)
- # luminus (2)
- # lumo (38)
- # off-topic (14)
- # onyx (78)
- # planck (4)
- # re-frame (55)
- # reagent (1)
- # ring (3)
- # ring-swagger (2)
- # rum (19)
- # shadow-cljs (89)
- # spacemacs (101)
- # sql (2)
- # unrepl (88)
is it possible to dispatch to multiple other handlers ? ie. {:dispatch [[:handler1] [:handler2]] }
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
@kah0ona If you use a reg-event-fx you can use :dispatch-n
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.
What kinds of performance considerations you are concerned about? I'm only seeing a couple of map lookups -- all seems pretty benign.
@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.
@U0J30HBRS Going to check out re-frame-trace, thanks
@U04V15CAJ any subscription which depends directly on app-db
will rerun every time app-db
changes. So make them trivial. Map lookups are trivial.
@U04V15CAJ if you use the latest version of re-frame-trace
you'll ALSO have to be using re-frame v0.10.3-alpha1
@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
.
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
@mikethompson What happens when the db changes? The entire state has to be compared to the previous state. Is this a cheap operation?
No, you misunderstand the process
The Layer 2 subscriptions WILl run each time app-db
changes.
No question. They will run. So we make them trivial
If the values they extract (from app-db) test
=` to "last time", then no further propogation though the signal graph will occur
So all Layer 2 subscription will run when app-db
changes in any way.
But we put serious computation in layer 3
And layer 3 subsciptions never run unless the value of their (layer 2) input signals change.
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.
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?
Making the =
test trivial
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.
Are we there :-)
@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?
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.
its all more than efficient enough.
@mikethompson We’re stuck at D3 3.5 but it still seems to work with that 🙂
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
I wonder what the behavior is on dynamic subs (I believe that is the terms for a sub that takes args?)
@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
They will work, but might have slightly unusual behaviour
@danielcompton I meant
(rf/reg-sub :my/thing
(fn [db [_ x y]]
(do-something db x y)))
@mikerod that's a pretty standard kind of subscription and it will be displayed just fine.
@mikethompson I’ll have to mess around with it to see
It is WIP but it does work well enough.
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. :-)