Fork me on GitHub
#clojurescript
<
2019-04-24
>
henrik04:04:26

Closure docs has this example: var vsm = new goog.dom.ViewportSizeMonitor(); I wanted to translate this to something like (def vsm (new (goog.dom.ViewportSizeMonitor))), but get the complaint that "goog.dom.ViewportSizeMonitor is not a constructor". What would be the proper interop for this?

henrik05:04:34

Also, it's apparently "not a function". This is the definition though: goog.dom.ViewportSizeMonitor = function(opt_window) {…. What is it if not a function?

henrik05:04:43

Never mind, answered my own question: Require [goog.dom.ViewportSizeMonitor], then:

(let [vsm (goog.dom.ViewportSizeMonitor.)]
  (.listen goog.events vsm goog.events.EventType.RESIZE
           #(js/alert (str "View size: " (.getSize vsm)))))

Jay06:04:02

Hey guys, I'm having trouble finding the errors in my reagent code I'm new to clojure so I'm not sure if I'm doing something wrong when I run figwheel it doesn't show any errors I have in the terminal Sometimes they will show in the browser instance rendered at the bottom in a little cljs window and sometimes they won't show at all but I never see them in the actual terminal that I am running figwheel from

mauricio.szabo04:05:05

That's one f the reasons I use shadow-cljs: because the compilation is more reliable on Shadow...

phill09:04:55

@jayvmithani646 me too (using lein figwheel) but not very often. Remedy is to stop figwheel, do "lein clean" and "lein cljsbuild once", fix the problems it announces, repeat the clean & cljsbuild until the result is clean, and then try figwheel again.

Jay09:04:16

@phill Hey, thanks for the guidance. I followed your instructions and found the bugs in my code. Now when I run lein figwheel I still get no error reporting though. Maybe I'm misunderstanding what I'm supposed to be seeing. Are my errors supposed to show up in the repl? (where it shows app:cljs.user=> ).

arbscht09:04:25

@jayvmithani646 hm, are they compile errors or runtime errors?

Jay09:04:10

I believe compile errors

Jay09:04:29

Actually, it happens on both

arbscht09:04:41

ok, I'd expect either type of error to appear in the HUD on the page. but you can see compile errors in repl if you initiate a build there, e.g. => (build-once :dev)

arbscht09:04:10

I wouldn't expect errors on the page to appear in the repl -- they share the runtime but control isn't in the repl

Jay09:04:33

ah, yes compiler errors do appear on the HUD

Jay09:04:42

runtime errors don't appear anywhere, though

arbscht09:04:55

ah, so runtime errors would go to console

arbscht09:04:13

it seems the hud is only for compile errors

arbscht09:04:35

(I haven't used figwheel in a long time, checking it out myself...)

Jay09:04:30

Oh okay, so like the browser console?

arbscht09:04:40

yep, devtools / web console

Jay09:04:59

Okay, I see

arbscht09:04:13

if you're working on chrome I can recommend https://github.com/binaryage/dirac for a nicer cljs console experience

Jay09:04:05

Ah, thanks!

idiomancy18:04:09

how do I do what I'm actually trying to do here

idiomancy18:04:29

like, you cant actually extend concrete superclasses with reify

idiomancy18:04:26

Id just like some way to define a class inline, ideally just an anonymous one

thheller18:04:08

@idiomancy I played with webcomponents a couple years ago, maybe this helps a bit? https://gist.github.com/thheller/36332574918b974a3e4996efcb7457d2

idiomancy18:04:06

ahhh, outstanding. that gist is right at the current level of progress I'm working through

idiomancy19:04:43

@thheller can you shed a little light on these arguments? whats the idea behind recursively passing the function into the HTMLElement constructor? (js/Reflect.construct js/HTMLElement #js [] component)

idiomancy19:04:49

I know it was a couple years ago

idiomancy19:04:47

so, I mean, if you happen to remember, that's awesome, but if not I'll figure it out

thheller19:04:11

@idiomancy not sure how current that is but back then it wasn't possible to construct a HTMLElement subclass without actually using class without Reflect

Frank Henard20:04:01

Just curious, does swandonette hang in here anymore?

idiomancy20:04:21

err, huh. okay so its... subclassing in that its using the function from A to build a new instance of C, where A and C are positionally the arguments to construct

john20:04:30

@ballpark Yeah, he's around sometiems

Frank Henard20:04:02

is he still developing on Clojurescript? Also just being nosy

john20:04:31

I've definitely not heard any announcements that he wouldn't be

👍 4
thheller20:04:18

@idiomancy the component argument in the Reflect.construct call specifies the prototype

thheller20:04:13

but that doesn't work for HTMLElement because its a native class. maybe it works nowadays. didn't test this for a while

idiomancy20:04:14

interesting. for me Reflect.construct doesn't work for HTMLElement

(js/Reflect.construct js/HTMLElement #js [] )
=> TypeError: Illegal constructor

thheller20:04:46

you are missing the third arg?

idiomancy20:04:31

the docs I'm looking at say that that's optional. says it will construct a new instance of the first arg unless the third is present

idiomancy20:04:06

I mean fwiw I get the same error when I put my prototype in the third arg

thheller20:04:31

you need all the stuff I had in my example

thheller20:04:37

can't just leave out parts

idiomancy20:04:45

huh, gotcha. I'm hoping to discover some intuitive reasoning behind the choices made in there, but ¯\(ツ)

thheller20:04:13

well the issue is that the browser will call the constructor

thheller20:04:37

so you need the super() call which the js/Reflect.construct does IIRC

idiomancy20:04:13

ahhh, I think I see.

idiomancy20:04:48

the constructor is a function that calls js/Reflect.construct, and that's the whole point

thheller20:04:20

I don't really remember all the details but thats what it took to get a "web component" working back then

idiomancy20:04:44

nice. okay got it. lets you convert a simple form-1 react component into a webcomponent

idiomancy20:04:35

its a start anyway!

wiseman21:04:42

anyone know of good examples/info on using (stuart sierra-style) components in clojurescript?