Fork me on GitHub
#re-frame
<
2019-08-01
>
tianshu02:08:49

sometimes hot-reload a bad code may break the render. is it possible to recovery the UI without reload the browser.

tianshu07:08:55

Can I dispatch a single fx in re-frame?

Ahmed Hassan08:08:02

Single fx means?

tianshu09:08:23

I mean just like I can dispatch an event, can I dispatch a fx?

tianshu09:08:04

(reg-fx :foo (fn ...))

(re-frame/dispatch [:foo])
This won't work, because fx is not event.

oconn09:08:40

I typically create two registrations reg-event-fx :foo and reg-fx :foo where the first triggers the second. Another thing you can do is create the var foo-fx and then bind that function to reg-fx :foo - you can then invoke it as a regular function where it makes sense (probably within a lifecycle method?). I would go with the first approach though and keep it 100% within re-frame.

tianshu09:08:12

I get it. thanks for the explain.👍

tianshu09:08:21

May I ask one more question:joy: Can I have some async flow in the cofx. The case is, assuming there's a AsyncStorage, I want use inject-cofx to get a item, inject the item to cofx then dispatch the event. Is it possible or am I on the wrong way?

tianshu12:08:27

yes, I can use localstorage like this, but in React Native, the storage has an async API. it can't be used like this.

tianshu12:08:44

The value will be available in a callback.

tianshu12:08:45

I know how to do this with a chain like event -> fx -> event. But what if use cofx injection?

romain14:08:44

Holà! I use re-frame-http-fx to perform a POST request. I just send a string in the body. The request is "OK", I got a status 200, but also an error (JSON.parse: unexpected keyword at line 1 column 1 of the JSON data Format should have been JSON keywordize). So the request goes for :on-failure and not :on-success whereas it is executed and the API consumed the string. Can I fix it without touching the code from API ?

scknkkrer14:08:02

It means: your request performed well. But your payload doesn’t parsed to JSON.

scknkkrer14:08:25

Are you sure about that your payload is a valid JSON string ?

romain14:08:04

@scknkkrer well, I implemented the POST request from a colleague's postman collection. And the body is just a string

scknkkrer14:08:58

Can you send an example output from the Request you are trying to do ? Explicitly, in code tags ?

scknkkrer14:08:36

Like:

javascript
example payload!

scknkkrer14:08:44

Is this a valid JSON string?

romain14:08:25

I don't think so, it should be "", I may have to parse it in :body ?

scknkkrer14:08:08

Yeah, maybe you can. I don’t know the details about re-frame-http-fx. You can solve your issue with wrapping it by quotes, before you parse it as JSON. Sorry, I can’t help with the implementation details. But; I’ve written a library called Suluk for this. Fetch API wrapper for Clojurescript. You can quickly look at it’s documentation. https://github.com/LeaveNhA/suluk

romain14:08:49

Oh yes I saw your lib few days ago 🙂

scknkkrer14:08:02

If you have a feed-back, throw me! 😂

romain14:08:06

I'll try to give a look at it anytime soon 🙂

scknkkrer17:08:19

I’m waiting for your feed-back, @U050PEFK2.

kstehn14:08:54

you can define the response-format that you expect and just use ajax/text-response-format

4
romain14:08:30

Oh yes you're right! Why would I expect a json response whereas I expect nothing 😛

romain19:08:16

I read FAQ about inject-sub but it's 2017 dated. Any new stuff since?

James Acklin21:08:45

Is there a good pattern (or even example) on how to wrap a subscription within another subscription?

jahson22:08:47

You could use one subscription's data inside another — is that what you're looking for? Like https://github.com/Day8/re-frame/blob/ce4c580dfc24e120b932f4aebf000a85b426543e/examples/todomvc/src/todomvc/subs.cljs#L49-L52