Fork me on GitHub
#clojurescript
<
2017-04-27
>
john00:04:59

@oahner @thheller I was stringifying the data further down the stream. Sorry for the noise.

john00:04:05

Pretty sure it's working. Transfer speed hasn't improved much, but at least the main thread doesn't hang trying to convert the results to the array.

john00:04:58

So I'm building a cellular automaton to show tradeoffs of using web workers in this agent way. I've got the automaton processing on both the main thread and the web worker, showing the difference between the two. Pretty fun little exercise.

john00:04:36

Next bit to implement, parallelization of a 1D CA. Not looking forward to that šŸ™‚

john00:04:57

I've got an idea to process the whole thing in triangle patches, which will allow parallelization for a particular number of consecutive rows.

john00:04:09

In two passes

Drew Verlee02:04:53

how would i achieve this in clojurescript?

(defrecord ReversibleTie [a b])

(extend-protocol Reversible
  ReversibleTie
  (my-reverse [tie] (->ReversibleTie (:b tie) (:a tie)))
  js/String
  (my-reverse [s] (->> s
                    reverse
                    clojure.string/join "x")))
The code complies, but doesnā€™t work. as in, (my-reverse "hello") fails because their is no my-reverse defined

noisesmith03:04:16

who defines the Reversible protocol?

Drew Verlee03:04:03

@noisesmith I was sort of hoping clojurescript. But i wouldnā€™t be suprised to learn that it doesnā€™t exist. Part of what i was confused about was how to figure out what protocols current existed in clojure/clojurescript.

noisesmith03:04:10

so, when implementing Reversible, you can only implement methods that are actually defined on that protocol

noisesmith03:04:16

if it even exists...

noisesmith03:04:38

even if clojurescript defined a Reversible protocol, it wouldn't have a method called my-reverse

noisesmith03:04:02

but you are free to define Reversible, and call a method my-reverse

Drew Verlee03:04:24

ouch, yea. That makes sense. How do you go about finding out what protocols exist? are they listed somewhere.

noisesmith03:04:38

I don't know if there's good documentation, but there's a namespace that has them in cljs - one moment

Drew Verlee03:04:25

awesome! I think i get it, lets see if i extend the actual protocal thenā€¦

ikitommi05:04:34

hi. any schedule on porting the spec.alpha for cljs too?

robert-stuttaford06:04:14

is there perhaps a way to build multiple disparate :main cljs builds in parallel with cljsbuild? right now weā€™re doing cljsbuild id id2 id3 which does them in serial, which is much faster than do cljsbuild id, cljsbuild id2. but i wonder if perhaps we can build multiple entrypoints in parallel in a single cljsbuild call somehow? cc @dnolen

thheller07:04:49

@robert-stuttaford in theory with :parallel-build true doing multiple builds in serial should be fastest since each successive build can re-use the analyzer data from the previous

thheller07:04:08

if they are isolated each must compile everything on its own which is more work

thheller07:04:57

but FWIW I think it is safer to not share analyzer data between builds, so do should be "safer"

robert-stuttaford09:04:27

cool, weā€™re doing :parallel-build true + one process already, so i guess weā€™ll just add cores until itā€™s as fast as it can be for now šŸ™‚

thheller09:04:58

hmm you are probably stuck waiting for closure? that part could definitely be done in parallel

robert-stuttaford10:04:09

almost certainly, yes

robert-stuttaford10:04:32

weā€™re building about 6 apps, and some of them have an :advanced + :pseudo-names true variant

sickill11:04:20

is there a way to use apply with .methodName interop in ClojureScript?

sickill11:04:18

(apply .methodName object args) doesn't compile

savelichalex11:04:02

(apply (.-methodName object) args) ?

sickill11:04:08

@savelichalex ah, of course! thanks

dnolen13:04:48

@robert-stuttaford Iā€™m sure you could do it manually with your own script - cljsbuild used to have that feature but it I believe the problem was that it tried to share the compiler state atom across very different builds which isnā€™t a good idea

qqq13:04:18

I'm aware of libraries like Om / Reagent / Re-Frame and why I should use them. However, assume I'm bent on directly manipulating the DOM. I want to keep hiccup style notation for creating DOMs (instead of directly using strings myself). Is there a library that will let me directly modify the DOM with hiccup like notation ?

dnolen13:04:07

@robert-stuttaford still @thheller might be right here and youā€™d have to do some testing to see

qqq13:04:04

does hiccup work in cljs, or do I need some other library like crate or hiccups ?

niquola14:04:01

Hi, problem with building -

Circular dependency detected, cljs.core -> cljs.core
[org.clojure/clojurescript "1.9.521" :scope "provided"]

niquola14:04:18

until you remove build directory

niquola14:04:22

in build directory there are two files core.cljs and core.cljc (which requires cljs.core.cljs)

