Fork me on GitHub
#clojurescript
<
2017-07-19
>
qqq00:07:10

is there a way to extend hiccup by adding new keywords?

qqq00:07:44

I want to add something like :my-widget so that when hiccup sees :my-widget, it calls a function (my-widget-render ...) to compute the hicup forms to render

bellp00:07:43

ClojureScript is 1.9.x while Clojure is 1.8.x. Does that mean cljs is using a different version scheme or they’re jumping ahead of Clojure?

danielcompton00:07:03

@bellp CLJS has a different version scheme

danielcompton00:07:22

it usually goes to 1.9.0 at the same time/feature parity as Clojure 1.9.0

bellp00:07:53

Does ClojureScript have any templates for a hello world app with tests setup?

jsselman20:07:36

This isn't a template, but this screencast was invaluable for me when learning how to set this all up.

bellp00:07:02

Something to just get your foot in the door? I’ve been spending the last 2 days trying to follow several tutorials and it’s crazy how many steps there are. And my app doesn’t yet compile 😕

beders00:07:13

I just tried out re-frame which includes the todomvc example and super simple setup.

beders00:07:46

git clone lein do clean, figwheel

beders00:07:13

that should get you up and running

stuartrexking01:07:05

Is there a nice way to preserve namespaces when using clj->js?

stuartrexking01:07:07

Or is anyone aware of a function / lib that will do so?

mikethompson01:07:20

@bellp perhaps the templates mentioned in the ExternalResources section of the docs?

stuartrexking05:07:50

When I use clojure.spec.alpha/explain and pass it a spec and a value, it’s validating all specs in the registry, not the spec I passed it. The spec is namespaced but it’s not the behaviour I expect. Am I missing something?

stuartrexking05:07:34

Here is an example. I’m clearly passing in one namespaced spec, but it’s explaining another. https://www.dropbox.com/s/t9dk2nxnftm34ya/Screenshot%202017-07-19%2015.59.34.png?dl=0

stuartrexking06:07:13

If I just use a map literal and not the re-frame app-db atom, I get success https://www.dropbox.com/s/x7p299qgqg42daj/Screenshot%202017-07-19%2016.23.17.png?dl=0

stuartrexking06:07:02

@mikethompson could the above have something to do with re-frame.db/app-db?

rauh06:07:02

@stuartrexking Spec will always check all map keys against the spec, even if you didn't specify it.

stuartrexking06:07:52

@rauh Didn’t specify it where?

stuartrexking06:07:34

My spec specifies one key, my map has many, including the key in the spec. Why would it check against keys not in the spec?

stuartrexking06:07:03

Surely it should just ignore those? Why bother including the spec as an argument to explain then?

stuartrexking06:07:14

If it’s just going to check them all.

stuartrexking06:07:00

@rauh Just tested that and you are right. Doesn’t make sense to me though. Why bother including a spec in the calls to valid?, explain, etc

rauh06:07:35

Yeah this has been discussed countless times in the spec channel. It's pretty confusing. Though it is documented in the spec guide.

rauh06:07:57

Personally I don't like it, but it is what it is. 😕

stuartrexking06:07:37

Yowzers. That’s confusing. Ok, I’ll work with it.

osmirnov09:07:13

Hi all, I'm trying tor require npm deps in my reagent app with :npm-deps feature in deps.cljs, but when I add (:require [npm-lib]), I've got Uncaught ReferenceError: require is not defined from this lib on client side, how to fix it?

martinklepsch13:07:11

@osmirnov full :npm-deps integration isn’t yet released I think

mikerod13:07:42

In cljs doing some interop with a JS foreign lib. I ran into a situation like this:

(let [foo (js/somelib.require "foobar")]
  (new foo.FooBar))
