Fork me on GitHub
#clojurescript
<
2017-05-05
>
puzzler07:05:12

How do you call the "superclass" method of a JS prototype-based inheritance object from Clojurescript? The call I'm trying to make would correspond to: Phaser.Particle.prototype.update.call(this); and I did: (this-as this (.call js/Phaser.Particle.prototype.update this) with no luck.

thheller07:05:20

(this-as this (js/Phaser.Particle.prototype.update.call this))

puzzler07:05:55

Hmmm, that didn't seem to work either. I'm not getting any error, so it's hard to know what's going wrong.

thheller07:05:06

hard to say without more code, why call the prototype in the first place?

thheller07:05:13

seems like you are supposed to inherit from it?

puzzler07:05:42

I have an object, emitter, whose built-in update function is called every cycle to emit particles. I want to override that update with custom behavior (set! (.-update emitter) (fn [] ...custom-behavior... now call regular update function)))

thheller07:05:34

I know nothing about phaser but is emitter the Phaser.Particle instance?

thheller07:05:01

otherwise you'd be calling the wrong update?

puzzler07:05:25

Right, good point. I'll work on that.

puzzler07:05:02

I think I need to set emitter's ParticleClass, and this would be the new update for that, not for the emitter itself.

thheller07:05:42

yeah judging by this you'd need a class

thheller07:05:57

since emitter is a different object

rauh07:05:37

Is there a compiler API that can turn /home/rauh/dev/srs-om/src/cljs/srs_c/components/learn/initial/home.cljs (obtained from &env) into ?

thheller07:05:46

not sure I understand the question? obtained from &env? but probably no

rauh08:05:56

Actually I pick it up from (:file (meta &form)) in my log macro. But it gives me the absolute path. I want to be able to log it into the console with line number (`:line`) so that I can jump to the source

thheller08:05:16

don't source maps take care of that?

rauh08:05:12

Yeah I guess I can log the cljs file, but I'd still need the translated path. I'll check what Chrome makes clickable...

rauh08:05:03

Ok so I'd still need the ?rel=... or ?zx=... parameter to make it clickable. But yeah I'd actually want the .cljs not the .js as I posted above

thheller08:05:36

I don't understand, what is ?rel= or ?zx=?

rauh08:05:14

Yeah that's probably a figwheel question. Cache busters I assume

rauh08:05:45

I guess I can throw an error and get the stacktrace to get the location. But that's pretty ugly

thheller08:05:47

is this what you are talking about?

thheller08:05:04

the browser.cljs:23 is clickable?

rauh08:05:24

Yeah that works fine. But I'm dumping to the console on the click of a log message

rauh08:05:23

It first logs to an array and you can view the messages. Then you can click messages of interest and it'll dump all local bindings, the log message params and filename+line number

rauh08:05:55

Works great with devtools so you can inspect the environment during the log call.

thheller08:05:09

ah you want the location in code not in the console?

rauh08:05:03

Yeah if you dump chrome a http:..... and that's a source file loaded it won't just load the file in a new tab but instead jump to the source in the source panel of the developer tools

rauh08:05:33

Right now I dump the raw filename (`/home...`), which just isn't clickable.

thheller08:05:34

but don't you want the raw filename? why would you ever want to jump to the generated .js?

thheller08:05:00

what is the point of klang? doesn't the devtools console already provide all that?

rauh08:05:48

Yeah but if I logged everything to the console the console would be swamped with messages. So klang just logs to memory and you can then dump the local bindings (which can be many bindings) to the console.

rauh08:05:56

I also want full control over what log calls go into production

rauh08:05:22

So only fatal,error, warn stay in production and then they'll call a function that can report the error.

thheller08:05:18

you can do all that and still use js/console.{log|warn|error} to log?

thheller08:05:43

and the devtools formatters allow expansion of objects on demand

thheller08:05:04

so on click just like yours

thheller08:05:33

but I'm curious: how do you send something to the console that chrome makes clickable as a link?

rauh08:05:05

Yeah kind of, but when I started work on klang many years ago devtools didn't work for me. Now it does 🙂

thheller08:05:07

ah lol .. just the url

rauh08:05:00

so fighweel calls goog.Uri.prototype.makeUnique to cache bust

thheller08:05:09

file:///home/rauh/dev/srs-om/src/cljs/srs_c/components/learn/initial/home.cljs seems to work no?

rauh08:05:12

Yes tried that, but it'll open the file in a new tab.

rauh08:05:21

I want it to jump to the source.

thheller08:05:14

