This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2017-07-19
Channels
- # aleph (11)
- # aws (1)
- # beginners (14)
- # bitcoin (1)
- # boot (41)
- # cider (6)
- # cljs-dev (1)
- # cljsrn (13)
- # clojure (138)
- # clojure-italy (10)
- # clojure-nl (1)
- # clojure-poland (2)
- # clojure-russia (62)
- # clojure-sg (2)
- # clojure-spec (31)
- # clojure-uk (51)
- # clojurescript (109)
- # core-matrix (1)
- # core-typed (1)
- # cursive (63)
- # datomic (10)
- # emacs (9)
- # euroclojure (1)
- # hoplon (112)
- # immutant (16)
- # jobs (2)
- # lumo (5)
- # off-topic (14)
- # om (54)
- # onyx (17)
- # parinfer (23)
- # pedestal (2)
- # re-frame (41)
- # ring-swagger (23)
- # spacemacs (9)
- # specter (10)
- # uncomplicate (5)
- # vim (1)
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
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?
@bellp CLJS has a different version scheme
it usually goes to 1.9.0 at the same time/feature parity as Clojure 1.9.0
This isn't a template, but this screencast was invaluable for me when learning how to set this all up.
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 😕
Is there a nice way to preserve namespaces when using clj->js?
Or is anyone aware of a function / lib that will do so?
@bellp perhaps the templates mentioned in the ExternalResources section of the docs?
Ie. up the top of: https://github.com/Day8/re-frame/blob/master/docs/External-Resources.md
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?
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
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
@mikethompson could the above have something to do with re-frame.db/app-db?
@stuartrexking Spec will always check all map keys against the spec, even if you didn't specify it.
@rauh Didn’t specify it where?
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?
Surely it should just ignore those? Why bother including the spec as an argument to explain then?
If it’s just going to check them all.
@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
Yeah this has been discussed countless times in the spec channel. It's pretty confusing. Though it is documented in the spec guide.
Yowzers. That’s confusing. Ok, I’ll work with it.
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?
@osmirnov full :npm-deps
integration isn’t yet released I think
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.@mikerod See https://clojurescript.org/reference/advanced-compilation#providing-externs and https://clojurescript.org/reference/compiler-options#externs
@mfikes I’ve read about these. I didn’t see this as an externs problem. I’m probably incorrect.
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)
If you are curious about externs inference https://clojurescript.org/guides/externs
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?
@lsenta I believe it is similar to what I did above:
(let [e (js/require "electron") ...] ...)
For more on modules, I know there is https://clojurescript.org/news/2017-07-12-clojurescript-is-not-an-island-integrating-node-modules and https://clojurescript.org/reference/javascript-module-support
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 releaseSee the link that mikerod put above for more information
@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?
except I just had a weird access case that I mistakenly thought wasn’t about externs 😛
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?
@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
I’m not the definitive source to go to on this though. I’m still fighting through nearly this same topic currently hah
https://clojurescript.org/guides/externs if you missed it
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")))
🙂
extern:
var document = function() {}
var getElementById = function() {}
var innerHTML = function() {}
var electron = function() {}
electron.remote.BrowserWindow = function() {}
electron.remote.BrowserWindow.prototype.show = function () {}
code:
(defonce e (js/require "electron"))
(defn poptest []
(let [win (e.remote.BrowserWindow. (clj->js {:width 100 :height 100}))]
(.show win)))
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.
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
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.
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 ?
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.
thank you , i was trouble about thinking that i must convert json objects to clojurescript maps all the time,i am tottally new
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?
@ingared that error means that the file that should define the namespace doesn’t have an ns form that declares that namespace
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?
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.
for my use case it was. I was exposing some admin-focused widgets for a dataset whose server-side api was written in Clojure
This isn't a template, but this screencast was invaluable for me when learning how to set this all up.
@jebberjeb you just use reagent.core/reactify-component
and then ^:export that result
@bja did you do an :advanced build on the cljs components before including them in the js project?
@noisesmith : Thanks it was a typo in my directory name.
yeah, that would do it
@michaelblume I didn't because it's an internal project
cool =)
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
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.