Question

Is there a way to make another container in cljs like it is in clojure by implementing IDeref?

(reify clojure.lang.IDeref
     (deref [_] ...))

The compiler warns IDeref is not a protocol

Was it helpful?

Solution

Try this:

(def a
  (reify IDeref
    (-deref [_] "Hello!")))

(.log js/console @a)

outputs "Hello!". You may want to use deftype:

(deftype LikeAtom []
  IDeref
  (-deref [_] "Hello!"))

(.log js/console @(LikeAtom.))
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top