Fork me on GitHub
#datascript
<
2015-08-27
>
sonnyto19:08:40

@tonsky: I'm looking through the source code and can't find the definition of map->DB . what does map->DB do? where can I find the defintion?

tonsky20:08:02

@sonnyto: you get it automatically with defrecord

tonsky20:08:27

(defrecord Rec [a b c]) creates map->Rec and ->Rec fns

sonnyto20:08:27

thanks. didnt know that

tonsky20:08:54

first one takes {:a ... :b ... :c ...} map, second one [a b c] vector

sonnyto20:08:02

my real problem is i'm trying to persist a db value to indexedDB

tonsky20:08:07

not vector, just positional arguments

sonnyto20:08:19

but having DATA_CLONE_ERR errors

sonnyto20:08:30

thats when i started looking into the structure of the DB

tonsky20:08:09

how can I help?

sonnyto20:08:34

i am not sure ... lol

sonnyto20:08:56

i think indexedDB cannot persist some things

sonnyto20:08:16

Error and Function objects cannot be duplicated by the structured clone algorithm; attempting to do so will throw a DATA_CLONE_ERR exception.

sonnyto20:08:34

does the db value contain Function objects when its translated into js?

tonsky20:08:12

It probably does

tonsky20:08:18

I don’t know

tonsky20:08:37

actually it depends on cljs implementation of defrecords and protocols

sonnyto20:08:38

yeah it probably does...

sonnyto20:08:50

implementing lazy datastrucutres would require functions

sonnyto20:08:21

what if i use transit to serialize the db value?

sonnyto20:08:38

would i be able to deserialize it and get the original value?

sonnyto20:08:52

i am attempting to do that now

tonsky20:08:45

I’m using transit at the moment in production

sonnyto20:08:23

cool.. it a pity that indexedDB cannot store the raw DB value

tonsky20:08:44

(transit/read (transit/reader :json {:handlers {"datascript/DB" dc/db-from-reader}}) s)

tonsky20:08:06

don’t have cljs write snippet, only clj

tonsky20:08:46

you probably would like to serialize only one index out of three

sonnyto20:08:50

why not serialize them all?

sonnyto20:08:53

space concerns?

tonsky20:08:06

they have the same information, only order is different

tonsky20:08:29

and db-from-reader expects single index

tonsky20:08:02

Do this: (transit/tagged-value "datascript/DB" {:schema <schema> :datoms <datoms>})

tonsky20:08:36

where <datoms> is (:eavt db)

sonnyto20:08:18

cool... i will try it.

tonsky20:08:39

you probably can extend transit to serialize DB specific way, and that’s the way

sonnyto20:08:04

i'm using sente for websockets

sonnyto20:08:15

and it is somehow able to serialize the whole db value

sonnyto20:08:21

i assume it uses transit underneath

tonsky20:08:37

probably EDN

tonsky20:08:46

edn is supported out-of-the-box

sonnyto20:08:57

read-string is slow

tonsky20:08:00

transit isn’t because it’s an external dependency

sonnyto20:08:19

@tonsky if we ever meet in person, i have to buy you a beer simple_smile thanks for being so helpful

tonsky21:08:41

if you’d figure the code for transit read/write out, I’ll be happy to put it to tips & tricks