Fork me on GitHub
#re-frame
<
2017-05-17
>
fabrao01:05:26

Hello all, how do I encode application/x-www-form-urlencoded for

(re-frame/reg-event-fx
  ::http-post
  (fn [_world [_ val]]
    {:http-xhrio {:method          :post
                  :uri             ""
                  :params          data
                  :timeout         5000
                  :format          (ajax/json-request-format)
                  :response-format (ajax/json-response-format {:keywords? true})
                  :on-success      [::good-post-result]
                  :on-failure      [::bad-post-result]}}))

fabrao01:05:21

In params? I tried some like :params {:username username :password password} but it not encode

bradleesand02:05:02

I'm guessing you should use :format (ajax/url-request-format)

bradleesand02:05:30

I haven't done it myself but that's what I would try

sashton02:05:08

are there any examples of writing clj tests when using the jvm interop functions? like testing a subscription function, or testing an event handler which has some interceptors.

sashton02:05:20

or would you instead write your code like this:

(defn name-fn [db _ _]
  (:name db))
(rf/reg-sub :name name-fn)
And just test name-fn directly, skipping the re-frame part of things.

bradleesand16:05:24

sashton: This is how I do

sashton17:05:43

thanks @U0V9BJR9V. How do you test handlers which have interceptors? Do your tests just pass data to you function in a form that matches what the interceptors would have done?

sashton17:05:46

(defn some-id-fn [db v]
  ...)
(reg-event-db          
   :some-id
   [add-some-token]        
   some-id-fn))
In this case, I could test some-id-fn separately, but my test would have to format the input data in a way that matches what add-some-token does.

bradleesand17:05:45

right exactly

sashton17:05:33

In a way, that keeps the test focused on just what some-id-fn is responsible for. But on the other hand, it means I could forget to add an interceptor, or an interceptor could change and it wouldn’t get caught in my test

bradleesand17:05:40

it's unfortunate that we don't get full coverage with this method but the unit tests are pretty simple to set up since you're just testing functions

cmal02:05:02

re-frame-http-fx http_fx.cljs line 26 , can you open the url ? I found this is a 404.

cmal02:05:12

Does that mean this one: ?

chpill13:05:59

Hi guys, I made of fork of re-frame to try to port its goodness to new lands (aka rum) and without global state https://github.com/chpill/re-frankenstein

chpill13:05:18

It should be completetely backward compatible with re-frame

chpill13:05:56

Feedback wanted 🙂

souenzzo14:05:09

I like explicit db

antonmos17:05:14

hi! is there a way to register a global interceptor? i’d like to display a friendly error message when errors like this happen “re-frame: no :fx handler registered for:”

bradleesand18:05:24

I have a standard-middlewares that is a collection of interceptors I include for every event handler I register

bradleesand18:05:42

I don't know if there's a way to register middleware globally

antonmos19:05:22

gotcha, thanks. I also looked at the source, and, sadly, I dont see a way to detect that a handler is not registered… it looks like it only goes to console 😞

antonmos21:05:20

@jfntn that’s what i skimmed - is there a particular line i should look at?

jfntn21:05:48

get-handler

jfntn21:05:07

The only trick is they’re grouped by kind so if you don’t know that in advance you’ll have to try every kind/id combination

antonmos21:05:03

oh i see. that’s a bit different from what I was trying to do. I wanted a runtime error/event/notification if the code tries to dispatch an event that is not registered.

chpill22:05:21

Yes, I did! In fact, I did not plan to fork re-frame at first. I was just discussing with the creator of scrum about some of the design decisions in both libraries. I ended up digging so deep into re-frame that I kind of saw a way to reuse most of re-frame without using the global state. And use rum on top 🙂

danielcompton22:05:51

@chpill I took a quick look, and expected to see the frank passed around the app as the state container, but it doesn’t seem like that's how it works?

kauko06:05:54

danielcompton: Did you notice the with-frank mixin?

chpill07:05:30

@U051KLSJF There are several tricks. For the views, @U0EM88XL7 is right, they can access frank via the react context (thanks to the with-frank mixin.

chpill07:05:44

For the handlers, it is a bit more subtle

chpill07:05:43

basically, users still continue to use the classic registering mechanism like reg-event-db, but when you do (frank/create) it derefs the value of the handler registry, and replace the handlers and interceptors that affect global state with some that affect only the freshly created local-db

chpill08:05:17

Oh I forgot to mention, indeed, the root mixin that injects frank into the context also injects partially applied dispatch functions https://github.com/chpill/re-frankenstein/blob/2e36ed5a19370a890f795ecb96ae9e03807a65cb/src/re_frame/rum.cljs#L45-L46

chpill08:05:24

The views use those partially applied dispatch, that's why you don't see frank as argument in there (but in fact it is)

frank22:05:52

thanks for the mention, slack