thheller14:04:44

@nicola is it possible that the build directory is also a source path?

roberto14:04:12

I have never used it but it might be useful to u

niquola14:04:15

@theller

{:source-paths ["src/cljs" "src/clj"]
                    :cljsbuild
                    {:builds
                     {:ui {:source-paths ["srcs" "env/prod/cljs"]
                           :compiler
                           {:main "ui.prod"
                            ;; :foreign-libs []

                            ;; :externs []

                            :output-to "build/js/ui.js"
                            :output-dir "build/js/out"
                            :optimizations :advanced
                            :pretty-print  false}}}}

thheller14:04:45

@qqq you could try https://github.com/thheller/shadow specifically the shadow.dom namespace. I have been using that quite some time. not well documented but pretty straightforward.

thheller14:04:10

(dom/append [:h1 "hello world"]) (append to js/document.body)

thheller14:04:08

that looks correct although "srcs" looks a bit suspicious since you already have src/clj and src/cljs?

niquola14:04:42

This src/clj and src/cljs is obsolete - will try to remove

niquola14:04:19

did not help - second build always cljs.core -> cljs.core

souenzzo14:04:41

There is some conf/task to lein copy my Index from resources to target?

niquola14:04:51

cljs.core.cljc
(:require clojure.walk
            clojure.set
            [clojure.string :as string]
            [cljs.compiler :as comp]
            [cljs.env :as env]
            #?(:clj [cljs.support :refer [assert-args]])
            #?(:cljs [cljs.core :as core]) <- HERE
            #?(:cljs [cljs.analyzer :as ana]))

kommen14:04:34

Are there any common pitfalls which break Closure compilers cross-module code motion? All namespaces and dependencies I donā€™t explicitly include in some moduleā€™s :entries end up in the :cljs-base module, though the clearly could be.

niquola14:04:48

separated :output-dir and :output-to - works!

thheller15:04:56

but if you want to rely on code motion: any "side-effect" won't be moved

thheller15:04:28

that includes hash-map construction, defmethod, anything that swaps into an atom, etc

kommen15:04:02

@thheller ok, thanks. good to knowā€¦

kommen15:04:20

that explains things for us I guess

kommen15:04:35

@thheller but does a side-effect than cause the whole namepsace not being moved?

thheller15:04:48

no each def/side-effect individually

thheller15:04:13

unless you are talking to something that wasn't moved

thheller15:04:34

(def x (atom {})) nothing accessing x will be moved

kommen15:04:40

ok, thatā€™s definitely not the case for all of our code

thheller15:04:14

do you have an example of something you'd expect to be moved?

kommen15:04:51

for example my :editor module has editor.core in its :entries. only editor.core or namespaces required by it require reagent. but reagent still ends up in the base module

thheller15:04:50

yeah things like that shouldn't rely on code motion at all as we can figure that out just by looking at the requires

thheller15:04:13

I think defn with multiple arities are never moved as well

kommen15:04:31

@thheller maybe I can make a sample repository demonstrating the issue tomorrow

thheller15:04:52

this pretty much covers everything already https://github.com/thheller/cljs-issues/tree/master/modules šŸ˜‰

qqq15:04:17

suppose you were writing an app, where all it is is 100,000 circles (in svg) moving around randomly; for an app like this, would it be more appropriate to (1) use react / om / re-frame / some type of diffing or (2) just manipulate the dom directly?

thheller15:04:43

@qqq I suppose with that many circles you want canvas (not svg) but react would not be ideal I think

darwin16:04:06

@qqq I would strictly break such app into two parts: 1) ā€œengineā€ 2) ā€œlogicā€ => I would write the engine in plain js with direct DOM manipulation (performance sensitive code), and the logic in clojurescript (as a scripting language, not performance sensitive code) - the engine api should be suitable to expected usage, e.g. submitting js array of data for each frame, or provide just selective updates, it depends on usage

qqq16:04:11

darwin: but you also would use canvas rather than svg, and "render each frame from data" rather than "just update fieds/properties of what changed" ?

darwin16:04:49

cannot tell, this depends on how many objects will be changing on average

darwin16:04:58

if you are going update most of them, then go with canvas

darwin16:04:05

if you are going to do some ridiculous amount of circles all moving every frame then I would consider webgl instead

darwin16:04:29

you can then offload that work to GPU and upload only changed positions each frame

darwin16:04:44

easy task for GPU

qqq16:04:04

okay, so I lied a bit; I'm not rendering circles; I'm rendering lots of pieces of text

qqq16:04:18

I considered GPU, but then I run into problem of text rendering

qqq16:04:29

in particular, pure textures = blurry, signed distance fields = slightly better,

qqq16:04:36

and vector / rendering bezier curves = complicated

qqq16:04:47