seems like you should be able to create something with some subs and document.location

puzzler08:05:03

It works, but is there a way to do this more elegantly, or is this as good as it gets?

rauh08:05:46

@thheller Anyways... I revived my :trace setting (`(goog.debug.getStacktrace)`) that attaches a full blown stacktrace to every log call. So once that meta data is dumped to the console I can click the entire stacktrace along. Much easier.

thheller08:05:58

(defn ElectroParticle [x y args] (this-as this (js/Phaser.Particle.call this x y args)))

thheller08:05:31

(gobj/extend (.-prototype ElectroParticle) js/Phaser.Particle.prototype #js {:update the-update-fn})

thheller08:05:07

gobj is goog.object

puzzler08:05:27

That's nicer. Thanks.

puzzler09:05:17

When I println an object to console, I just get #object[Object [object Object]]. Is there a handy way to get a more useful printing of the object?

thheller09:05:28

(js/console.log obj) 😉

thheller09:05:44

i never use prn or others in CLJS

puzzler09:05:36

Good to know. BTW, something funny is going on with the gobj/extend version you gave me; some of the properties that should be set by the constructor aren't getting set. Not a big deal since my other version is working, but wanted to see if there's something subtle I'm maybe missing.

rauh09:05:53

(js/console.log "%o" obj) works well with DOM elements and objects

rauh09:05:15

Otherwise js/console.dir also works similar

thheller09:05:53

@puzzler I don't know what phaser expects so can't say much. I use the gobj/extend version for my react components and it works without issues

pseud10:05:41

Anyone using clojurescript for writing back-end (e.g. Node.js) apps ? I haven't really seen an example using Boot or one which actually considered how to have a REPL

vikeri11:05:07

@pseud Check out #lumo

vikeri11:05:41

For the REPL part, not sure about actual backend dev

thheller11:05:57

alternatively just use a node REPL and go from there

pseud12:05:07

@thheller thanks a lot 🙂 I will look into this

petr.myain13:05:32

Hi everyone! I started a new podcast "5 minutes of React" - many of us work with React itself and I think it might be interesting to keep up with React hot news and topics for ClojureScript community, so I share it here. https://5minreact.audio

kommen13:05:26

should the be a way with ClojureScript to use this https://github.com/ianstormtaylor/slate-auto-replace/blob/master/lib/index.js as a foreign lib? I can’t figure out how to provide the type-of dependency…

thheller13:05:17

@kommen dont bother with :foreign-libs imho. use webpack or browserify

thheller13:05:10

which you'll need to do anyways if you want to package that as a foreign lib

thheller13:05:29

hehe it is not that bad

kommen13:05:13

would have hoped to not further introduce complexity into our build pipeline

thheller13:05:25

ah there should be a ./dist/index.js in the npm package

thheller13:05:34

that probably already contains the type-of

thheller13:05:07

well if you use many cljsjs packages the odds are pretty high that your bundle is bigger than it needs to be

thheller13:05:51

dunno I'm currently moving everything off cljsjs and started using webpack

thheller13:05:04

it really isn't that bad

kommen13:05:12

I’m interested

kommen13:05:45

any pointers for resources on how to?

thheller13:05:52

create a bundle.js

thheller13:05:56

var React = require("react");
var ReactDOM = require("react-dom");

window["React"] = React;
window["ReactDOM"] = ReactDOM;

thheller13:05:54

webpack -p bundle.js dist/out.js

thheller13:05:09

include out.js in your package before including the CLJS

thheller13:05:57

add every other thing you want exposed to the bundle.js

kommen13:05:43

that requires an npm step first to have the dependencies installed I suppose?

thheller13:05:58

I'm using yarn but yes

thheller13:05:34

still figuring some things out but so far it seems simple enough

thheller13:05:10

externs are manual though

kommen13:05:37

yeah, I really want to avoid npm if possible, I’ll see if we want to use yarn

kommen13:05:06

thanks for your insights!

honzabrecka13:05:54

Did anyone try to compile lein project with javasctipt modules using cljsbuild? Does cljsbuild support javascript modules feature?

spinningtopsofdoom13:05:04

The ClojureScript compiler supports JavaScript modules (either Common JS or ES6 variety) with the :foreign-libs compiler option (https://clojurescript.org/reference/compiler-options#foreign-libs). You'll just need to add that option to your cljsbuild profile.

pesterhazy16:05:41

Coming from boot, I'm wondering lein-figwheel has an option to emit an audible signal or a visual clue (say, in the taskbar) if there's a clojurescript compiler warning or error

pesterhazy16:05:05

The context is working with react-native, where the On-Screen Display doesn't always show reliably

zacanger17:05:00

I'm not sure what the "right" way to do that would be, but you could do something hacky like

while inotifywait -q -e modify figwheel_server.log >/dev/null
do
  zenity --info --text "$(tail figwheel_server.log)"
done

zacanger17:05:18

There's probably a better way, though :$

pesterhazy17:05:49

haha not a bad idea

pesterhazy17:05:09

I'm totally going to try this 🙂

qqq18:05:06

since js only has 1 thread, can an errant go block nuke an entire app ?

dnolen18:05:03

@qqq if that go block has an infinite loop yes (and doesn’t have any chances to block)

ag18:05:53

I’m using latest clojurescript in the project with clojure 1.8. Is there a function in CLJS that can transform new namespaced maps into “old” syntax?

jr18:05:30

you mean the print method?

qqq18:05:59

@dnolen : suppose I want to instrument a function to say: run this function for 100ms, kill it if it does not complete; is the only wan to do this to insert the check in the function itself?

ag18:05:29

@jr my problem is when I evaluate something with CIDER, something that comes from cljs side and has new map syntax, I can’t format it using cider-format-edn, because it uses Clojure. and the Clojure version available to cider is 1.8. So, I need something that can translate new map syntax to old map syntax

ag18:05:00

so I can format it to readable form

dnolen18:05:24

@qqq that’s not possible with or without core.async

anmonteiro18:05:36

@qqq is that Node or the browser?

anmonteiro18:05:11

if you’re running in Node, there’s a V8 API to interrupt evaluation. Lumo 1.4 shipped with the ability to kill infinite loops at the REPL thanks to it

Alex Miller (Clojure team)18:05:14

@ag there is a flag *print-namespace-maps* that can turn that printing style on and off btw

ag18:05:05

alexmiller: oh… awesome! now I need to find a way to make cider respect it

Alex Miller (Clojure team)18:05:28

(set! *print-namespace-maps* false) ?

Alex Miller (Clojure team)18:05:28

I’m not sure if that works in cljs

qqq18:05:52

@dnolen @anmonteiro : I should have clarified. This is the browser. Chrome in particular.

qqq18:05:19

Can "webworker" threads be killed by it's parent, or do they also have to terminate on their own ?

john06:05:15

qqq: You can launch and terminate and communicate with web workers. But you can't interrupt the currently running logic of a synchronous context running within the worker.

darwin18:05:03

@qqq I believe if all the code is under your control, you could wrap all functions potentially called from that root function into core.async go blocks and then write your own “interruptible” dispatcher: https://github.com/clojure/core.async/blob/master/src/main/clojure/cljs/core/async/impl/dispatch.cljs

darwin18:05:01

or of course you can do that wrapping selectively, just for hot paths, depends

darwin18:05:35

ah, forget my post, that core.async won’t work for tight infinite loops as dnolen correctly pointed out, those won’t be broken as core.async tasks

dnolen18:05:34

I just changed cljs.spec to cljs.spec.alpha now would be a good time to try master - would like to cut a release for this

darwin19:05:56

@dnolen just tested master clojurescript with my lib[1] using spec both in clojure and clojurescript, and I confirm it started to work again: https://github.com/binaryage/cljs-oops/tree/spec-ulation

ag20:05:44

Can anyone tell me why:

cljs.user> (set! *print-namespace-maps* false)
false
cljs.user> *print-namespace-maps*
true
upd: it seems I have to do something like this:
(binding [*print-namespace-maps* false]
             (pprint x))

mfikes22:05:51

@ag I can’t repro what you are seeing.

$ java -jar cljs.jar -m cljs.repl.node
ClojureScript Node.js REPL server listening on 53388
To quit, type: :cljs/quit
cljs.user=> *clojurescript-version*
"1.9.521"
cljs.user=> (set! *print-namespace-maps* false)
false
cljs.user=> *print-namespace-maps*
false

ag22:05:44

@mfikes [org.clojure/clojurescript “1.9.521”] ?

mfikes22:05:01

Yes, that is using the cljs.jar you can download

ag22:05:07

oh, right

ag22:05:56

could it be nrepl thing?

mfikes22:05:15

Dunno. The set! call compiles to cljs.core._STAR_print_namespace_maps_STAR_ = false which really has no choice but to work. 🙂

mfikes22:05:43

Perhaps you are onto something… that would be a dynamic var that should be isolated to a REPL session.