This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2017-12-09
Channels
- # adventofcode (201)
- # bangalore-clj (5)
- # beginners (90)
- # cider (1)
- # cljs-dev (3)
- # cljsrn (28)
- # clojure (128)
- # clojure-argentina (1)
- # clojure-brasil (15)
- # clojure-dev (9)
- # clojure-greece (18)
- # clojure-italy (11)
- # clojure-madison (1)
- # clojure-poland (19)
- # clojure-russia (28)
- # clojure-spec (33)
- # clojure-uk (26)
- # clojurescript (20)
- # core-async (2)
- # cursive (1)
- # datomic (2)
- # emacs (4)
- # figwheel (3)
- # fulcro (15)
- # graphql (7)
- # hoplon (1)
- # lein-figwheel (2)
- # lumo (2)
- # numerical-computing (3)
- # off-topic (9)
- # re-frame (13)
- # ring (1)
- # shadow-cljs (1)
- # unrepl (1)
- # vim (17)
When testing a re-frame app, I'd like to intercept my login event to do a different event which creates a test user and logs in. I haven't found any existing docs in re-frame or re-frame-test for mocking or intercepting in this way (i.e. not re-frame interceptors). Any pointers?
Guys, is there something wrong about using subscriptions inside subscriptions. Or is there performance difference between those 2 constructs?
(reg-sub
:some-sub
(fn [db [_ param]]
(= 1 @(subscribe [:other-sub param]))))
(reg-sub
:some-sub
(fn [[_ param]]
[(subscribe [:other-sub param])])
(fn [[result]]
(= 1 result)))
@madvas why not use the other form of reg-sub using the :<-
There's an example in reframe todomvc
You can pass a second fn to reg-sub to calculate the param
(reg-sub :visible-todos ;; Signal Function ;; Tells us what inputs flow into this node. ;; Returns a vector of two input signals (in this case) (fn [query-v _] [(subscribe [:todos]) (subscribe [:showing])]) ;; Computation Function (fn [[todos showing] _] ;; that 1st parameter is a 2-vector of values (let [filter-fn (case showing :active (complement :done) :done :done :all identity)] (filter filter-fn todos))))
The signal function calculate the subscription
@madvas I don't think that's anything wrong with it in terms of the behavior. If you look at the code for reg-sub
, you'll see that input signals that Hendrik described are handled just like that - they're dereferenced and passed to the computation fn.
But the explicit inclusion of subscriptions in the computation fn has a couple of problems. The first one, it's less composable. The second one, if you forget to dereference a subscription, there will be leak.
Say you’d like to do an http post when someone clicks a button. Is it more idiomatic to a) execute the post in the on-click, and post and dispatch an event when the response is received, or b) dispatch a ‘clicked-button’ event, which has an event handler that triggers an effect handler that executes the post?
@brycecovert Definitely (b).
@p-himik Thanks. I suspected so. 🙂