Fork me on GitHub
#re-frame
<
2017-10-06
>
colbydehart00:10:26

Ahhh ahh okay. That makes sense.

colbydehart00:10:24

Nope, actually that wasn’t the problem, you can run the handler on figwheel, the problem is that I had the uri wrong. I should have had "/api/v1" instead of "/api/v1"

rgm01:10:58

I'm struggling a bit with a long initial load time and I'm hoping someone can point me to the right place in the docs for managing this... in my [:initialize-db] I'm kicking off an xhr effect to pull down a 60,000 line CSV file with all my data. The parse (in my xhr success handler) seems to take about 5-6 sec and blocks the event loop.

rgm01:10:52

what's the usual way to get that as off the single thread as one can in JS? ... I gave core.async a go but it's quite probable I'm not using it right.

danielcompton02:10:43

You can also look at running a web worker to do the processing. I don't think that is a very well trodden path in ClojureScript though, and getting the data back over the serialisation boundary might be tricky

danielcompton02:10:19

@rgm also you could take a look at storing the data as JSON or transit, as they are probably faster to deserialise

rgm02:10:28

So it seems like a batching approach is called for in the CPU hog article.

rgm02:10:33

Oh good point

rgm02:10:07

I’m not quite grokking how spinning off a coeffect would avoid locking up CPU.

danielcompton02:10:11

Thousands of hours have gone into browser's parsing JSON fast

danielcompton02:10:21

I don't think coeffects would avoid CPU lock, but it would be more idiomatic to do the parsing work in an effect handler, rather than in the xhr success callback

rgm02:10:40

I have full control over the data; JSON/transit will be the biggest gain at least complexity <smacks own forehead>.

rgm02:10:41

But yeah, I guess next is to push off the parse as a coeffect and after that deal with chunking it up.

rgm02:10:48

Thanks again.

danielcompton02:10:40

no problem, also Transit lets you parse a stream of values, whereas standard JSON needs to read the whole object in one go

danielcompton02:10:25

So you could chunk Transit it on the server side, and parse a chunk at a time

lovuikeng02:10:58

sorry, @rgm, thought you'd like to do something else while processing the bulk 😞

rgm02:10:30

No worries. Appreciate the pointer.

lovuikeng02:10:51

you might want to go crazy with cljsjs/oboe for JON Streaming http://oboejs.com/

lovuikeng02:10:47

not sue if there is clojure backend to spit out the streaming though

lovuikeng02:10:14

got the idea from Spring WebFlux

rgm03:10:11

Also generally the re-frame docs are amazing and I want to thank @mikethompson @danielcompton and everyone else involved a whole ton.

lovuikeng03:10:28

you don't say, @rgm re-frame makes Web development fun again 🙂

rgm03:10:59

Dang, the 7-8 sec CSV parse is now < 1s using JSON Transit.

rgm03:10:48

gzipped size of the CSV and Transit are both around 350kb.

rgm03:10:35

And of course being Clojure pipeline-y code there was only one function to rewrite in the spreadsheet "juicer" that I made to produce the data files from a giant Excel hairball of engineering data.

rgm04:10:38

honestly the best part of being just past the steepest part of the Clojure learning curve is that I learn about something new (eg. Transit), start using it and it's just like Christmas happening about every 36 hours.

rgm04:10:01

@lovuikeng completely, utterly agree... I have one client project I've been working on since 2014 for which they chose Meteor and this is better in just so many ways. The despair is gone.

lovuikeng05:10:55

it'd be even more fun if re-template include profiles of duct (for backend) and semantic-ui-react (for UI) 🙂

rgm13:10:27

@lovuikeng just to close the thought on the parser, am I understanding right that the more correct approach on a parse would be to stick it into the :after of an interceptor? It seems to be related to coeffects but I was having trouble grokking how a parse (being in response to receiving data) would fit into coeffects, which seem to be a before kind of thing.

rgm13:10:26

And now I see that coeffects seem to be :before interceptors, which is slick.

rgm14:10:01

I guess the alternative is to register a parse effect and put that in the effect map.

rgm14:10:24

Maybe that’s less magical.

lovuikeng14:10:53

@kennethkalmer brings up tips on "Layer 3 computations", might something to look into https://opensourcery.co.za/2017/02/12/using-semantic-ui-react-with-re-frame/

kasuko14:10:35

@lovuikeng @kennethkalmer I’d also check out Soda-Ash which is a wrapper around semantic-ui-react so you basically get all the Reagent components of semantic-ui-react for free. https://github.com/gadfly361/soda-ash

kasuko15:10:23

and if you want to go further down the rabbit hole there is sodium which is a wrapper around soda-ash to provide validations and useful re-frame functions 😝 https://github.com/deg/sodium

kasuko15:10:41

I have used soda-ash personally quite extensively but have never used sodium

kennethkalmer15:10:26

funny enough, the reworked soda-ash version came out within hours of that blog post, total coincidence

kennethkalmer15:10:36

or the other way around, can’t remember exactly

kennethkalmer15:10:09

thanks for the tip on sodium though, forms & re-frame & myself aren’t the best of friends yet

lovuikeng15:10:44

Yes, I've checked out both too, @kasuko Only that I'm still trying to get around re-frame, and @kennethkalmer tips is simply great for working with react components like the fantastic semantic-ui 🙂 And I tend to like a simple wrapper which still stick to re-frame subs/dispatch API

kasuko15:10:31

soda-ash works great with re-frame subs/dispatch. You just don’t have to write that component wrapper yourself