Fork me on GitHub
#hoplon
<
2017-12-24
>
James Vickers00:12:46

This question may be overly broad...but can we compare/contrast Hoplon and the ClojureScript bindings for React (Om, Rum, Reagent)? I didn't know anything about those when I started making a small app in Hoplon but having read about them since, there seem to be a lot of similar abilities (e.g. define HTML components in ClojureScript)

flyboarder01:12:21

@jamesvickers19515 there are similarities, however while those use react.js under the hood, hoplon uses native javascript internally and cljs features for the “reactive” parts of hoplon

James Vickers01:12:59

Makes sense. I saw Hoplon mentioned in a thread comparing these CLJS React libraries, basically saying you could use it if your app wasn't huge/complex and didn't have significant performance considerations. Is that a fair characterization? The app I'm making is not particularly large or complex and doesn't interact with a server (client side only).

flyboarder01:12:25

I disagree, I would say so long as you dont intend to use react native, there is no reason to use those over hoplon

flyboarder01:12:13

I personally feel those libraries add bloat and additional layers of complexity which are not needed in most applications

flyboarder01:12:32

at Degree9 we exclusively use Hoplon for the client portion of our applications.

flyboarder01:12:39

but I dont have any direct comparison for benchmarks between the two

flyboarder01:12:19

I think the buzz around those libraries makes people overlook solutions which are simpler and designed in cljs

flyboarder01:12:00

I always ask people what does the structure of your application look like in memory? In the browser it’s the same as the structure of your HTML, so your code should look like your HTML, Hoplon is the only thing that does this IMO

flyboarder01:12:44

@jamesvickers19515 this is just my personal view tho

James Vickers01:12:52

Thanks for the thoughtful response! I was getting sucked into considering bringing in one of those React libraries but it doesn't seem like a great fit for this application. Hoplon it is! I have liked it so far.

James Vickers01:12:31

Is there an example somewhere of doing charts (data visualization) in Hoplon, that update when a Javelin cell changes or something?

James Vickers01:12:58

What kind of CLJS charting libraries do people use with Hoplon? Maybe that's a weird question since Hoplon wouldn't be opinionated about that.

flyboarder01:12:42

you can use any js charting library, checkout whats available on CLJSJS

thedavidmeister02:12:07

@jamesvickers19515 this "hoplon is bad for performance" thing has been floating around but i haven't seen it in anything i've done

thedavidmeister02:12:43

there are some hand wavey references to ancient forum posts, but i looked at them and to me it just looked like badly designed code, not something hoplon was doing

thedavidmeister02:12:22

hoplon is simple and powerful, but doesn't have a marketing juggernaut behind it 🙂

thedavidmeister02:12:25

if anything, you might get tripped up by the eagerness of javelin cell evaluation but:

thedavidmeister02:12:32

1. javelin is technically not hoplon 😛

thedavidmeister02:12:48

2. it's pretty easy to work around eager evaluation thrashing the CPU using standard techniques like throttle/debounce, etc.

thedavidmeister02:12:33

3. if you ever come across some serious performance issue, we'll look into it, i'm sure we can improve things if we have actual examples of problems 😉

thedavidmeister02:12:33

@jamesvickers19515 for charting i use some utility funtions and raw hoplon.svg

thedavidmeister02:12:54

javelin + hoplon is already basically a much better version of what d3 tries to do

thedavidmeister02:12:13

so i use the part of d3 that calculates SVG path strings and ignore the rest

thedavidmeister02:12:53

e.g. here is a slice of a pie chart that i made

thedavidmeister02:12:56

(defn pie-slice
 [slice]
 (let [centroid (j/cell= (apply d3-cljs.arc/polar-centroid (flatten (vec slice))))
       angle (j/cell= (mod (second centroid) wheel.math.number/tau))
       ; annoyingly d3 quadrants are *clockwise*
       quadrant (j/cell= (quot (second centroid) wheel.math.number/lambda))

       ; arc measures angles from q3 so we have to rotate by -lambda to get
       ; x/y as expected by svg.
       centroid' (j/cell= [(+ (:outer-radius slice) spacing.data/mini-pad)
                           (- (second centroid) wheel.math.number/lambda)])
       x-y (j/cell= (apply wheel.math.geometry/polar->cartesian centroid'))]
  (svg/g
   (h/when-tpl (j/cell= slice)
    [
     (svg/path
      :svg/d (j/cell= (some->> slice vec flatten (apply d3-cljs.arc/arc)))
      :svg/stroke colours.data/strongdarkpurple
      :svg/fill colours.data/strongdarkpurple
      :svg/fill-opacity (j/cell= (if (:pie.slice/fill? slice) 1 0)))
     (svg/text
      :svg/x (j/cell= (first x-y))
      :svg/y (j/cell= (second x-y))
      :svg/dy "0.3em"
      :svg/font-weight "bold"
      :svg/text-anchor
      (let [end-tolerance (/ wheel.math.number/tau 15)]
       (j/cell=
        (cond
         ; near the bottom
         (>=
          end-tolerance
          (Math/abs (- (* 2 wheel.math.number/lambda) angle)))
         "middle"

         ; near the top
         (or
          (>= end-tolerance angle)
          (>= angle (- wheel.math.number/tau end-tolerance)))
         "middle"

         ; rhs
         (#{0 4 1} quadrant) "start"

         ; lhs
         :else "end")))

      (j/cell= (:pie.slice/label slice)))]))))

thedavidmeister03:12:28

yields something like this (i could probs put a little more whitespace on the text at the top):

thedavidmeister03:12:00

@jamesvickers19515 all this should be on the hoplon home page, we get asked this stuff a lot >.<

dm317:12:34

the only problem with Hoplon - there are like 20 people total actively using it

dm317:12:49

but it’s small enough to actually read and understand the source code

dm317:12:00

try that with React…