Basically, this lib is just doing a polyfill for modules and has it’s own somelib.require. I don’t think that is particularly important though. The basic idea is that a JS function returns a JS object. That object holds a function that is actually a constructor function and needs to be invoked via new. Sort of like
foo = {"FooBar": <ctor function>}
I had it working with :optimizations :none, but it is failing with :advanced. I get an error like this at runtime:
Uncaught TypeError: $foo__$1_this$$jscomp$174$$.$FooBar$ is not a constructor
So it looks like the symbol FooBar is be “munged” in some way. Just curious of something is obviously wrong with how I’m trying to do interop here? It’s a bit tricky to search for how to call new in cljs in situations like this.

mikerod14:07:59

@mfikes I’ve read about these. I didn’t see this as an externs problem. I’m probably incorrect.

mikerod14:07:05

The name isn’t shortened either

mikerod14:07:09

it just gets $ around it

mikerod14:07:28

Also, I was wondering if there was an approach with extern inference here too, but had no luck there (just to try to understand how this is working)

mikerod14:07:42

the only problem with the gen code is the $FooBar$

mikerod14:07:45

the rest is correct

mfikes14:07:47

Do you have :pesudo-names set to true?

mikerod14:07:08

ugh… yes… I forgot

mikerod14:07:15

I bet that explains what I’m seeing…

mfikes14:07:24

That would explain why names don’t seem to get shorter.

mikerod14:07:32

Dang, thanks. Sorry for the dumb question then

mfikes14:07:40

No problem

mfikes14:07:15

If you are curious about externs inference https://clojurescript.org/guides/externs

mikerod14:07:21

Yeah I couldn’t figure out how to use an type hint on this one

mikerod14:07:42

perhaps a return type hint and put some wrapper functions

mikerod14:07:54

I will think about it and see if I can make sense

lsenta14:07:25

Hi #clojurescript, speaking of externs & js modules: I'm checking out electron, I can e = require('electron') in my window, how should I do this in a cljs file?

lsenta14:07:17

js/require? would it work with advanced compilation?

mikerod15:07:18

@lsenta I believe it is similar to what I did above:

(let [e (js/require "electron") ...] ...)

mikerod15:07:31

but you may be looking for more in terms of having the dependency around etc

spinningtopsofdoom15:07:41

If you're willing to wait a bit you can put it in your build e..g.

:npm-deps {:electron "<version number>"}
and then call it just like any other ClojureScript namespace
(ns my-ns.foo
  (:require [electron :as e] ))
This is in ClojureScript master right now and not in any official release

spinningtopsofdoom15:07:00

See the link that mikerod put above for more information

lsenta15:07:33

@mikerod @spinningtopsofdoom I use the http://descjop.org template, it deals with packaging the code & modules, so I should be able to avoid using the npm-deps option (looks pretty cool though!). If I go for the (js/require ....) way, the minute I call: (.BrowserWindow e) it'll break with advanced optimisation right?

mikerod15:07:05

@lsenta yeah, you’ll have to do the whole externs thing to avoid that

mikerod15:07:20

Which is basically the same thing the issue I discussed above was about

mikerod15:07:41

except I just had a weird access case that I mistakenly thought wasn’t about externs 😛

lsenta15:07:03

Thanks @mikerod, I'm looking into this

lsenta15:07:42

something doesn't compute in my mind, I have an extern that declares var TopLevel = {"electron": ..., etc} and the closure compiler is going to figure out that the result of js/require maps back to this declaration?

mikerod15:07:48

@lsenta that is a good question. With “externs inference” (alpha feature in link shared above), I could see using a return-type hint perhaps, but other than that I don’t know

mikerod15:07:02

Or I mean a type hint of some sort, doesn’t have to be ret type

mikerod15:07:25

I’m not the definitive source to go to on this though. I’m still fighting through nearly this same topic currently hah

lsenta15:07:17

It worked, thanks for the details @mikerod and @spinningtopsofdoom! I'm still quite surprised by closure figuring out the externs. what if I'd (def x (js/require (if (random) "a" "b"))) 🙂

mikerod16:07:08

@lsenta which externs worked for you?

mikerod16:07:19

just the static style in an externs file?

mikerod16:07:29

var TopLevel = {"electron": ..., etc} style?

mikerod16:07:44

