Fork me on GitHub
#clojurescript
<
2018-02-19
>
martinklepsch09:02:42

Is this a valid use of externs inference?

(def ^js/SomeThing thing js/SomeThing)
I’d find something like this most common and think I’ve seen it somewhere before, yet none of the docs have this kind of example.

thheller09:02:57

In that particular example the typehint is inferred by js/SomeThing itself so it is redundant

thheller09:02:05

assuming you have :infer-externs enabled

thheller09:02:55

but yes it would be a valid use

martinklepsch09:02:12

Oh so (def thing js/SomeThing) would also have an implicit ^js/SomeThing type hint?

thheller09:02:01

it should have yes

rauh09:02:47

@martinklepsch Anything js/... will get added to the externs.

sumit10:02:19

How can i go to some route without using # in secretary? currently i am able to route to a path like localhost:3449/#home but i would like it to be localhost:3449/home Any ideas? I am using Reagent & referred this link from reagent cookbook https://github.com/reagent-project/reagent-cookbook/tree/master/recipes/add-routing Thanks

robert-stuttaford10:02:26

@kumar1993sumit15 you want goog.history.html5history which uses pushState

koala punch10:02:52

hi, i’ve not tried yet, but you could look at bidi for routing plus the pushy library

sumit10:02:46

@robert-stuttaford hey thanks for the reply i'll try it out see if i can make it work @christopher.paul thanks for the tip i'll look into it when i get the time

justinlee16:02:38

@kumar1993sumit15 It is much easier to just install https://github.com/venantius/accountant It just takes a few lines of config and html5 history will be working like a charm.

martinklepsch16:02:03

Having some weird issues with goog.date.relative:

(goog.date.relative/format (- (.getTime (js/Date.)) 300))
Shouldn’t this return “5 minutes ago”?

mfikes16:02:59

@martinklepsch Havent't looked into whether right or wrong, but the argument appears to be in milliseconds

(goog.date.relative/format (- (.getTime (js/Date.)) 300000))

martinklepsch17:02:12

@mfikes thanks that was part of the issue I had. the other part is that goog.date.relative/format returns an empty string for dates older than 2 weeks 😄

mathpunk19:02:10

I think I'm misunderstanding how a self-hosted ClojureScript project is structured & run. The tests that I run with lein tach lumo work fine, but when I try and run my core file with lumo src/sherman/core.cljs, the namespace I'm requiring is not found. Project is here: https://github.com/mathpunk/sherman

mathpunk19:02:33

My hypothesis is, running a file with lumo is different than lein run because lein knows all about the project from looking at the project.clj, and lumo is perhaps not doing that

mathpunk19:02:42

I've just tried putting in a :main sherman.core line into my project.clj, but that gives lein the impression I've got a Clojure namespace by that name, and I've got only a ClojureSCRIPT namespace

manutter5119:02:47

Lumo has a -c arg for classpath, but I confess I haven’t used lumo, so I’m just passing on what I’ve heard about

mathpunk19:02:05

I see... so it has finally come time for me to learn what a classpath actually is 🙂

mathpunk19:02:39

I don't quite understand the brief descriptions of the command line options. When I figure this out, I'd like to expand the documentation a little: https://github.com/anmonteiro/lumo/blob/site/docs/RunningLumo.md

mathpunk19:02:39

I tried adding a -main function to sherman.core and running lumo -c src -m sherman.core, but no dice

manutter5119:02:57

The -c needs to be followed by a list of directories containing the files you're trying to require in your cljs, but I'm not sure what the format for that is

manutter5119:02:42

Try lumo -c #(lein classpath) -m sherman.core

manutter5119:02:15

lumo -c $(lein classpath) -m sherman.core

manutter5119:02:37

I'm regurgitating an answer I saw elsewhere, so that may or may not work

mathpunk20:02:05

hey that works!

mfikes20:02:45

@U0E9KE222 If it helps, most of the material describing Planck is applicable to Lumo. Planck has an extensive user guide here http://planck-repl.org and talks about -c in the dependencies section.

mathpunk20:02:31

@mfikes That helps greatly, thank you

richiardiandrea21:02:11

Also writing a comment for pushing the PR on lumo forward is a good idea. I wonder if at some point we should have a common doc for lumo and planck at least for the basics

Lachlan Robertson22:02:55

Does anyone know how to get the following spec stuff - written in CLJC - to work in CLJS?

(defmacro opt-keys-spec [spec-name opt-keys req-type req-key]
  (let [keys (eval opt-keys)]
    `(s/def ~spec-name (s/and
                         #(contains-opt-keys? 1 % ~opt-keys)
                         (s/keys ~req-type [~req-key]
                                 :opt ~keys)))))
It works in CLJ but fails because eval doesn’t work/exist in CLJS and it’s doing my head in :< Maybe looking for an alternative to eval or a CLJS-specific way to do it? Any help would be greatly appreciated, thanks in advance.

mfikes22:02:58

@lachlan737 For JVM-ClojureScript, the macro would be in a Clojure file, and eval is available at macroexpansion time. Note that in your macro, eval is not in the syntax-quote portion. In other words it is called at expansion time (in Clojure).

mfikes23:02:13

FWIW, that macro expands for me.

cljs.user=> (require-macros 'foo.core)
nil
cljs.user=> (macroexpand '(foo.core/opt-keys-spec ::abc :a :req :rk))
(s/def :cljs.user/abc (s/and (fn* [p1__426__427__auto__] (foo.core/contains-opt-keys? 1 p1__426__427__auto__ :a)) (s/keys :req [:rk] :opt :a)))

mfikes23:02:11

If on the other hand you are in self-hosted ClojureScript, then it is generally possible to define your own eval and then make use of it. FWIW, both Lumo and Planck do that to satisfy the need for eval in this macro: https://github.com/clojure/clojurescript/blob/f55b19b89e98a210a89151f52e67567108c536cf/src/main/cljs/cljs/spec/test/alpha.cljc#L113