Fork me on GitHub
#clojurescript
<
2016-06-08
>
fasiha06:06:56

I was crashing into http://dev.clojure.org/jira/browse/CLJS-536 but per dnolen's note there, I learned about extend-type and got the following snippet to get clj->js to retain namespaces in keywords. Is this a reasonable way to do so?

(extend-type Keyword
  IEncodeJS
  (-clj->js
    [kw]
    (str (namespace kw) "/" (name kw))))
I guess I could alternatively have used (subs (str kw) 1)?

dnolen14:06:14

@fasiha: in apps sure that’s fine - just don’t do that kind of thing in a lib

fasiha14:06:54

Ah. Understood @dnolen. I'm stuffing EAVT tuples into a "regular" database (RethinkDB) as JSON and was confused why my attributes were coming out naked and un-namespaced.

dnolen14:06:29

right, converting to JS is inherently lossly - so that’s why we have knobs

dnolen14:06:36

no way to know what anyone is actually going to want to do

dm314:06:00

what's the proper way to specify an extern for (let [c (.-Constructor (js/require "module")), o (new c)]) ?

dnolen14:06:41

the simplest way

dnolen14:06:11

Object.Constructor = function() {};

dm314:06:47

ah, thanks!

dm314:06:56

then when you call (.someFn o), you need Constructor.prototype.someFn = function() {};, right?

dnolen14:06:12

if Constructor is a type

dnolen14:06:09

/* @constructor */ Object.Constructor = function() {};

dnolen14:06:28

or something like this, really the Google Closure compiler docs are the place to look

dnolen14:06:41

externs files are just Google Closure annotated files without any code in the bodies

dm314:06:01

ok, I see

dnolen14:06:28

and yes, if you’ve defined Constructor, then you define the methods as you’ve described

fasiha18:06:58

Idea: Slackify http://clojuredocs.org, so any library can get its own version of clojuredocs with its functions & docstrings and where people can post examples and add "see also"s.

jasonjckn19:06:49

I want to extend a javascript react class with a IFn interface so I can invoke it

jasonjckn20:06:03

can't quite figure out how to extend this javascript class with IFn, tried a few things

jasonjckn20:06:16

e.g.

(specify FooT
  IFn
  (-invoke [this a] :yay))

rohit20:06:19

@jasonjckn: i think you are almost there. it should be extend-type instead of specify.

potetm21:06:25

Okay, taking a shot in the dark here.

potetm21:06:40

When starting up a cljs repl, I'm getting goog is not defined and clojure is not defined.

potetm21:06:11

The namespace has loaded up properly, (e.g. I can (js/console.log "HELLO") in the cljs file and see it show up in my console), but the initial payload of the repl results in goog is not defined.

dnolen21:06:48

@potetm: sounds you haven’t configured :asset-path for whatever makes for your web server setup

dnolen21:06:11

looking at the Network panel of any browser devtools should show you that no sources could be loaded

potetm21:06:07

So, I'm getting 200s for all of my js files. It's the repl eval that causes the error. (I actually have only 200s in my network panel.)

potetm21:06:44

Do I need to set :asset-path on the repl or repl-env?

jasonjckn21:06:28

@rohit: i got it working but then the google closure compiler emitted warnings about invalid arity

rohit21:06:59

@jasonjckn: could you share some code?

meowy21:06:24

@potetm Can you create a minimal example?

jasonjckn21:06:55

@rohit:

(defui Foo 

  static IFn
  (-invoke ([this a b] :yay))

  Object
  (render [T]
          (div (str "Foo props: " (prn-str (om/props T))))))

(js/console.log (Foo 3 4))
the code works as expected, but when i edit the source file and figwheel reloads it I get an error

jasonjckn21:06:04

wrong number of arguments passed to Foo

jasonjckn21:06:15

Figwheel: Compile Warning - Wrong number of args (2) passed to admin.ui/Foo at line 23 /Users/jason/d/play/admin/src/client/admin/ui.cljs

potetm21:06:19

@meowy: Working on it now.

arohner21:06:06

anyone have success loading figwheel to an already loaded page? I’m running into ‘can’t document.write after the page is fully loaded' errors

arohner21:06:17

alternatively, getting the plain browser repl to work over SSL?

rohit21:06:26

@jasonjckn: i gotta call it a night. its kinda late here. will check it in the morning. sorry about that

jasonjckn21:06:39

no sweat, thanks for your help @rohit night

potetm22:06:07

Is there any chance that a repl working dir can get into a bad state and cause those goog is not defined errors? cc: meowy

potetm22:06:29

Running (browser/repl-env :optimizations :none) does it for me.

potetm22:06:50

Once that's been run, it doesn't appear to ever recover either.

potetm22:06:09

It appears that all that matters is what's run first. If the first run does not include :optimizations :none, then it connects successfully and will connect successfully on subsequent runs, not matter what optimizations are later specified.

potetm22:06:34

If the first run uses :optimizations :none it will never successfully connect.

potetm22:06:51

Is this the expected behavior, or should I file a ticket for this?

potetm23:06:43

Oh I forgot, the whole thing is loaded in an iframe, so it has to reload all of the code.

potetm23:06:23

So :optimizations :none can only work if you've specified a :main, because otherwise it expects you to load yourself goog/base.js first.

potetm23:06:00

But, unfortunately, the browser repl env only allows you to pass in :optimizations and :output-dir into the initial compile.