or using a type hint

mikerod16:07:51

with :infer-externs = true

lsenta16:07:33

The first one

lsenta16:07:42

extern:

var document = function() {}
var getElementById = function() {}
var innerHTML = function() {}
var electron = function() {}

electron.remote.BrowserWindow = function() {}
electron.remote.BrowserWindow.prototype.show = function () {}

lsenta16:07:11

code:

(defonce e (js/require "electron"))

(defn poptest []
  (let [win (e.remote.BrowserWindow. (clj->js {:width 100 :height 100}))]
    (.show win)))

mikerod16:07:38

Thanks for the details!

mikerod16:07:03

Yeah that is surprising to me that it could infer that unless it somehow knew that js/require was returning an electron. I guess there is more to learn about how externs work.

mikerod16:07:05

or maybe it is dummer than all that and just knows there is an object with a fn under remote.BrowserWindow so anywhere it sees <obj>.remote.BrowserWindow to leave that alone

lsenta16:07:12

I guess you'd have to leave <obj>.BrowserWindow too, in the end you'd skip any the symbol you've seen in the externs. The hierarchy would be useless.

mikerod16:07:49

Yeah, so maybe my guesses aren’t correct

mikerod16:07:57

I want to track through this some sometime soon

mikerod16:07:01

too many externs mysteries for me

takis_19:07:09

hello 🙂 is anyone using clojurescript with node.js/express/mongodb/mongoose etc? those libraries are written for javascript,the different data structures(json objects) or the different programming model,cause many problems? or they are easy to use ?

carly19:07:51

I use clojurescript with many libraries written for javaScript (currently d3) and there are not really any problems, using examples can be tricky becasuse you have to watch the scope but other than that it's great.

takis_19:07:52

thank you , i was trouble about thinking that i must convert json objects to clojurescript maps all the time,i am tottally new

mobileink19:07:25

State of Javascript 2017 just (?) started. State of Clojure 2017 starts in Dec? I would like to see a State of Clojurescript 2017, with a lot more detailed questions, specific to cljs than I found in SoC 2016. Is there a mechanism to allow community to suggest question items?

noisesmith20:07:24

@ingared that error means that the file that should define the namespace doesn’t have an ns form that declares that namespace

jebberjeb20:07:15

Other than Datascript, are there any other libraries out there written in Clojurescript which have a dedicated JS API, or are just intended to be used from JS in general?

jebberjeb20:07:05

Datascript is the perfect example of this, but it made me wonder if that's something people are doing -- writing libs for JS using Clojurescript.

bja20:07:24

I've written some react components using Reagent that are primarily used by a JS SPA

bja20:07:37

Reagent makes this pretty easy

jebberjeb20:07:55

@bja Was it a good experience?

jebberjeb20:07:10

Did the consumer care it was done w/ cljs?

bja20:07:31

for my use case it was. I was exposing some admin-focused widgets for a dataset whose server-side api was written in Clojure

bja20:07:41

so I could share things like Schemas

bja20:07:52

the consumer didn't know/care that it was in cljs

bja20:07:44

@jebberjeb you just use reagent.core/reactify-component and then ^:export that result

michaelblume20:07:00

@bja did you do an :advanced build on the cljs components before including them in the js project?

ingared20:07:25

@noisesmith : Thanks it was a typo in my directory name.

noisesmith20:07:49

yeah, that would do it

bja21:07:27

@michaelblume I didn't because it's an internal project

bja21:07:50

in fact, I built it with :simple and serve the result from the api in question

bja21:07:13

which lets me update it independently of doing releases for our admin app

bja21:07:15

which is kinda nice

tiagoantao21:07:36

hi, How do I set *eval-fn* when using cljs.js? From the documentation it seems that the runtime is supposed to take care of that, but I have it empty both on rhino and the browser

tiagoantao22:07:51

I am just answering my question if someone looks at the logs. It seems that there is no default *eval-fn*, this can be set/bound or the eval opt can be passed to e.g. eval-str. cljs.js/js-eval seems to do the job.