Skip to content

Commit

Permalink
mrhyde: jso - added key/value interop to js functions
Browse files Browse the repository at this point in the history
  • Loading branch information
dribnet committed Apr 13, 2013
1 parent fad15a1 commit 3486f5f
Showing 1 changed file with 38 additions and 0 deletions.
38 changes: 38 additions & 0 deletions src/cljs/mrhyde/extend_js.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,44 @@
(map #(vector % (aget o %))
(sort keys))))))

(extend-type function
ILookup
(-lookup
([o k]
(aget o (strkey k)))
([o k not-found]
(let [s (strkey k)]
(if (goog.object.containsKey o s)
(aget o s)
not-found))))

IEmptyableCollection
(-empty [_]
(js-obj))

ITransientCollection
(-conj! [o [k v]]
(assoc! o k v))
(-persistent! [_]
(throw (js/Error. "JavaScript function isn't a real transient, don't try to make it persistent.")))

ITransientAssociative
(-assoc! [o k v]
(aset o (strkey k) v)
o)

ITransientMap
(-dissoc! [o key]
(gobject/remove o key)
o)

ISeqable
(-seq [o]
(let [keys (gobject/getKeys o)]
(when (pos? (alength keys))
(map #(vector % (aget o %))
(sort keys))))))

(extend-type array
IEmptyableCollection
(-empty [a]
Expand Down

0 comments on commit 3486f5f

Please sign in to comment.