This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2017-08-23
Channels
- # beginners (55)
- # boot (37)
- # braid-chat (1)
- # chestnut (3)
- # cider (4)
- # clara (22)
- # cljs-dev (54)
- # cljsrn (3)
- # clojure (114)
- # clojure-italy (12)
- # clojure-losangeles (3)
- # clojure-portugal (1)
- # clojure-russia (1)
- # clojure-spec (30)
- # clojure-uk (67)
- # clojure-ukraine (1)
- # clojurescript (101)
- # core-async (11)
- # cursive (6)
- # data-science (27)
- # datomic (8)
- # figwheel (3)
- # fulcro (59)
- # graphql (2)
- # hoplon (89)
- # jobs (3)
- # jobs-rus (1)
- # leiningen (3)
- # lumo (19)
- # off-topic (9)
- # om (48)
- # pedestal (2)
- # portkey (4)
- # protorepl (19)
- # re-frame (13)
- # reagent (38)
- # remote-jobs (1)
- # ring-swagger (4)
- # spacemacs (10)
- # specter (2)
@juhoteperi btw I have a patch for that issue yesterday about node deps in JS foreign libs
Just need to get the windows tests to pass
Turns out the solution was simply to pass the absolute path to Closure
Otherwise it cant find node modules
Heh, that was simple
I'm excited
This is yet another step in making js<-> cljs even easier
Plus my conj talk about this stuff got accepeted yesterday!
Will that be about the latest changes in Cljs in general or more specifically about JS integration?
Btw. I'll be speaking at ClojuTRE about recent Cljs changes, probably with emphasis on how the libs can use the same code to work with both foreign-libs and Node (i.e. global-exports and related things), and what this requires from Cljsjs and libs
I'm going to touch on the major things happening in CLJS land: node modules, js integration, code splitting, maybe selfhosted
@juhoteperi looking forward to hanging out at ClojuTRE!
^ my Lumo talk also briefly mentions implicit requires in Lumo/Node
@anmonteiro Will you be staying here before/after the conf?
I arrive the 31st at night
I leave San Francisco the 30th at 1pm lol :(
Only day I'm staying extra is Sunday
@anmonteiro That's the best day for hanging out 😄
I'll have to think about how to top last year, especially if @martinklepsch is present again
just booked my flights ✌️
@juhoteperi https://github.com/anmonteiro/clojurescript/commit/21d3b315fa5e777bf0cf2caf481bcf9fb36d5330
just attached this patch to CLJS-2334
@anmonteiro Cool. Is it our code or Closure code which requires absolute paths? All this handling of file paths as strings is quite complex.
Closure won’t find the node modules if we don’t pass absolute paths
putting together an example for you
@juhoteperi given test.js
and npm install left-pad
:
var leftPad = require('left-pad');
console.log(leftPad(42,5,0));
this works:
java -jar closure.jar /Users/anmonteiro/Documents/github/clojurescript/test.js /Users/anmonteiro/Documents/github/clojurescript/node_modules/left-pad/package.json /Users/anmonteiro/Documents/github/clojurescript/node_modules/left-pad/index.js --process_common_js_modules --module_resolution NODE > bundle.js
this doesn’t:
java -jar closure.jar test.js /Users/anmonteiro/Documents/github/clojurescript/node_modules/left-pad/package.json /Users/anmonteiro/Documents/github/clojurescript/node_modules/left-pad/index.js --process_common_js_modules --module_resolution NODE > bundle.js
test.js:1: WARNING - Failed to load module "left-pad"
var leftPad = require('left-pad');
^
test.js:1: WARNING - Failed to load module "left-pad"
var leftPad = require('left-pad');
^
0 error(s), 2 warning(s)
Oh so because we use absolute paths for node modules, we need to use absolute paths for all files JS being processed
Another part I wondered was, why Closure wants the paths as strings, instead of File objects, but that is probably because some of the sources are not Files: https://github.com/clojure/clojurescript/blob/master/src/main/clojure/cljs/closure.clj#L86-L93
right
would it be a good idea to make NodeList
ISeqable?
so querySelectorAll
can be iterated like a sequence
@shaunlebron I think that has been considered and was rejected because it’s “to much implicitness” or so
how do cljs people iterate a NodeList then?
In such cases I do Array.from
first
also CLJS targets multiple platforms, some of which don’t have the concept of NodeList
Array.from
is not supported in IE, lemme check goog
the old way is Array.prototype.slice.call(coll)
goog.array.toArray
will convert any object with a .length
property to an array: https://google.github.io/closure-library/api/goog.array.html#toArray
guess I’ll be using this!
@shaunlebron I think array-seq
should also work http://cljs.github.io/api/cljs.core/#array-seq
yup, that did it, thanks @juhoteperi !
apparently prim-seq
works the same way goog.array.toArray
does, but produces a sequence
i’ll document this
ha, it’s been in core since the first cljs release
documented ✅
aclone
is also a good option to copy an array like object to a real array. I'd hesitate to use prim-seq
to wrap a NodeList.
array-seq
docstring says "from a JavaScript array or array-like object" so I think it should be fine, NodeList is "array-like"
lol no, I was looking at the docs written by @shaunlebron 😄
okay, yeah, that also says array-like