Skip to content

Instantly share code, notes, and snippets.

@travis
Created February 27, 2014 18:45
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 travis/9256435 to your computer and use it in GitHub Desktop.
Save travis/9256435 to your computer and use it in GitHub Desktop.
(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