Fork me on GitHub
#clojurescript
<
2020-08-09
>
benny03:08:42

how does one turn something like this into cljs?

var foo = new Foo("input", (e) => { if (e) return; foo.bar(); });

benny03:08:03

maybe something like this?

(let [foo (atom nil)]
  (reset! foo (new js/Foo "input" #(if-not e (.bar @foo)))))

lilactown03:08:08

do you need foo to be mutable?

lilactown03:08:16

I'd probably do:

(let [foo (js/Foo. "input" #(when-not % (.bar foo)))]
  ;; use `foo` here
  )

benny03:08:18

not sure if it’s something i’m doing wrong or if it’s actually not working, but says my “foo” is undefined

benny04:08:37

(ns foo-bar (:require ["react-native-sound" :as Sound]))
; ...
(let [effect (Sound. sound-name (.-MAIN_BUNDLE Sound) #(.play effect))])

benny04:08:35

i get > undefined is not an object

benny04:08:52

this ended up working 😕

(let [data (atom nil)
      do-stuff (fn [error] (.play @data))]
  (reset! data (Sound. sound-name (.-MAIN_BUNDLE Sound) #(do-stuff %))))

😮 3