Fork me on GitHub
#clojurescript
<
2018-08-05
>
colinkahn02:08:57

I'm trying to import an es6 javascript module using the instructions here: https://clojurescript.org/guides/javascript-modules When I did I got the following error: Uncaught SyntaxError: 'super' keyword unexpected here I reduced it to a simple test case with the following:

export class Greeter {
  constructor(subject, salutation) {
    this.subject = subject;
    this.salutation = salutation;
  }

  greet() {
    console.log(`${this.subject} ${this.salutation}!`);
  }
}

export class HelloWorld extends Greeter {
  constructor() {
    super("Hello", "world");
  }
}
I couldn't find anything on the Google Closure GitHub issues about issues with super so I thought I'd post it here to see if anyone could help.

llsouder02:08:51

parsing some text loaded by a web page. After 2 days I figured out that the strings are NOT java strings but javascript strings and so lots of clojure stuff I do isn't working.

llsouder02:08:38

Is it safe to say that clojure.string/xxxxx is going to behave correctly?

lilactown02:08:33

@llsouder clojure.string is completely cross-platform. there’s occasionally little idiosyncracies but it’s very much corner cases

lilactown02:08:15

:thinking_face: @colinkahn are you getting that error at compile time or in the browser?

colinkahn02:08:03

in the browser, from what I can tell the compiled code turns the constructor of the class into a normal function and the super call is no longer valid within it

colinkahn02:08:02

let HelloWorld$$module$src$js$hello = function() {
    super("Hello", "world")
};
I shortened the variable it outputs, but that's what the compiled result where the syntax error occurs

lilactown02:08:44

and you have the :module-type set as :es6?

colinkahn03:08:20

:foreign-libs [{:file "src" :module-type :es6}]

skrat13:08:43

anyone using Datascript with function bindings? I can't get it working

skrat13:08:45

ah, got it, gotta pass them in query inputs

mfikes14:08:27

@colinkahn I haven’t looked at what is going on above, but ClojureScript master has a revision to update to the latest released Closure Compiler. Also, you can specify that version by explicitly overriding that dep in your project.

colinkahn15:08:48

@mfikes awesome, overriding worked, thanks!

daviwil15:08:55

Apologies for the noob question: In ClojureScript, what's the correct pattern for defining two functions that call each other? I'm trying to do this now but getting a compiler error that the second function is not defined when it is called in the first function because the compiler hasn't reached that point in the file yet

daviwil15:08:01

The context here is that I'm writing a tree component with Reagent where there can be different types of tree nodes, using a render-node function to decide which actual render function to use based on the tree node type

lilactown15:08:33

you can declare the function-name before you defn it

daviwil15:08:15

Thanks @lilactown! That seems to have worked 🙂

👍 4
hmaurer16:08:18

By the way @daviwil, this is called “mutual recursion”; it might make it easier to search for it 🙂

mario-star 4
daviwil16:08:51

Thanks! I'm aware of the terminology and searched for that but didn't find any answers, thus I came here 😉

hmaurer16:08:47

@daviwil if you don’t find any answers for a question like this in clojurescript, try clojure; afaik all of these things should behave similarly, and so have the same solution

daviwil16:08:22

Yeah, I wasn't sure if this was one of the subtle differences between Clojure and ClojureScript but I'll try that next time

hmaurer16:08:55

Not trying to discourage you to ask here mind you; I do so all the time. Just a tip in case you want a quicker solution 🙂

daviwil16:08:08

Much appreciated!

john16:08:27

Hey folks, I've got some example code over in #architecture about managing memory over SharedArrayBuffers in CLJS. It's sort of a garbage collection problem. Anybody built a slab allocator before?

kwladyka16:08:43

Hi, I am thinking about make small module (100 lines?) to simplify use form validation messages for user. Like error should appear after user touch / lost focus the required field not before. It matters especially about empty fields. Errors messages based on spec validation. In this examples I use simple messages, but it could also look like:

{::sc/email "Typo? It doesn't look valid."
::sc/password "Password is required."
::sc/password-difficulty "Too easy"
::sc/password-length "Too short"}
Does it make sense? Would you like to use it? Maybe solution like this already exist? I didn’t find one.
(defn log-in []
  (let [specs->msg {::sc/email "Typo? It doesn't look valid."
                    ::sc/password "Password is required."}
        names->spec {:email ::sc/email
                     :password ::sc/password}
        names->value (r/atom {:email ""
                              :password ""})
        form (form/init-form names->value names->spec specs->msg)
        value->form (form/fn-value->form form)
        name->touched (form/fn-name->touched form)
        form-valid? (form/fn-form-valid? form)]
    (fn []
      (let [email-error? (form/show-error? form :email)
            password-error? (form/show-error? form :password)]
        [:div
         [:form
          [mui/text-field
           {:on-change value->form
            :on-blur name->touched
            :error email-error?
            :helper-text (if email-error?
                           (form/get-error form :email)
                           " ")
            :name "email"
            :label "Email"}]
          [mui/text-field
           {:on-change value->form
            :on-blur name->touched
            :error password-error?
            :helper-text (if password-error?
                           (form/get-error form :password)
                           " ")
            :type "password"
            :name "password"
            :label "Password"}]
          [:div
           [mui/button
            {:variant "raised"
             :color "primary"
             :on-click #(when (form-valid?)
                          (re-frame/dispatch [:log-user @names->value]))}
            "Log in"]]]]))))

genekim16:08:57

I’m embarrassed about this newbie question — but I just upgraded to ClojureScript 1.10.339 (to try out Ghostwheel by @clojurians.net!) and now I’m get a bunch of type inference errors for functions like GetElementByID and preventDefault. What is the best way to get definitions of all these functions? (or maybe I should broaden the question to: “how do I make all these warnings go away?” 🙂 Thanks in advance!!!

Cannot resolve property getElementById for inferred type js/HTMLDocument in expression

Ex: (.getElementById js/document "app")

Cannot infer target type in expression (. event preventDefault)

Ex: (.preventDefault event)

TC17:08:27

Hello everyone 👋 I’m trying to get a Clojure linter into VSCode and am using Calva. Has anyone encountered this error (or know how to interpret it?)

Caused by: java.lang.IllegalStateException: Attempting to call unbound fn: #'nrepl.middleware/set-descriptor!
I followed these directions https://shadow-cljs.github.io/docs/UsersGuide.html#_calva_vs_code and encountered the error upon adding [cider/cider-nrepl] to my dependencies.

TC17:08:07

my best guess: I didn’t have my server running (I restarted it to add this dependency) and it looks like the middleware trips because it expects the nrepl to be up already.

thheller17:08:09

@UC2FSP5KK cider-nrepl is in a weird spot currently due to some breaking changes in the upgrade to nrepl 0.4

thheller17:08:18

which version of cider-nrepl are you using?

TC17:08:21

is there a place I can look for the “last working version”?

thheller17:08:05

you can downgrade shadow-cljs to 2.4.24 which should still work with the old cider release

💯 4
thheller17:08:16

I don't think a new cider-nrepl release was released just yet

TC17:08:58

awesome thank you @U05224H0W I’ll try it out

TC17:08:55

Whoa my shadow-cljs version is 2.3.30. Looks pretty behind.

TC17:08:10

That did it!

genekim17:08:15

Many moons ago, I added to certain namespaces (set! *warn-on-infer* true) to detect extern errors (things that would get minimized away by the Closure compiler). Getting warnings on getElementById and preventDefault didn’t happen with ClojureScript 1.9.946. Thanks!

justinlee17:08:00

@genekim you need to typehint event. in shadow you’d just do ^js event — i’m not sure how it works with the standard compiler

genekim21:08:35

Alas, @lee.justin.m, adding ^js event typehint does not make the warnings go away in the standard CLJS compiler. 😞 Thanks, though!

justinlee21:08:37

Sorry @genekim this is much easier in shadow-cljs

justinlee21:08:01

I think you need to give it a real type like ^js/Object event or something

justinlee22:08:21

you should probably post on stackoverflow. someone will definitely have an answer for you

justinlee17:08:04

the other warning is new to me

genekim17:08:55

Ooh... got it! I’ll give it a try tonight! Thanks @lee.justin.m !!!