otherwise, I'd happily jump to WebGL

gazaxian16:04:11

Distance fields look ace

gazaxian16:04:24

some guy just wrote a live coding env in a web browser and replaced all of the UI components with shader blobs, it sounds mad (it is) but the text looks ace zoomed in

gazaxian16:04:27

let me find it

gazaxian16:04:04

great presenation

john16:04:11

That's pretty bad ass

qqq17:04:18

in cljs, after I create a new pop up window with js/window open ... , I seem to have race conditions dealint with accessing divs of the window

qqq17:04:31

do I need to somehow use a on-window-load of thepop up window as well ?

mikepence17:04:04

a JS lib is passing back an Object of data to my cljs. Is there a cljs method to show me the content of that data?

mikepence17:04:16

in Ruby-land I just had to object.inspect

jr17:04:05

(comp pr-str js->clj)

mikepence18:04:11

hmm, so the value being sent to me by JS logs to the console as

{:source [{source /dzi/madonna.dzi, eventSource #object[Object [object Object]], userData nil}]}

mikepence18:04:45

I want that 'madonna.dzi' value but attempts at destructuring it are unsuccessful

mikepence18:04:51

time to get figwheel and cursive working together so that I can actually have a REPL and see values, I guess.

qqq19:04:00

do popup windows inherit css from parent

qqq19:04:10

or do they need to have their own css includes ?

mobileink19:04:18

#off-topic? lots of css slack channels.

qqq19:04:52

@mobileink : fair enough, not everything done in cljs is on topic for #cljs

mobileink20:04:46

just bustin your chops. šŸ˜‰

darwin20:04:40

I had to go. But I think text rendering can be done with webgl without blur. This experimental project is state of the art IMO: https://github.com/evanw/sky

mikepence20:04:45

wow, loving cljs. interop with js is so easy.

darwin20:04:22

yes, and he also wrote very nice blog article(s) about text rendeirng

mobileink20:04:50

darwin: link?

qqq20:04:01

I almost attempted that until (1) found his code was in Skew (???) and (2) each char gets blown up to like 100 triangles (in particular, # of control points)

darwin20:04:18

each char is just a single quad

darwin20:04:46

he uses pre-rendered textures in this case

darwin20:04:33

and IMO skew is not a problem if you want to re-implement the method

darwin20:04:39

it reads pretty well

darwin20:04:33

Iā€™m talking about sky editor (not about his article or theta)

mobileink20:04:04

i'm very interested in this, but maybe #off-topic is better? since we do not have #typography.

alexwheeler22:04:30

how does everyone load cljs namespaces in a lein project into the repl?

skeuomorf22:04:31

Is there an html generation lib Ć  la hiccup that works across different targets? i.e. jvm, JS

john23:04:48

not sure how closely that aligns with the clj version.

skeuomorf23:04:16

@john Yeah, Iā€™ve seen that one, not cross-target though -I think-

skeuomorf23:04:32

@john What I mean is, something thatā€™s mostly *cljc

skeuomorf23:04:46

*.cljc, maybe with minor cljs and clj code

john23:04:36

It may be possible to take the hiccups version and make a cljc version, by pulling in bits from the clj version.

skeuomorf23:04:06

@john Yeah, took a quick glance and was thinking the same

john23:04:55

Could potentially do server-side rendering with the hiccups lib

john23:04:32

Though that's a different workflow, potentially negating the benefit you were looking for in a cross-platform solution

skeuomorf23:04:29

Sorry, I am not following

skeuomorf23:04:34

oh, I am familiar with server-side rendering, was wondering how that ties into the conversation is all

skeuomorf23:04:04

prepending ā€œfun fact:ā€ to ā€œCould potentially do server-side rendering with the hiccups libā€ šŸ˜„

john23:04:47

oh, I guess I meant the "hiccup lib"

john23:04:59

I've never actually messed with server side rendering.

john23:04:14

Yeah, I guess I got the rendering backwards šŸ™‚ hiccup is already "rendering" the html server side.

skeuomorf23:04:39

yeah, I just call it generation

skeuomorf23:04:55

cause rendering has all the ā€œdisplayā€ connotations attached to it

skeuomorf23:04:15

cause essentially, weā€™re just generating strings

skeuomorf23:04:37

sending it to a renderer e.g. (a rendering engine inside a browser) gets it rendered

john23:04:41

Do both implementations generate strings? or does one make some kind of object?

skeuomorf23:04:49

both generate strings

skeuomorf23:04:33

which is mentioned in the hiccups readme, which returns dom nodes instead

john23:04:14

Seems like the hiccups version should be eligible for a cljc upgrade then.

john23:04:26

If both versions generate strings

john23:04:33

the same strings

skeuomorf23:04:00

Yeah, but I think hiccups is behind regarding some features, at least based on the TODO