Fork me on GitHub
#clojurescript
<
2016-12-13
>
Aron00:12:54

i should write something like this, for jsnetworkx

Aron00:12:42

probably easier than reimplementing the algorithm, although i am not quite sure, that formula doesn't look this complicated šŸ˜„

podviaznikov04:12:25

what is the best way in clojurescript to extend ES6 classes? I want to extend code like in this example: https://github.com/substance/simple-writer/blob/develop/lib/simple-writer/SimpleWriter.js#L9

hueyp07:12:46

@podviaznikov not sure if there is a better way but I just do it manually ā€¦ stole it from one of the many react libraries (probably om ;p)

(defn ^{:jsdoc ["@constructor"]} Root []
             (this-as this
               (.apply js/React.Component this (js-arguments))
               this))

           (set! (.-prototype Root)
                 (goog.object/clone js/React.Component.prototype))

(specify! (.-prototype Root) Object ā€¦ your stuff ā€¦)

borkdude09:12:48

I tried to cache canvas data by caching the dataURL. Turns out redrawing the canvas is like 50x faster than creating an image from the dataURL. Does that make sense?

Aron10:12:38

but it also depends on a bunch of factors, however i expect canvas to be extremely fast by itself

borkdude10:12:32

it depends on the amount of operations on the canvas vs the amount of data generated by the canvas I guess

Aron10:12:57

my first guesses for why the dataURL method might be slower are 1. conversion might be hard 2. some DOM API might be touched and that obviously ruins everything immediately

borkdude11:12:23

@ashnur do you mean the creation of a new image element as DOM api?

Aron11:12:00

that would be one example, sure

borkdude11:12:54

Is there already a macro that wraps (js/performance.now) around the body and prints the duration of an expression that I donā€™t know of maybe? šŸ™‚

rauh11:12:18

