Pregunta

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

¿Fue útil?

Solución

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.))
Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top