Skip to content

Instantly share code, notes, and snippets.

@favila
Created April 24, 2014 20:20
Show Gist options
  • Save favila/11268240 to your computer and use it in GitHub Desktop.
Save favila/11268240 to your computer and use it in GitHub Desktop.
Hack to fit tempids into JS int range for storefront.
(def ^:const SIGN-BIT (bit-shift-left 1 63))
(defn tempid-cljs->clj [tid]
(if (neg? tid)
(let [cljtid (-> tid (-) (bit-or SIGN-BIT))]
(d/tempid (d/part cljtid) (d/tx->t cljtid)))
tid))
(defn tempid-clj->cljs [tid]
(if (neg? tid)
(-> tid (bit-xor SIGN-BIT) (-))
tid))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment