Fork me on GitHub
#clojurescript
<
2017-04-26
>
jholkeboer01:04:58

i've tried things like (use 'cljs.clojure.data), (require 'cljs.data), etc

noisesmith01:04:54

clojure.data

noisesmith01:04:58

go by the name given in the ns form

jholkeboer01:04:28

(use 'clojure.data) throws an error. something i'm missing here?

jholkeboer01:04:47

in cljs repl

jholkeboer01:04:58

oh hey i got it working by adding clojure.data to the namespace form, outside of the repl

deas06:04:24

@anmonteiro Wouldn't it make sense to squeeze the "module which is not package" cases close to :npm-deps and index all the things in one go?

bunkers13:04:53

Does anyone have any links to documentation about monitoring atoms and memory usage? I’ve got a situation where I think I’m doing something a bit odd and it’s causing big garbage collection pauses

bunkers13:04:38

Also, the project is using Matter.JS as a physics engine, and I’ve got lots of references to JS objects that it creates and updates. Would there be any particular issues with storing these in a map in a global state atom?

darwin13:04:42

@bunkers Chrome DevTools’s Memory tools do not work for you?

bunkers13:04:16

well I’ve been profiling with that, but the output is a bit incomprehensible for me! That’s why I was wondering if there was any tutorials for using tools like that to profile ClojureScript

darwin13:04:55

I doubt you will find anything better than that 😕

bunkers13:04:14

I think I’m probably using it wrong, and/or need a better understanding of it. It chucks out a load of stuff but I can’t see how it relates to the objects and data structures in my clojurescript code

darwin13:04:17

you could hand-roll something to track number of your atoms and how much is stored there, I would double check that you don’t keep references to “historical” objects, so that each frame you release all garbage properly

bunkers13:04:26

have you got any pointers on using the memory profiling in dev tools?

darwin13:04:14

no, I’m sorry

bunkers13:04:12

no problem, I’ll try sticking in some logging like you suggest

darwin13:04:11

@gmercer (def format js/goog.string.format), but that assumes that you required the goog.string.format package correctly

darwin13:04:38

or goog.string?

darwin13:04:57

let me look where exactly it is provided

gmercer13:04:15

I have the require done

gmercer13:04:19

#?(:cljs [goog.string.format :as gsf]) )

gmercer13:04:23

was hoping for

#?(:cljs
       [goog.string.format :as format])
    )
or similar

darwin13:04:53

it is provided in goog.string.format, but adds format method on goog.string

darwin13:04:29

so this require should work: [goog.string.format] [goog.string :refer [format]]

gmercer13:04:58

gimme a sec

darwin13:04:15

or use [goog.string.format] [goog.string :as gstr] and then gstr/format

darwin13:04:14

or just [goog.string.format] and then js/goog.string.format, because goog.string.format pulls in goog.string implicitly: https://github.com/google/closure-library/blob/master/closure/goog/string/stringformat.js#L27

gmercer13:04:56

not having any luck with the :refer suggestion .. I was hoping to leave the current clj alone - the def seems to be doing the trick

darwin13:04:26

or [goog.string.format :as format] might work as well

gmercer13:04:48

that doesn't work .. I think that was one of my first attempts

darwin13:04:39

yep, I think the problem is that goog.string.format is both namespace and a method

darwin13:04:03

I’m 100% sure [goog.string.format] [goog.string :as gstr] and then gstr/format worked for me at some point in the past

thheller13:04:08

IIRC think :refer only works for CLJS

darwin13:04:32

you can do then (def format gstr/format) and call it a day, no?

gmercer13:04:23

I can live with the def .. which is better than reader hacking all of the working clj code

darwin13:04:05

I think your best bet is to require [goog.string.format] and then (def format js/goog.string.format)

thheller13:04:32

> I’m 100% sure [goog.string.format] [goog.string :as gstr] and then gstr/format worked for me at some point in the past

thheller13:04:34

this works fine and is better than pull it into a local var

gmercer14:04:38

defing seems the best when working with an exiting clj codebase

dominicm14:04:44

Is there an interop form for async/await from es7?

thheller14:04:22

@dominicm no we compile to ES3

Pablo Fernandez14:04:17

