This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2018-05-23
Channels
- # aws (4)
- # beginners (14)
- # boot (7)
- # cider (75)
- # clara (87)
- # cljsrn (6)
- # clojure (115)
- # clojure-berlin (2)
- # clojure-dusseldorf (2)
- # clojure-gamedev (8)
- # clojure-italy (15)
- # clojure-russia (9)
- # clojure-spec (46)
- # clojure-uk (195)
- # clojurescript (24)
- # css (44)
- # datascript (19)
- # datomic (18)
- # emacs (6)
- # fulcro (57)
- # hoplon (1)
- # jobs (3)
- # jobs-discuss (37)
- # jobs-rus (3)
- # luminus (6)
- # lumo (28)
- # off-topic (24)
- # onyx (11)
- # planck (8)
- # re-frame (31)
- # remote-jobs (12)
- # rum (10)
- # schema (4)
- # shadow-cljs (28)
- # specter (24)
- # sql (3)
- # tools-deps (34)
- # vim (43)
- # yada (10)
does anyone see a problem with the following code?:
(require 'goog.object)
(def spawn (goog.object/get (js/require "child_process") "spawn"))
(def proc (spawn "ls" (clj->js ["-lh", "/usr"])))
((.. proc -stdout -on) "data" (fn [data] (js/console.log data)))
(js/console.log "we are here")
and i get the following exception:
Cannot read property '_events' of null
_addListener (events.cljs:201:19)
addListener (events.cljs:258:10)
Readable.on (_stream_readable.cljs:784:35)
(evalmachine.<anonymous>:11:26)
Script.runInThisContext (vm.cljs:65:33)
Object.runInThisContext (vm.cljs:197:38)
()
(Object.lumo.repl.caching_node_eval)
(NO_SOURCE_FILE <embedded>:5824:287)
z (NO_SOURCE_FILE <embedded>:5825:306)
@johanatan looking, FWIW you can use (require '[child_process :refer [spawn]])
馃槻 4
feels more idiomatic to me
@johanatan I think it鈥檚 a problem with JS this
binding
unfortunate
here鈥檚 how you can write it:
(.on (.-stdout ls) "data" (fn [data] (prn data)))
(.. proc -stdout -on)
-> (.on (.-stdout proc))
if you start lumo with -v
/ --verbose
here鈥檚 the generated code:
cljs.user=> ((.. ls -stdout -on) "data" (fn [data] (prn data)))
Evaluating ((.. ls -stdout -on) "data" (fn [data] (prn data)))
cljs.user.ls.stdout.on.call(null,"data",(function (data){
return cljs.core.prn.call(null,data);
}))
Cannot read property '_events' of null
_addListener (events.cljs:201:19)
addListener (events.cljs:258:10)
Readable.on (_stream_readable.cljs:784:35)
(evalmachine.<anonymous>:1:24)
Script.runInThisContext (vm.cljs:65:33)
Object.runInThisContext (vm.cljs:197:38)
(Object.wt)
(Object.lumo.repl.caching_node_eval)
(NO_SOURCE_FILE <embedded>:5824:287)
z (NO_SOURCE_FILE <embedded>:5825:306)
vs:
cljs.user=> (.on (.-stdout ls) "data" (fn [data] (prn data)))
Evaluating (.on (.-stdout ls) "data" (fn [data] (prn data)))
cljs.user.ls.stdout.on("data",(function (data){
return cljs.core.prn.call(null,data);
}))
#object[Socket [object Object]]
you鈥檙e probably not passing "data"
as the arg
or something
but do you see the difference above?
one is using .call(null)
^ this binds the function this
to null
which is wrong
lumo --verbose
or -v