Created
February 27, 2014 18:45
-
-
Save travis/9256435 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(extend-type ParseObject | |
ILookup | |
(-lookup [obj key] | |
(case key | |
:id (.-id obj) | |
;; wrap dates so they're easier to serialize | |
:createdAt (js/Date. (.-createdAt obj)) | |
:updatedAt (js/Date. (.-updatedAt obj)) | |
(.get obj (name key)))) | |
IEquiv | |
(-equiv [o other] (and (instance? (type o) other) (= (.-id o) (.-id other)))) | |
IHash | |
(-hash [o] (hash (str (.-className o)"-"(.-id o)))) | |
IEncodeClojure | |
(-js->clj [parse-object {:keys [keywordize-keys] :as options}] | |
(reduce (fn [m key] (assoc m | |
(if keywordize-keys (keyword key) key) | |
(apply js->clj (.get parse-object key) (flatten (vec options))))) | |
{} | |
(.keys js/Object (.toJSON parse-object))))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment