Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
cljs.user=> (def metas (atom {}))
#'cljs.user/metas
cljs.user=> (extend-type object
#_=> IWithMeta
#_=> (-with-meta [o meta]
#_=> (swap! metas assoc (goog/getUid o) meta)
#_=> o))
nil
cljs.user=> (extend-type object
#_=> IMeta
#_=> (-meta [o] (when (goog/hasUid o)
#_=> (@metas (goog/getUid o)))))
nil
cljs.user=> (def o #js {:a 1})
#'cljs.user/o
cljs.user=> (with-meta o {:b 3})
#js {:a 1, :closure_uid_857478408 17}
cljs.user=> (meta *1)
{:b 3}
@mfikes

This comment has been minimized.

Copy link
Owner Author

@mfikes mfikes commented Dec 15, 2018

Or just cram the meta in the object to tie its life to the object:

cljs.user=> (extend-type object
       #_=>  IWithMeta
       #_=>  (-with-meta [o meta]
       #_=>    (goog.object/set o "object_meta" meta)
       #_=>    o))
nil
cljs.user=> (extend-type object
       #_=>  IMeta
       #_=>  (-meta [o]
       #_=>   (goog.object/get o "object_meta")))
nil
cljs.user=> (def o #js {:a 1})
#'cljs.user/o
cljs.user=> (with-meta o {:b 3})
#js {:a 1, :object_meta {:b 3}}
cljs.user=> (meta o)
{:b 3}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment