mpdairy / posh

A luxuriously simple and powerful way to make front-ends with DataScript and Reagent in Clojure.
Eclipse Public License 1.0
460 stars 45 forks source link

Pull doesn't work with entity ids like 5.036617769192117e+47 #33

Open jpmonettas opened 5 years ago

jpmonettas commented 5 years ago

Steps to reproduce:

(def c (d/create-conn))
(posh/posh! c)

(d/transact! c [[:db/add 1 :person/name "Rich"]
                       [:db/add 5.036617769192117e+47 :person/name "Alex"]])

@(posh/pull c '[:person/name] 1)
;; {:db/id 2, :person/name "Rich"}

@(posh/pull c '[:person/name] 5.036617769192117e+47)
;; nil

;; While it works in datascript
(d/pull @c '[:person/name] 5.036617769192117e+47)
{:person/name "Alex"}
jpmonettas commented 5 years ago

Created a PR that fixes this issue (https://github.com/mpdairy/posh/pull/34)

metasoarous commented 5 years ago

While it may be possible to use floating point ids in Datascript, I'm not sure its a good idea. There are likely performance implications, and I'd suspect you should be able to get around this by casting as an int.

jpmonettas commented 5 years ago

I went for a reading and javascript stores everything as double precision floating point numbers, following the IEEE 754 standard. So everything is just 64 bit numbers where the number (the fraction) is stored in bits 0 to 51, the exponent in bits 52 to 62, and the sign in bit 63.

Looking at clojurescript code for "int casting" it just strip decimal places.

I think is a nice property to have posh pull interface to follow datascript pull one.