Fork me on GitHub
#clojurescript
<
2016-03-25
>
martinklepsch11:03:29

@domkm: you can use js* 😛

slotkenov11:03:38

Anybody seen this exception:

java.lang.IllegalStateException: Can't change/establish root binding of: *cljs-repl-env* with set

slotkenov11:03:00

I start a repl with boot repl and then in the repl I call (start-repl)

slotkenov11:03:27

Using adzerk.boot-cljs-repl library for that

slotkenov11:03:00

Maybe I should ask this in the Boot channel… simple_smile

martinklepsch11:03:49

@slotkenov: you need to start the repl server using the cljs-repl task then in a client boot repl --client you can call (start-repl)

slotkenov11:03:22

ahh, I forgot the -c option for boot repl. Didn’t know that was mandatory for the cljs-repl

slotkenov13:03:52

I can get the closure compiler to pick up an object, but not any properties inside that object My externs file goes like this:

var api = function() {};
api.get = function(limit, offset, callback) {};
api remains in the advanced optimized code, but get gets scrambled.

slotkenov13:03:36

By the way: you always need an externs file for any external library? Or am I missing something?

darwin13:03:23

here I use it in a generated library to side-step externs complexity: https://github.com/binaryage/chromex#advanced-mode-compilation

slotkenov13:03:26

Ah, yeah, I knew that, thanks. But thats kind of hackish I’d say

slotkenov13:03:04

Didn’t know that library 😉

darwin13:03:19

would be great to have some tool/framework to generate externs files somehow

darwin13:03:25

until then I will use string names, it might increase :advanced build sizes and slow down javascript property lookups a bit, but it is not an issue in many scenarios, for example if the api is not called too often or file size is not that big deal

darwin13:03:54

you could use something like this to make calling code look just fine when accessing props by string names: https://github.com/binaryage/chromex/blob/master/src/lib/chromex/support.clj#L5-L26

slotkenov13:03:15

@darwin: Nice, thanks for pointing this out

thheller14:03:45

@darwin did you by any chance try these externs?

thheller14:03:05

look fairly complete to me, although I barely use any of the chrome stuff yet

darwin14:03:37

thanks for pointing that out, last time I checked I found some incomplete externs in closure lib, updated by hand

darwin14:03:00

this could be usable if it was really generated directly from chromium sources

darwin14:03:44

I might eventually support a compilation switch for chromex, to emit non-string property access code, and people could use something like this if they preferred

darwin14:03:53

but right now string access just works(tm), I don’t want to hear from people messing with outdated externs files / using them incorrectly

thheller14:03:57

yeah externs can be painful

darwin14:03:20

chrome api calling code is produced through this generator, I would just make this line configurable, and instead of oget I would generate there normal js-interop access https://github.com/binaryage/chromex/blob/master/src/lib/chromex/wrapgen.clj#L70

darwin14:03:47

and similar

octahedrion15:03:08

suddenly I'm getting "Invalid :refer, var does not exist in file" errors when I compile incrementally, but if I compile from scratch all is well

domkm16:03:57

@darwin: Awesome! Thanks!

domkm16:03:39

@martinklepsch: That might just work! I'll give it a shot later. Thanks.

domkm17:03:09

@martinklepsch: js* works but compiler options :language-in :ecmascript6 :language-out :ecmascript3 isn't compiling class declarations

domkm17:03:38

@martinklepsch: Nevermind. It works with simple optimizations (and, presumably, advanced as well) 😄

josh.freckleton19:03:42

@chrisoakman: You sir, are a saint. I spent so long beating my head against this! However, (.focus js/window) still doesn't focus. Even if I run that straight in the figwheel REPL. Any idea why not? (it does however work if it's straight javascript...)

chrisoakman19:03:28

I'm not familiar with window.focus() generally

chrisoakman20:03:01

although the code I posted on that SO thread compiles down to return window.focus(); directly (the return because it's the last expression in that function)

base69820:03:51

I have a build:

{
              :builds {:prod
                       {:id "prod"
                        ; The path to the top-level ClojureScript source directory:
                        :source-paths ["src-cljs"]
                        :figwheel false
                        ; The standard ClojureScript compiler options:
                        ; (See the ClojureScript compiler documentation for details.)
                        :compiler {
                        :output-to "resources/public/main.js"  
                        :asset-path "out"
                        :main "tanks.core"
                        :optimizations :advanced}}
                       :dev {:id "dev"
                        ; The path to the top-level ClojureScript source directory:
                        :source-paths ["src-cljs"]
                        :figwheel true
                        ; The standard ClojureScript compiler options:
                        ; (See the ClojureScript compiler documentation for details.)
                        :compiler {
                        :output-to "resources/public/main.js"  
                        :asset-path "out"
                        :main "tanks.core"
                        :optimizations :none
                        :pretty-print true}}}}

base69820:03:03

figwheel seems to be loaded

base69820:03:08

in the prod build

base69821:03:22

weird, just deleting the out file worked

josh.freckleton21:03:44

@chrisoakman: hm... window.focus() should force the browser to jump to that window/tab automatically. It works just fine in js. I'm traking the problem, and here's an insight. Run the following code:

(do (js/alert "an alert")
    (.focus js/window)
    (.log js/console "console log"))
and notice that the console.log works, but neither of the other lines. I could see the non-functioning lines being used for spammy purposes, and so maybe the browsers are inhibiting them some way? How do I get around this?

josh.freckleton21:03:47

EDIT: ah weird, I just closed that tab, and re-opened it, and now alerts work, but not focus...

chrisoakman21:03:38

@josh.freckleton: I'm not sure about window.focus(); my gut says it's not a CLJS thing though

chrisoakman21:03:07

given the context you've shared here

josh.freckleton21:03:56

@chrisoakman: I'll get it, thanks for all the help simple_smile

chrisoakman21:03:21

you're welcome; anytime simple_smile

josh.freckleton21:03:45

@chrisocowan: if you're curious at all, I think I've found out that window.focus only works if it's from a user-initiated action. For some reason, there's something about your (awesome) cljs code you helped me with which makes it think that notification clicks aren't user initiated. The following works, and I just need to convert to proper cljs now:

(do (js* "

Notification.requestPermission(function (permission) {
  if (permission !== 'granted') return 'false';

  var notification = new Notification('Here is the title', {
    icon: '',
    body: 'Some body text',
  });

  notification.onclick = function () {
    window.focus();
    return 'true';
  };
});"))

josh.freckleton21:03:48

wait, false alarm, it's broken again...

josh.freckleton21:03:57

hrm, it looks like in order for the focus to work, some chrome tab needs to have focus when I click on the notification. If not, nothing happens until I click on a chrome tab, and then the notification. Weird.