This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2022-08-05
Channels
- # announcements (1)
- # babashka (16)
- # beginners (36)
- # biff (1)
- # calva (2)
- # cider (4)
- # cljdoc (1)
- # clojure (118)
- # clojure-austin (2)
- # clojure-czech (2)
- # clojure-europe (19)
- # clojure-norway (3)
- # clojure-spec (8)
- # clojure-uk (3)
- # clojurescript (11)
- # conjure (1)
- # cursive (3)
- # datalevin (5)
- # datomic (7)
- # emacs (16)
- # events (1)
- # figwheel-main (3)
- # fulcro (5)
- # hyperfiddle (17)
- # jobs (2)
- # lsp (19)
- # malli (5)
- # nbb (10)
- # off-topic (5)
- # polylith (5)
- # re-frame (3)
- # reagent (11)
- # remote-jobs (2)
- # shadow-cljs (1)
- # spacemacs (7)
- # web-security (4)
Hiho everyone. How do I access this
inside a class method? Thought it might be passed as the 0th arg and next guess is js/this
but no luck with either of these.
(ns stream-test
(:require [cljs.pprint :refer [pprint]]
["readable-stream" :as stream]))
(def number-stream
(new stream.Readable
#js{:objectMode true
:read (fn [count] (.push js/this “hello”))}))
(-> number-stream
(.on "data" (fn [chunk] (pprint (list "got" chunk))))
(.on "error" (fn [err] (pprint (list "err" err)))))
;; ("err" #object[TypeError TypeError: Cannot read property 'push' of undefined])
Ah the workaround is simple:
(ns stream-test
(:require [cljs.pprint :refer [pprint]]
["readable-stream" :as stream]))
(def number-stream
(new stream.Readable
#js{:objectMode true
:read (fn [_count] (.push number-stream "hello"))}))
(-> number-stream
(.on "data" (fn [chunk] (pprint (list "got" chunk))))
(.on "error" (fn [err] (pprint (list "err" err)))))
Aha - thanks! Something like that was next on the list to try but good to know there isn’t a pseudo- this
I should be using. Calling the object instance makes more sense anyway.
I’m super impressed with how compact the nbb code is compared with the equivalent in Nodejs.
nbb currently at the frontpage of HN: https://hn.algolia.com/?q=Clojure%20Scripting%20on%20Node.js 🙂
This was by far the best received post about nbb on hackernews if I check this correctly. And @U04V15CAJ nicely replied to op questions. It's however quite obvious that Lisp (in general) is a niche in our industry.