This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2017-09-27
Channels
- # beginners (34)
- # boot (15)
- # cider (7)
- # cljs-dev (7)
- # cljsjs (2)
- # cljsrn (46)
- # clojure (130)
- # clojure-argentina (1)
- # clojure-colombia (2)
- # clojure-greece (1)
- # clojure-italy (53)
- # clojure-losangeles (1)
- # clojure-russia (15)
- # clojure-spec (8)
- # clojure-uk (100)
- # clojurescript (117)
- # core-matrix (1)
- # cursive (24)
- # datomic (41)
- # duct (1)
- # emacs (11)
- # fulcro (22)
- # graphql (4)
- # hoplon (3)
- # jobs (1)
- # lein-figwheel (3)
- # luminus (18)
- # lumo (52)
- # off-topic (57)
- # pedestal (2)
- # planck (12)
- # re-frame (22)
- # remote-jobs (1)
- # ring-swagger (6)
- # rum (7)
- # shadow-cljs (13)
- # yada (19)
hello, i’m trying out the new npm-deps feature of cljs. i’m trying to require an addon from the codemirror project and when i build my app i get the following error:
java.lang.AssertionError: Assert failed: cljs.analyzer/foreign-dep? expected symbol got "codemirror/addon/edit/matchbrackets"
my ns declaration looks like the following
(ns my-app.web.components.editor
(:require
[codemirror :refer [CodeMirror]]
"codemirror/addon/edit/matchbrackets"
"codemirror/addon/edit/closebrackets"
"codemirror/addon/hint/show-hint"
"codemirror/addon/hint/sql-hint"
"codemirror/mode/sql/sql"
[reagent.core :as reagent]))
from the recent post about npm-deps https://clojurescript.org/news/2017-07-12-clojurescript-is-not-an-island-integrating-node-modules i thought that strings were permissible in ns declarations? but i suppose i was wrong. any help getting me pointed in the right direction would be much appreciated.
oh, in case it’s helpful, this is the implementation matchbrackets file https://github.com/codemirror/CodeMirror/blob/master/addon/edit/matchbrackets.js
“arriving in the next version of ClojureScript” is pretty vague. I’m new and don’t know what version that might be, but it’d have to be recent
cljs versions use the number of commits to master since the last major release (e.g. 1.9.908 means '908 commits since 1.9')
no idea. I’m on an older version.
@seako strings are valid, probably a problem parsing your module. can you put together a minimal repro I can look at?
I’ve created tests as i understand they’d be written in plain clojure with clojure.test but when i run lein test
it runs 0 tests
right, lein test doesn't load your clojurescript - there are frameworks to set up and run cljs tests, but essentially all you need is to have a running cljs repl, load all the source files that contain tests, and run them with cljs.test/run-tests
https://clojurescript.org/tools/testing
it seems like in here https://github.com/emezeske/lein-cljsbuild/blob/master/doc/TESTING.md that it’s possible, but the configuration interacts with phantom and doesn’t utilize clojure.test there’s no way to change that to use clojure.test instead is there?
you can make the function you hand it run anything you like in phantom...
clojure.test is probably the easiest thing to use in that function - but there are definitely other options for leiningen cljs test tooling -- for example I've frequently seen doo
mentioned (but haven't used it myself - I just made an alternate cljs build, with the same cljs source paths, and a page that loads that build and invokes my test runner in a script tag - that way I can run tests in the same browser my code is supposed to support) - https://github.com/bensu/doo
from skimming the doo readme, it looks like they also prefer making a seperate cljs build with your tests as a target
so if i understand it, looks like i would just do something similar to this? https://github.com/emezeske/lein-cljsbuild/tree/master/example-projects/advanced
I guess - though they aren't even using a test library, they just have some functions that call assert
Does the :foreign-libs feature provide any support related to source maps?
I'd like mylib.js.map to be copied alongside mylib.js
That way chrome would pick up the source mapping when debugging with :optimisations :none
Ah, found a related ticket. Looks like its a welcome feature waiting for a developer...
With that in mind, I'd love to hear any workarounds for copying extra files as part of the compilation
how often/when are foreign libs (re)downloaded?
@thedavidmeister not sure I understand the question
if i do :file
and put a url in, that has to download it though right?
With :optimisations :none
those files are copied into the output path. The browser will GET the file when it's required in a namespace.
In that case the browser fetches each namespace or foreign lib separately.
For a production build it's all bundled up into a single js file.
@U055DUUFS so if i have 10 foreign libs, then i have to download those 10 files every time i compile cljs?
I've never used urls in my build process.
My foreign-libs are precompiled js files which sit in the repo.
So not much different to regular source code really.
you might find this doco interesting if you're unfamiliar with foreign-libs
those docs don't really answer my q unfortunately
i'll try putting them locally though, worth a try 🙂
i converted everything to local and the speed was identical fyi
so it must cache the downloads
Interesting. Good to know.
hm hmmm if I try to feed a colon into cljs's read-string
, I get an exception. How do I either get nil instead of an exception, or check if something is valid for reading before feeding it into the reader?
cljs.user=> (cljs.reader/read-string ":")
#object[TypeError TypeError: Cannot read property '0' of null]
cljs$reader$read_keyword (jar:file:/home/u/.m2/repository/org/clojure/clojurescript/1.9.89/clojurescript-1.9.89.jar!/cljs/reader.cljs:359:21)
cljs.reader/read (jar:file:/home/u/.m2/repository/org/clojure/clojurescript/1.9.89/clojurescript-1.9.89.jar!/cljs/reader.cljs:456:22)
cljs$reader$read_string (jar:file:/home/u/.m2/repository/org/clojure/clojurescript/1.9.89/clojurescript-1.9.89.jar!/cljs/reader.cljs:469:6)
nil
I think you might be. read-string
expects a clojure (or cljs) data structure, as far as I understand, and :
is hardly a valid clj/cljs data structure 🙂 I tried entering :
into a clj repl to see what it would evaluate to, and it caused an exception as well.
haha yes, :
is not valid. I am taking user input though, so I can't control what goes in.
@daiyi from memory there are options you can pass to read string to determine whether it throws an error or returns info that it wasn't valid - can't remember if that was clj or cljs or both though
I think that's for reader, rather than read-string. I can't figure out how to use reader, I think it needs a stream? https://clojuredocs.org/clojure.core/read
yeah, i think i was wrong about that
i think this is it
https://github.com/clojure/tools.reader/blob/master/src/main/cljs/cljs/tools/reader.cljs#L368
seems like you need to either try/catch or find a function that just determines the validity of edn without trying to parse it
+1 for try-catch, it will do exactly what you are attempting. (try <some expr> (catch js/Error e nil))
. You could also then inspect the error and react differently depending on what happened. Below is an example of that, though a bit complicated because of cljs/clj reader conditionals: https://github.com/braintripping/magic-tree/blob/master/src/magic_tree/parse.cljc#L153
there is an option you can pass to read-string
to avoid throwing an error on “end of file” (`eof`) errors, but for the rest, exceptions are baked in.
anyone knows an example of a project that mixes server side rendering with clojurescript? (using re-frame to be more precise)
so in theory I could just use any templating library on the backend, and just render the HTML with the few interpolations I need
and then clojurescript will do the rest, right?
i'm using cljs-http and i need to POST both form params as well as a text/plain body. it looks to me like cljs-http only accepts parameter maps. has anyone come across this problem before? i'm trying to hit this web service API end point: http://iodocs.apps.intermine.org/flymine-beta/docs#/ws-list-append/POST/lists/append
@daiyi From the stacktrace, you seem to be using an older version of CLJS
Is the latest not a possibility?
You should get a much nicer error at least if you use 1.9.908
1.9.89 is waaaay old at this point
@fenton why are you using Date as a function instead of using .
to use its constructor in the first call?
because if you used .
to access the constructor I think that call would work 😄
I am working through the modules guide. I have a handful of differentiated namespaces, each with identical kit of functions.
right now I can manually identify each function but it is verbose, I feel like there could be a dynamic solution
@thheller really i meant getting that functionality. just using the namespace as a pojo and grabbing 'methods'
namespace foo.core and bar.core..... etc. each has functions a() b() ... etc. I split each namespace into a module
this is what records and protocols are made for - namespaces will never be a good fit for that kind of code pattern
a module is a collection of namespaces but you are using a single namespace in your example?
these are all namespaces that riff on the same functionilty. they are not all used at same time, so delivered when user needs them.
namespaces are definitely fragile when used as containers / injected dependencies. If what you need is multiple implementations that give different functionality or implementation but having the same basic interface for usage, use records and protocols
who said anything about data types?
if they never hold data at all, use reify and protocols
right, reify is code
another idea: each namespace can have one exported function returning a map of all functions in the namespace, this would survive advanced optimisations
namespaces are a clumsy way to do modularity - it can be done but it’s going to be awkward, but do it however you like of course
@pat you can even use a macro to generate that map automatically, so you don't have to maintain it
but a map is data, you said this wasn’t data
namespaces do not exist in :advanced
mode, so building anything on top of namespaces is risky
(and the main problem with using namespaces this way is they are clumsy as data containers)
it could look like this: https://github.com/binaryage/cljs-devtools/blob/master/src/lib/devtools/formatters/markup.clj
get-markup-db
fn could be set!
on global js/window
or anywhere to be consumed by other code