Fork me on GitHub
#datascript
<
2017-11-27
>
yannvahalewyn22:11:45

Hey channel, quick question: datomic supports strings for tempids but not negative numbers (anymore I think) and datascript does the opposite - likes negative numbers and hates strings. Is this voluntary / for a reason / interface difference between the two or a bug? How do you handle optimistic updates without getting some nasty tx transformation code?

souenzzo23:11:04

I don't interop datascript/datomic, but I use d/tempid on both

yannvahalewyn23:11:30

d/tempid will return decreasing negative numbers in cljs, which won’t fly when submitted to datomic

souenzzo23:11:43

Do you want to generete tempids om clients, serialize/send to server, transact and get back? Not sure but #om tempid's may do that.

souenzzo23:11:41

(may help you to do that.)

yannvahalewyn23:11:14

something like that. Don’t use om btw. The client generates transaction data which gets send to the server, which then replies with the created datoms. My client now kinda produces string temp-ids to be able to make that happen, would love to already transact those in datascript too to get some optimistic updates, and replace those when the server reply gets back.

yannvahalewyn23:11:48

There are hacks though, like using string negative numbers and looking for them, parseInt’ing them on the client for datascript, and doing some matching etc.. when the tx report comes back. But it’s a bit of a hassle and error prone, was wondering how the rest of the community handles this.

souenzzo03:11:43

I think that you can tweak the print-method

souenzzo03:11:43

No, datascript tempid is a primitive

souenzzo03:11:28

did you know #specter? you can (transform [(walker :db/id) :db/id (pred neg-int?)] d/tempid edn) on the server

yannvahalewyn05:11:42

I know specter. Could be useful here indeed, thanks 🙂

yannvahalewyn17:11:02

Actually, d/tempid will return a new one and I lose all references to the original tempid integer (ie: :tempids in the report contains other ones than the client sent out, which makes it hard to reconcile it when the response comes back. Not impossible, but just a lot of hassle. I’m curious to how other people in the community handle this.

souenzzo19:11:40

(= (d/tempid :db.part/user -65) (d/tempid :db.part/user -65)) ; => true

souenzzo20:11:01

or you can just stringify the negint from datascript

yannvahalewyn23:11:28

what I meant was:

(d/transact conn [[:db/add (d/tempid :db.part/user -1) :some/attr some-val]])
; => {... :tempids {-9223350046622220289 17592186048880} }
the -1 is lost (broadcasting the reports via (d/tx-report-queue). Stringifying the neg-ints is what I do now :)