This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2017-12-20
Channels
- # adventofcode (140)
- # beginners (107)
- # boot (120)
- # boot-dev (1)
- # clara (13)
- # cljs-dev (9)
- # clojure (107)
- # clojure-argentina (5)
- # clojure-art (16)
- # clojure-dev (23)
- # clojure-greece (19)
- # clojure-italy (5)
- # clojure-russia (2)
- # clojure-serbia (3)
- # clojure-spec (27)
- # clojure-sweden (1)
- # clojure-uk (15)
- # clojurescript (134)
- # cursive (5)
- # data-science (10)
- # datomic (23)
- # duct (28)
- # fulcro (48)
- # garden (5)
- # hoplon (2)
- # instaparse (1)
- # klipse (7)
- # leiningen (8)
- # lumo (36)
- # off-topic (72)
- # om (4)
- # onyx (37)
- # perun (4)
- # re-frame (64)
- # reagent (86)
- # remote-jobs (1)
- # shadow-cljs (59)
- # spacemacs (16)
- # sql (1)
- # uncomplicate (6)
- # unrepl (90)
Does anyone know how to get response-headers from http-xhrio?
@lachlan737 check the issues, I think that might be there as one
Yeah it is, was just wondering if anyone knew of any workarounds
There's an open issue for it https://github.com/Day8/re-frame/pull/413
I love it when I get errors like
react-with-addons.inc.js:14783 Uncaught TypeError: Cannot read property 'getHostNode' of null
at Object.getHostNode (VM11514 react-with-addons.inc.js:14783)
at ReactCompositeComponentWrapper.getHostNode (VM11514 react-with-addons.inc.js:6618)
at Object.getHostNode (VM11514 react-with-addons.inc.js:14783)
at Object.updateChildren (VM11514 react-with-addons.inc.js:4611)
at ReactDOMComponent._reconcilerUpdateChildren (VM11514 react-with-addons.inc.js:12997)
at ReactDOMComponent._updateChildren (VM11514 react-with-addons.inc.js:13101)
at ReactDOMComponent.updateChildren (VM11514 react-with-addons.inc.js:13088)
at ReactDOMComponent._updateDOMChildren (VM11514 react-with-addons.inc.js:8251)
at ReactDOMComponent.updateComponent (VM11514 react-with-addons.inc.js:8069)
at ReactDOMComponent.receiveComponent (VM11514 react-with-addons.inc.js:8027)
in the consoleFor me a manual reload often helps. Somehow it seems the react/dom state gets into a strange place.
ah well I get this doing a page reload
if instead I change something and I get figwheel doing the magic
it works
which is even more weird, but something messed up in the db initialisation maybe
It took me a while (read: weeks) to realize I can also sometimes scroll all the way to the right in the console to see more info. Not always useful but sometimes it helps.
there is some extra information about the failure related to some internal re-frame stuff
but it doesn't help much either š
any debugging tip?
@vinai I solved it in my project, will get the code for you
@vinai https://github.com/JoelSanchez/ventas/blob/master/src/cljs/ventas/core.cljs#L29
It beats filtering all warnings in the console output. Will use it until the PR from Daniel Compton gets merged š
Yes, it's a hack. Yes, it's awful. But it works, and it's reliable š
anyone using re-frame.test ?
I get quite wildly results if running with test-cljs
or by doing cljs-test.run-tests
from the repl
when using a signal-fn like here
(fn [query-vec dynamic-vec]
[(subscribe [:a-sub])
(subscribe [:b-sub])])
or using the syntax sugar :<-
, is it possible and a good idea to pass result of previous signal into the next ? like
:<- [:a]
:<- [:b a]
(fn [[useless-a? b] _]
@jvuillermet ...where a
would be the value of [:a]
?
This might work?
(fn [query-vec dynamic-vec]
[(subscribe [:b-sub @(subscribe [:a-sub])])])
Probably it's better to move it into a regular function and call it from the signal-fns
would be great to be able to visualize all the various dependencies between subs and events
since they are all data it should be possible, anyone tried that?
and any idea what this means re-frame: no :fx handler registered for: :http-xhrio
?
@andrea.crotti you are probably missing [day8.re-frame.http-fx]
in :require
this will register the effect you need
uhm odd it's not there in master either though
and don't get that error there
that does fixes it though, weird
@jvuillermet @vinai in that sort of case, I ended up using reg-sub-raw
since I thought it was less dirty than doing it in the signal fn (not sure if that is the appropriate use)
(rf/reg-sub-raw
:do-it
(fn [_ _]
(r/reaction
(let [a @(subscribe [:a-sub])
b @(subscribe [:b-sub])]
(do-it a b)))))
Iām looking at the impl for the signal-fn in reg-sub
and Iām now a bit doubtful that it is safe to deref subscriptions in it
Basically, itās this:
([db query-vec]
(let [subscriptions (inputs-fn query-vec)
reaction-id (atom nil)
reaction (make-reaction
(fn []
(trace/with-trace {:operation (first-in-vector query-vec)
:op-type :sub/run
:tags {:query-v query-vec
:reaction @reaction-id}}
(let [subscription (computation-fn (deref-input-signals subscriptions query-id) query-vec)]
(trace/merge-trace! {:tags {:value subscription}})
subscription))))]
(reset! reaction-id (reagent-id reaction))
reaction))
* subscriptions (inputs-fn query-vec)
- runs the signal fn
* The reaction
is created later that wraps over that resulting value. So your derefās have already happened and wonāt be done within a reactive context. So they wonāt respond correctly to changeBoth solutions seems complicated and hard to read to me. It feels that if one start going that road, you will end up with event more complex sub
and signal-fn
. At some point I guess itās better to have a simple fn that do that by taking the whole db or some part
@jvuillermet taking the whole db may be fine. Can also lead to unnecessary recomputing though potentially
Also, I have done this pattern you describe due to other subscription doing significant āmaterialized viewā work that I wanted to reuse
Itās the first case I encounter since a while where I needed that
Do you need it more frequently ?
However, I agree that it isnāt necessarily great and probably isnāt something youād like to see a ton of
Iāve needed it quite a bit in one current case where I have a lot of configuration driving the UI in terms of which components are shown and their properties. I just end up having to use āidā sort of indexing into most subscriptions
so when most subscriptions need an āidā you have to pass the āidā along if you have subscriptions using other subscriptions
well, I guess that is not the case you describe, we are talking about needing the return value of a subscription as an input to another. Iāve had that happen when my āidā isnāt explicitly passed in, but rather derivedā¦ Too abstract. This probably doesnāt make any sense to someone reading.
Letās say it this way: Probably most of the time you shouldnāt need reg-sub-raw
. However, it exists and is described fairly well @ https://github.com/Day8/re-frame/blob/master/docs/SubscriptionFlow.md
So Iām guessing it comes up in practice for people.
š
I think I get it. In my case, a blog can be edited or not based on user type, user-email and some blog props so the ::can-edit?
sub take 4 params. When I want to use this sub, I often already have sub for user-type
that would be nice to pass to the can-edit?
You could push the problem to the components/views like:
(let [user-type @(subs [:user-type])
can-edit? @(subs [:can-edit? user-type <etc>])] <etc>)
I didnāt like that though, I wanted to be able to not keep pushing intermediary results to the view when the view didnāt need to know
So I ended up just making the :can-edit?
style one look up its own user-type
and that relied on another subscription and thatās where Iād end up at the reg-sub-raw
usage
yes, pretty sure itās the same use case.
@jvuillermet one thing that I considered at one point is just share common logic via functions instead of have these more complex subscriptions rely on one another. However, the problem then becomes in always keeping things in sync. I think it starts to make the leaf subscription extra complicated are hard to manage
So you take all the impl from the subscription into a function for reuse that is independent of the subscription