Skip to content

Instantly share code, notes, and snippets.

@mfikes
Last active December 15, 2018 04:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mfikes/122814757fd1f2aec9de509446793e5f to your computer and use it in GitHub Desktop.
Save mfikes/122814757fd1f2aec9de509446793e5f to your computer and use it in GitHub Desktop.
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
Copy link
Author

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