Fork me on GitHub
#re-frame
<
2015-12-07
>
mikethompson01:12:12

What toolchain or hosting option should we use for Reagent's docs: https://github.com/reagent-project/reagent/issues/209

escherize01:12:14

It might be too geared toward APIs tho

mikethompson01:12:18

Could you add to ticket, so nothing gets lost and all conversations are contained.

pupeno06:12:13

@mikethompson: I was half expecting nodejs to crash, but not to have a wrong implementation. Are you sure that while waiting for a timeout, events should be processed?

mikethompson06:12:57

Yeah, absolutely sure.

mikethompson06:12:02

Give me a sec, i just want to look at core.async

mikethompson06:12:07

See what it does on Node

pupeno06:12:18

I have a very poor understanding of this non-thread model in js

pupeno07:12:35

@mikethompson: did you find anything useful?

mikethompson07:12:36

Ah, sorry, no. i got distracted by one of those idiot conversations one has every now and again on the internet

mikethompson07:12:47

Back to it now

pupeno07:12:48

Ah… hehe simple_smile

pupeno07:12:53

It happens.

mikethompson07:12:13

The idiot being me for getting involved

pupeno07:12:58

I suppose dispatch/queue-delay is the critical bit?

mikethompson07:12:54

Yeah, and it looks like the dispatch releated code uses goog.async.nextTick and js/setTimeout https://github.com/clojure/core.async/blob/master/src/main/clojure/cljs/core/async/impl/dispatch.cljs

pupeno07:12:34

That means that the problem is in my code and not core.async, correct?

mikethompson07:12:47

Yeah, I'm thinking that.

pupeno07:12:30

My code looks like this:

pupeno07:12:34

(go-loop []
            (timeout event-timeout)
            (if (> (- (.getTime (js/Date.)) start-time) total-timeout)
              (do (println "Done pre-rendering at    " (- (.getTime (js/Date.)) start-time))
                  (.send res (reagent/render-to-string [views/main-panel])))
              (do (println "Not done yet             " (- (.getTime (js/Date.)) start-time))
                  (router/-run-queue router/event-queue)
                  (recur))))

pupeno07:12:08

I suppose instead of just

recur
ring, I should try to give control back to re-frame.

mikethompson07:12:33

I'm sorry to do this ... but I have to go to dinner

pupeno07:12:40

bon apettite!

mikethompson08:12:07

@pupeno: in that code above, shouldn't it be (<! (timeout event-timeout))

dm311:12:19

@pupeno, how do you watch these? I'm logged in but it says > Because of its privacy settings, this video cannot be played here.

mccraigmccraig11:12:11

@dm3: i logged in and am viewing... didn't have to do anything special - are there perhaps geo-restrictions or something ?

pupeno11:12:48

dm3: it just worked for me, where are you based?

dm311:12:06

switzerland

pupeno11:12:28

I wonder if that’s an issue. I would reach to skillsmatter, they are very responsive.

mikethompson13:12:35

Dear all, I've written up a page on using stateful JS components from within Reagent/Re-frame: https://github.com/Day8/re-frame/wiki/Using-Stateful-JS-Components It is a very green document. Almost certainly has typos. Any feedback about content appreciated

henryw37416:12:50

@mikethompson: I think the doc is useful. Afaik this stuff is only documented by example in the Reagent cookbook. On a related note, what does seem a bit lacking in Reagent docs generally is a discussion of props and how to use them, how they differ from just normal args passed to a subcomponent etc. for example this page https://github.com/Day8/re-frame/wiki/Creating-Reagent-Components explains the forms, but does not mention how you would pass args to a form-3 such that *-mount fns could use them, whether props or otherwise.

underplank17:12:21

Hey I asked this over on #C03S1L9DN, when I didnt realise there is a #ref-frame channel

underplank17:12:24

I’ve been looking at re-frame for a SPA. I really like the event driven pipeline, but would prefer to just use type-1 reagent components, instead of type-2 and the reactions etc. Is there a really good reason I couldnt just use the type-1 components?

henryw37417:12:06

this page explains it pretty well: https://github.com/Day8/re-frame/wiki/Creating-Reagent-Components in short, if you need setup, local state etc then you need more than form-1

jstew18:12:13

The question you would have to ask yourself is how would you re-render when state changes? Sure, you can just use form-1 components, but at some point you'll have to react to state changes

underplank19:12:36

@jstew: but cant you already do that by just using normal reagent? ie passing the atom around which registers the components. I guess what I want to know is the reasoning behind using the form-2 over the form-1, and the tradeoffs.

underplank19:12:19

I get the local state part of form-2. But I dont think I undestand the full reasons behind why re-frame suggests to use them all the time.

mikethompson19:12:42

We want any subscription to be created once. The stream of values it produces should trigger many rerenders over time. If you go with Form-1 then the subscription will be recreated each time you rerender.

underplank19:12:20

Ah. And if we want to use subscriptions, then we want to do that. ok.

underplank19:12:16

And is the reason to use subscriptions to abstract away the structure of the atom data store? ie the way re-frame chooses to do the equivalent of Om.Nexts static query function?

mikethompson19:12:17

Yeah, there is a description of the dream situation here: https://github.com/Day8/re-frame#subscribe

underplank19:12:20

ahh righto, that makes sense. Next question. Testing.

underplank19:12:10

I had a look at the testing part of the wiki. thanks for the link though. I guess thats my sticking point for the form-2 components. I just dont like the testing story.

underplank19:12:28

With form-1 it seems pretty easy to pass in the atom and validate the data structure coming back. But form-2 components seem to make that more difficult. which is a shame.

mikethompson19:12:29

Yeah, testing views is harder, if you want to use subscriptions. There are ways of doing it, if you are dedicated. But I find these days I almost never test views. There just don't seem to be many bugs in that part of my code. Bugs tend to come in the control logic ...event handlers.

mikethompson19:12:20

BTW, the dedicated way of doing it is to always have an inner and outer version of the function. The outer sources the data and passes it in as props to the inner. Then the inner is pure.

underplank19:12:40

Right. yup. I guess that makes sense.

mikethompson19:12:07

Some discussion of that approach here (but not for the purposes of testing) https://github.com/Day8/re-frame/wiki/Using-Stateful-JS-Components

mikethompson19:12:23

The outer becomes quite trivial.

underplank19:12:24

Ahh thanks. that Wiki is pretty extensive simple_smile

danielcompton19:12:58

@underplank: on testing views, if you keep all the logic out of your views then there is a lot less to test

mikethompson19:12:35

@underplank if testing was critical to you, you could easily enough create a macro which did the whole inner/outer thing automatically.

underplank19:12:53

@danielcompton: yup agree. The road I was/am trying to go down is to have property based testing do most of the heavy lifting for me. ie generate the state from a schema, and then push that through and get the resulting datastructure.

mikethompson19:12:20

But I agree with @danielcompton there's often not much to test in the view.

underplank19:12:42

yup. These are all things I need to think about. Thanks a lot for your help!

mikethompson19:12:19

To put an alternative point of view: every line of code you write is a liability. You only want to write tests where there is genuine value. Cost benefit and all that.

underplank19:12:38

oh sure, hence the wanting to make it as easy as possible to verify.