How do you test for exception on cljs.test?

agile_geek15:04:01

(is (thrown? js/TypeError ....)

jfntn15:04:42

Does cljs allow defining one protocol implementation for multiple types with this syntax: (extend-protocol IFoo BarType BazType (foo [_]...))?

mikepence15:04:21

trying to do the cljs equivalent of viewer.open({tileSource: "/dzi/testdz.dzi"}); what I currently have

(. js/viewer (open "{tileSource:
\"/dzi/testdz.dzi\"}"))

mikepence16:04:22

I need to pass json with a string to the js object

mikepence16:04:29

not a whole string

jr16:04:12

(.open js/viewer #js {:tileSource "string"})

mikepence16:04:45

looking for some examples of passing cljs functions to be invoked as js callbacks

darwin16:04:47

nothing special about it (js/setTimeout some-cljs-fn 1000)

darwin16:04:46

(js/setTimeout (fn [] (println "hello")) 1000)

mikepence16:04:31

thanks, I meant passing cljs functions to js as callbacks (onsuccess, onfailure, etc.)

darwin16:04:54

what is the difference?

darwin16:04:17

setTimeout is a js function expecting a callback as the first param

mikepence16:04:44

quite correct, thank you

john18:04:51

Trying to translate a bit of JS into CLJS...

var imageData = context2d.createImageData(width, height);
imageData.data.set(new Uint8ClampedArray(bufferToReturn));
context2d.putImageData(imageData, x_offset, y_offset);
Is that set a method call? Would I do (.set (.-data imageData) (js/Uint8ClampedArray. buffer-to-return))) ??

john18:04:13

I'm getting a blank canvas atm

oahner18:04:06

@john that looks fine, is buffer-to-return a js or clj data structure?

john18:04:48

@oahner I've tried passing it a (js/Float32Array. [0 1 2 3 4 5]) and (.-buffer ... version of that. I can see there is data in the array I'm passing to the UInt8ClampedArray constructor. I must not be using the constructor right.

oahner18:04:24

(js/Float32Array. #js [0 1 2 3 4 5])

oahner18:04:48

it's the Uint8ClampedArray that's constructed wrong

john18:04:54

mdn says it takes an object. To pass a buffer, it says, new Uint8ClampedArray(buffer [, byteOffset [, length]]); ... Does that mean I should do (js/Uint8ClampedArray buffer #js [0 #js [4]])?

oahner18:04:57

imageData.data.set is TypedArray.set, it can take a TypedArray instance or a regular array

oahner18:04:40

(.set (.-data imageData) #js [0 1 2 3 4 5])) should work

john18:04:10

@oahner rgr, I'll give it a shot. thanks

john18:04:27

@oahner Oh, also, I'm trying to send arrays to and from web workers and so I need to send the Transferable ArrayBuffer. Is there a way to pass the ArrayBuffer in instead? Or convert the ArrayBuffer back into an Array?

john18:04:44

Basically, trying to do as much of the image prep on the worker side as possible, and just feed the finished buffer into the canvas context on the main thread side.

oahner18:04:01

you can pass typed arrays around with postMessage

john20:04:06

postMessage isn't liking specific TypedArrays. Chrome only seems to send ArrayBuffers

oahner21:04:13

@john you can get the underlying buffer with TypedArray.prototype.buffer and send that

john22:04:20

@oahner Thanks. Any idea how to convert an ArrayBuffer back into the TypedArray?

thheller22:04:05

don't they all take an arraybuffer as constructor arg?

thheller22:04:29

(js/Int32Array. buffer)?

ag23:04:25

I need to call js constructor as a function, how do I do that? e.g. (apply js/Date. x) won’t work

ag23:04:37

or in other-words: I need to pass vector of things into js constructor? How do I do that?

ag23:04:14

or in other-words, I need to translate something like this to Clojurescript syntax:

new (Function.prototype.bind.apply(Date, [null, "2008-10-10"]))

ag23:04:31

any ideas?

darwin23:04:36

(let [x (js/Function.prototype.bind.apply js/Date #js [nil, "2008-10-10"])] (x.))

darwin23:04:03

btw. why don’t you simply call date’s constructor like this? new Date("2008-10-10") ah ok, that was just an example