Fork me on GitHub
#re-frame
<
2019-01-11
>
oliy09:01:34

martian lets you have global and route-specific interceptors, and has re-frame bindings https://github.com/oliyh/martian/tree/master/re-frame @hoopes

victorb11:01:44

is the handler in rf/reg-event-fx only called if it's actually doing a change? Or maybe it's the panel from re-frame-10x that doesn't show events that doesn't actually change the state

curlyfry13:01:21

@victorbjelkholm429 No, it'll always be called. Should show up in 10x as well, just tried it with an event that just returns nil.

hoopes13:01:46

@oliy do you know of any way to have more than one instance of martian within re-frame? the code looks like it holds the martian object under ::martian :m (i've seen this pattern elsewhere too - i was hoping to have more than one API that i'm talking to)

oliy14:01:52

not using martian-re-frame as it is

oliy14:01:36

i used to have a similar pattern going in re-graph but re-graph now supports multiple named instances

Jacob Haag15:01:17

Has anybody else been having issues with calling a subscription from the Clojure repl (see below) -- Clojurescript --

cljs.user=> (require '[slm.components.typeahead.subscriptions :as subscriptions])
nil
cljs.user=> (require '[re-frame.core :as re-frame])
nil
cljs.user=> (re-frame/subscribe [::subscriptions/typeahead])
#<Reaction 42: {:query "a", :suggestions {:loading? true}}>
cljs.user=>
` -- Clojure --
user=> (require '[slm.components.typeahead.subscriptions :as subscriptions])
nil
user=> (require '[re-frame.core :as re-frame])
nil
user=> (re-frame/subscribe [::subscriptions/typeahead])

user=> Execution error (ArityException) at re-frame.subs/reg-sub$subs-handler-fn (subs.cljc:325).
Wrong number of args (1) passed to: slm.components.typeahead.subscriptions/eval47498/fn--47499

escherize16:01:49

Hi @jacobhaag17! I would bet you that your subscription function doesn't take 2 arguments

escherize16:01:33

because cljs, like js is permissive of calling functions with the wrong number of arguments (naughty js), but clojure (like java) doesn't allow that

escherize16:01:33

so perhaps somewhere reframe is calling

(your-subscription-function-that-takes-one-arg db [::subscriptions/typeahead])
which works fine in JS but not Java.

Jacob Haag16:01:30

@U051GFP2V So with the jvm it's trying to send an additional paramater?

escherize16:01:47

no, it's sending aditional parameter in both

escherize16:01:55

but the cljs function ignores extra args

escherize16:01:04

because js is uh "smart" that way ya know?

Jacob Haag16:01:55

Ah I see, so now we know the cause, do we know how to resolve this issue for the jvm? @U051GFP2V

Jacob Haag18:01:18

Here is what the subscriptions look like

(re-frame/reg-sub
 ::suggestions
 (fn [db [_ query]]
   (get-in db [:typeahead :suggestions])))

(re-frame/reg-sub
 ::query
 (fn [db [_ query]]
   (get-in db [:typeahead :query])))

(re-frame/reg-sub
 ::typeahead
 (fn []
   [(re-frame/subscribe [::query])
    (re-frame/subscribe [::suggestions])])
 (fn [[query suggestions]]
   {:query query
    :suggestions suggestions}))

Jacob Haag18:01:42

Calling (re-frame/subscribe [::query]) works fine

escherize18:01:21

that's because the registrered function for ::query takes 2 args

escherize18:01:30

the registered function for typeahead only takes 1 arg. *

escherize18:01:39

but it needs to take 2

escherize18:01:52

(fn [[query suggestions]]
->
(fn [[query suggestions] _]

escherize18:01:38

does that make sense?

Jacob Haag18:01:30

It does, but for some reason now I get the error "Wrong number of args (2) passed to: slm.components.typeahead.subscriptions/eval29377/fn--29381" when I change the subscription too

(re-frame/reg-sub
 ::typeahead
 (fn []
   [(re-frame/subscribe [::query])
    (re-frame/subscribe [::suggestions])])
 (fn [[query suggestions] _]
   {:query query
    :suggestions suggestions}))

thegeez19:01:56

this page shows the (fn [] .. after ::typeahead also takes two arguments: https://github.com/Day8/re-frame/blob/master/docs/SubscriptionFlow.md#example-reg-sub-raw

Jacob Haag20:01:18

@U06D9RGQM would you have any recommendations for how to call the subscription?

thegeez21:01:15

Calling the subscription like this should work like it is right now: (re-frame/subscribe [::subscriptions/typeahead]) but change

(re-frame/reg-sub
  ::typeahead
  (fn []
     [(re-frame/subscribe [::query])
      (re-frame/subscribe [::suggestions])])
  (fn [[query suggestions] _]
    {:query query
     :suggestions suggestions}))
to
(re-frame/reg-sub
  ::typeahead
  (fn [_query-v-ignored _second-arg-ignored]
    [(re-frame/subscribe [::query])
     (re-frame/subscribe [::suggestions])])
  (fn [[query suggestions] _]
    {:query query
     :suggestions suggestions}))

Jacob Haag21:01:31

Unfortunately already tried that and still get the same error Wrong number of args (1) passed to: slm.components.typeahead.subscriptions/eval27593/fn--27594 @U06D9RGQM

Whiskas16:01:02

is it possible to pause execution at every event on re-frame?

Whiskas16:01:16

like, going through them step by step?

Whiskas16:01:34

or to console log which event is being handled

lilactown16:01:37

@mateus.pimentel.w I know there is a popular tool called re-frame-10x which gives you advanced logging and inspection of events

lilactown16:01:45

I haven't used it but it might be worth checking out

Whiskas16:01:49

i mean, i use re-frame-10x

Whiskas16:01:17

but i wanted to see they printed on console too to see in which event a particular javascript error ocurred

escherize19:01:10

@mateus.pimentel.w you could make something like the debug intercepter but that would just print the event vector

escherize19:01:08

but you would have to put the intercepter into any of the events where you cared about the logging

Whiskas20:01:05

I think i will do some low level stuff and inject code into some of the re-frame functions at run time

Whiskas20:01:27

Since it's only a thing i will use at development

mikethompson21:01:56

@mateus.pimentel.w the debug interceptor does exactly what you want I think

mikethompson21:01:25

And it can be easily left out of production builds