Fork me on GitHub
#re-frame
<
2018-01-13
>
souenzzo01:01:35

;; A
(defn button [{:keys [on-click]}] [:button {:on-click on-click}])
(defn Card [] (let [id @(subscribe [:foo])] [button {:on-click #(dispatch [:click id])}]))
;; B
(defn button [{:keys [on-click]}] [:button {:on-click #(dispatch on-click)}])
(defn Card [] (let [id @(subscribe [:foo])] [button {:on-click [:click id]}]))
There is performance differences between A and B? Has any difference between @(subscribe ..) or @id?

mikethompson02:01:34

I can't imagine any material difference between A and B

mikerod03:01:35

@souenzzo @mikethompson the one thing I thought, but not too sure, is that A may try to render button more often

mikerod03:01:51

Since the anonymous fn would change every time, even if id hasn’t changed.

mikerod03:01:06

The different fn’s as props would never be =

mikerod03:01:27

in the case of B the vector would be = even when a new vector is made, so the props would still be = for Reagent rendering cycle

mikerod03:01:40

However, I’m not sure how big of an affect that should really be in such a tiny case

mikethompson03:01:35

Neither would their be any difference between @(subscribe ...) and @id. Maybe if you were completely paranoid about performance, you might try:

(defn button 
   [*id] 
   [:button {:on-click #(dispatch [:on-click @*id])}])

(defn Card
   []
   (let [*id  (subscribe :foo)]     ;; subscription outside - we name cursors with a leading *
      (fn []                      ;; note the render function 
          [button *id]
           )))

mikethompson03:01:56

Back in the day when we passed subscriptions around we would always name them with a leading *, so make it clear they were not values

mikethompson03:01:25

But we stopped doing this approach because we found it confusing when we later came back to the code.

p-himik03:01:45

@mikethompson Wouldn't dereferencing a subscription inside an :on-click handler leak the subscription in case a user never clicks the button?

mikethompson03:01:44

I think it will be okay. The subscription is "captured" by the act of rendering button. When button goes away, the subscription will be released

mikerod03:01:22

I’d think that it wasn’t reactive anymore if the :on-click never happens

mikethompson03:01:44

Oh, right. Now I get what you are saying

mikethompson03:01:51

Very true. Sorry, i missed that @p-himik

p-himik03:01:52

Thanks for confirming. 🙂

mikerod03:01:02

I wonder if @souenzzo saw a performance difference in some case or if it was just speculative

souenzzo11:01:36

It was just a doubt. 🙂

mikerod20:01:34

Hah. I see.

mikethompson03:01:07

@mikerod I agree with your analysis about the function parameter never testing equal.

mikerod03:01:44

Was it re-frame docs that actually mentioned that as a potential perf issue? I can’t remember. However, I understand conceptually why it’s the case

mikethompson03:01:07

In normal everyday use it doesn't really matter at all. But if you have a LOT of one kind of component, then its the equivalent of a tight loop, and you might need to optimise. Maybe.

mikerod03:01:51

ah yeah, there it is

mikerod03:01:02

Yeah, I don’t tend to worry about it most of the time

mikethompson03:01:59

Perhaps this is the moment when I plug re-frame-trace. X-Ray vision for your re-frame app. Well, it will be that eventually. Still a bit simple ... but surprisingly useful. A new version is about to drop.

tagore03:01:26

Hmm- I'm reminded of some performance problems in a React table thingy I wrote a while ago.

tagore04:01:25

Our CTO said "Isn't React supposed to be fast, and solve this?"

tagore04:01:04

I almost sent him the perlisism 'When someone says "I want a programming language in which I need only say what I wish done," give him a lollipop.'

tagore04:01:44

There's very little as fast as whacking data in place.

tagore04:01:08

But try to get it right, in the lone run.

souenzzo13:01:18

A bit OFF from re-frame: but I'm a CSS noob, at the moment, I'm <link src="bootstrap.css"> on my index.html and writing some :button.btn. What are the possible paths to a "real" CSS architecture? #garden is the way? Need something else then garden to make everything works on a re-frame project? Examples?

curlyfry14:01:43

That's not really related to re-frame, you can use whatever css technology you prefer! 🙂 I tend to use a preprocessor (less/sass/stylus) that builds a single style.css file that I just include in my index.html. <link href="css/style.css" rel="stylesheet" type="text/css">

souenzzo14:01:15

So you make classes in less (for example) and use with div.button? how you organize that classes? one classe for each use? :div.ok-button.home-style or :div.ok-button-home.? I can write tests for find typo errors, like :div.ok-buttno? I'm totally lost on CSS (and I cant find good docs)

curlyfry15:01:46

There are a lot of resources for learning CSS online. If you're totally lost on CSS it might be best to just use "bare" CSS without a preprocessor while you're learning. Check out https://developer.mozilla.org/en-US/docs/Learn/CSS/Introduction_to_CSS for example!

curlyfry16:01:15

Haha 🙂 Hmm, maybe check if there are some nice tutorials on youtube?

justinlee16:01:45

@souenzzo As a programmer who taught himself the horrors of CSS, here is my advice: (1) Don’t layer too many complexities like BEM naming and stuff like that. I’d reccomened you get a sass preprocessor going just so that you can use variables and includes, but don’t use any other features of the preprocessor. (2) Write one class per component and don’t worry about too much copy-and-paste. Writing “clean” CSS code isn’t worth it unless you are on a team. (3) Learn flexbox. Find some tutorials and learn it well, because you can do almost anything with it.

tagore23:01:13

I've come to think that stylesheets are a bad fit for web applications- they are a fine fit for websites.

tagore23:01:31

I'm inclined to think that approaches like 'styled-components' (a JS library) are much nicer for web applications.

tagore23:01:53

You might want to take a look at libs like https://github.com/roman01la/cljss

souenzzo12:01:06

I think that @U4EFBS3PH complement @U8ES68TGX. yesterday I started to write some #garden but cljss looks simpler. I will try it today.

souenzzo14:01:37

#cljss hasn't a cljc port and all my project is in cljc. Back to garden branch 😄