(defmacro profile-always
  "Stays in production"
  [k & body]
  `(let [k# ~k
         t0# (js/performance.now)]
     (let [res# (do ~@body)
           t1# (js/performance.now)
           ms# (- t1# t0#)
           report# (str k# " " ms# "ms")]
       (if (< 10 ms#)
         (js/console.warn report#)
         (js/console.info report#))
       res#)))

anmonteiro11:12:35

there is cljs.core/system-time, btw

borkdude11:12:02

@rauh something like that yes šŸ™‚

borkdude12:12:40

Can a macro re-definition be picked up by the clojurescript compiler?

borkdude12:12:18

or is it only read at startup?

dnolen12:12:10

@borkdude we have support for :reload at the REPL, downstream tooling can easily support macro-redef

dnolen12:12:53

also the time macro calls performance.now if available

borkdude12:12:16

nice, thanks!

borkdude12:12:32

Made this one now:

(defmacro profile-js [k & body]
     `(do
       (defonce ~'profile-stats (atom {}))
       (let [k# ~k
             t0# (js/performance.now)
             res# (do ~@body)
             t1# (js/performance.now)
             ms# (- t1# t0#)
             all-stats# (swap! ~'profile-stats
                                update k# conj ms#)
             k-stats# (get all-stats# k#)
             avg# (/ (apply + k-stats#)
                      (count k-stats#))
             report# (str k# " " ms#
                          "ms, average: " avg# "ms")]
         (js/console.info report#)           
         res#)))
(credits to @rauh for the idea)

rauh12:12:15

@dnolen About yesterdays conversation: This also means we should avoid declare for performance critical code since the cljs compiler won't know the exact arity of the function and generate unoptimal code. Good to keep an eye out.

crankyadmin12:12:33

Hi

import createRichButtonsPlugin from 'draft-js-richbuttons-plugin';

const richButtonsPlugin = createRichButtonsPlugin();

crankyadmin12:12:54

Given that, what would the clojurescript version be?

crankyadmin12:12:04

(defn createRichButtonsPlugin (aget js/window ā€œcreateRichButtonsPluginā€))

anmonteiro12:12:12

@crankyadmin

(def createRichButtonsPlugin (. js/window -createRichButtonsPlugin))

anmonteiro12:12:44

aget is meant to only be used for arrays

crankyadmin12:12:00

Iā€™m ashamedā€¦ I knew that.

crankyadmin12:12:10

Its been a head bashing off desk morning.

anmonteiro12:12:46

that wasn't the problem with the above though. It would work (currently), but that's an internal implementation detail

anmonteiro12:12:56

your problem was the defn

crankyadmin12:12:02

I get a esModule back now. Which is a step forward. šŸ™‚ My main problem is that Iā€™m having difficulty porting this https://github.com/jasonphillips/draft-js-richbuttons-plugin#usage to cljs

crankyadmin12:12:40

I just want the CodeButton object

anmonteiro12:12:37

@crankyadmin hrm there should be a default key in the object you get, probably

anmonteiro12:12:49

so

(def createRichButtonsPlugin (.. js/window -createRichButtonsPlugin -default))

crankyadmin13:12:18

(def richButtonsPlugin ((.. js/window -createRichButtonsPlugin -default)))
(def CodeButton (aget richButtonsPlugin ā€œCodeButtonā€))
Got me what I needed šŸ™‚ Thanks for the help!

dnolen13:12:53

@rauh we always generate arity check + dispatch if we canā€™t figure it out - but yes declare is like the higher order case

danielgrosse14:12:03

How can I clone and install the google-closure-library local? I found a bug and wan't to resolve it for my project.

martinklepsch15:12:01

@danielgrosse afaik @stuartsierra is packaging that for Maven etc, maybe he has some advice or repo up somewhere

Alex Miller (Clojure team)15:12:54

in the clojurescript repo there is a script under /script/closure-library-release

Alex Miller (Clojure team)15:12:51

thatā€™s the script used to build the lib that clojurescript depends on so you could modify that

danielgrosse15:12:41

@alexmiller Thank you. I will look into it.

cmal15:12:15

Hi, why the (for ...) clause in the let clause did not run? I logged the value of k and v but it shows nothing.

cmal15:12:35

the console output is {:title "test1" :options {"a" 0, "b 2}} 2 0 -1 ["#1f77b4", ...]

rauh15:12:49

@cmal for is lazy, you probably want a doseq in this case

cmal15:12:07

@rauh oh, Thank you!

thheller16:12:41

@danielgrosse you can also just put the file you want to edit into your source path

thheller16:12:03

that should take precedence over the file in the jar

lxsameer19:12:54

I'm trying to use a js package in my cljs app, the js package add the object A to window. How can i require the A object using cljs ?

dnolen19:12:30

@lxsameer: people generally do this via :foreign-libs compiler option

lxsameer19:12:02

I'm using the samething

lxsameer19:12:13

I'm trying to use Grommet

lxsameer19:12:53

it has a global object which contains several react components. What is the best practice to use the children of the Grommet object ?

lxsameer19:12:31

@dnolen since intern in not implemented in cljs, how can i define a var from a string ? something like (intern ns (symbol "x") value)

dnolen19:12:05

thereā€™s no such thing since Vars do not really exist

dnolen19:12:30

reified vars and namespaces are pretty much incompatible with the advanced compilation model

dnolen19:12:24

the answer to Var & Namespace voodoo in ClojureScript is - "no you canā€™t do that"

lxsameer19:12:09

@dnolen thanks that was the best answer šŸ™‚

dnolen19:12:41

@lxsameer we can simulate only the static aspect of vars, like dump the metadata for a var - but all the dynamic stuff is not possible

enajski21:12:27

hiya, I'm trying to debug some spec code that often throws an error on cljs:

enajski21:12:24

the trigger seems to be that the second form's :max-count is higher than the first ones

dnolen21:12:26

@enajski I donā€™t see anything obvious, I would use source maps and use a debugger to see where itā€™s failing in cljs.spec/coll-prob

enajski21:12:20

@dnolen that's where I'm at, will keep hacking at it

dnolen21:12:31

@enajski also need more environmental information

dnolen21:12:41

I took a look and I see nothing wrong there

dhruv121:12:02

newbie clojurescript questions here. I am using material-UI from cljsjs in my project. How do i use it? For example, how would i use the App Bar component http://www.material-ui.com/#/components/app-bar

enajski21:12:51

@dnolen what environment information would be useful? I'm connected to a figwheel/cljs-repl and evaling the code

dnolen21:12:51

@enajski thatā€™s useful šŸ™‚

dnolen21:12:58

in anycase I would look at the source for coll-prob I donā€™t see how you could get that error

dnolen21:12:05

youā€™re as likely to find the source of the problem as I am

dnolen21:12:21

I took a cursory look and I didnā€™t see anything

enajski22:12:07

yup, it's really not obvious why this happens as the clj implementation looks very much alike and no errors occur

dnolen22:12:08

@enajski I also couldnā€™t reproduce your problem at the REPL

enajski22:12:47

have you tried a couple of times? the error occurs with some probablity for me

dnolen22:12:01

@enajski I cannot repro

dnolen22:12:05

I just tried dotimes 1e5

dnolen22:12:36

but Iā€™m not using Figwheel either, just the standard Node REPL

dnolen22:12:41

I would not rule out environmental problems

enajski22:12:04

thanks, I'll see what else I can find

enajski22:12:40

so the stacktrace I posted was from Chrome, trying the same in Firefox yields a different message:

dnolen22:12:42

ok yeah that helps šŸ™‚

enajski22:12:23

in Safari: #object[TypeError TypeError: undefined is not an object (evaluating 'cljs.core.unquote.call')]

dnolen22:12:09

@enajski I pushed a fix to master - if you can try that out

dnolen22:12:45

Git clone ClojureScript, cd into the directory, ./script/build

dnolen22:12:58

take note of the version that gets installed into your local Maven, and use that in your project instead

dnolen22:12:04

(make sure to clean your build, etc.)

dnolen22:12:04

thanks much

enajski22:12:30

@dnolen I think it did the trick, thanks!

dnolen22:12:41

@enajski glad to hear it

fiddlerwoaroof23:12:48

I can't seem to find a function for finding the floor, ceiling and raising a number to an exponent, do people just use js/Math?

michaellopez23:12:13

theres a goog.math.safeFloor and goog.math.log10Floor and goog.math.safeCeilā€¦ https://github.com/google/closure-library/blob/master/closure/goog/math/math.js