Fork me on GitHub
#datascript
<
2017-03-10
>
Aron09:03:06

so, i just tried this last version, and it is not flattening the object for me

Aron09:03:40

ds.db_with(State.db, vector( hashMap(":db/ident", "history" , ":history/location", mori.conj(toClj(removeNull(history.location)), hashMap(":db/ident", "location")))))

Aron09:03:27

value of attribute :history/location is saved as a hashMap in datascript instead of being breaken up into datoms. even though :history/location is specified as a reference

Aron09:03:53

tried to do State.update(ds.db_with(State.db, vector( hashMap(helpers.keywordize(":db/ident"), "history" , helpers.keywordize(":history/location"), mori.conj(toClj(removeNull(history.location)), hashMap(helpers.keywordize(":db/ident"), "location"))))))

Aron09:03:21

Error: Cannot compare :db/ident to pathname is the response to that

Aron09:03:39

personally, i don't even understand why it is trying to compare it, but both are strings, so it should be able to compare it

Aron09:03:45

really confusing

Aron09:03:53

and i remember this same exact error message from a year ago and it was driving me crazy back then too 😞

Aron09:03:56

ok, so i can't use namespaces because something is wrong, but it works without

tonsky09:03:44

@ashnur what’s your problem?

Aron09:03:31

which one? 🙂 right now i can't use namespaces, but it might be because something weird from https://github.com/typeetfunc/datascript-mori

Aron09:03:00

otherwise stuff seems to be working

tonsky09:03:03

seems like a side effect, not the cause

tonsky09:03:14

can’t use namespaces where and why?

Aron09:03:24

well, i tried to document here the issue

Aron09:03:58

if i do keywordize(":history/location") and schema_to_clj(schemajson), with :history/location specified as a reference attribute in the schema, it doesn't work in the sense that hashmaps under that attribute do not get flattened

Aron10:03:19

if instead i use some random string that is not :x/y but x_y, and everything the same, it works

tonsky10:03:33

what’s keywordize?

tonsky10:03:39

what’s schema_to_clj?

tonsky10:03:19

it’s hard to figure out because all those are your own helpers that can do whatever. E.g. we have no guarantee they support namespaces

tonsky10:03:29

I can’t read the whole thread :)

Aron10:03:32

not mine...

tonsky10:03:43

they are not meant for consumption. Why are you using them?

tonsky10:03:03

e.g. keywordize obviously doesn’t support namespaces

Aron10:03:19

that was not obvious for me 🙂

Aron10:03:37

i know only little clojure/script

tonsky10:03:53

oh wait no it does

Aron10:03:54

i am using datascript-mori so i can use mori functions on datascript stuff

tonsky10:03:58

CLJS does it differently

tonsky10:03:15

it actually tries to parse the string and see if there’s a slash in the name

tonsky10:03:03

my advice for you is to print everything you try to put into the database with pr-str and see what are you really passing in

Aron10:03:26

well, right now, without keywords it works

Aron10:03:37

i might get back to this later if more important stuff is done

Aron10:03:48

but really, i think i will just try to not have to use datascript from js

Aron10:03:55

because it's a constant struggle

tonsky10:03:11

e.g. I’m very suspitious for toClj(removeNull(history.location)),

Aron10:03:52

history.location is just a simple js object, removenull removes all properties with null values so datascript doesn't complain

tonsky10:03:53

well actually if you’d use datascript-js you won’t have to convert everything to CLJS objects

Aron10:03:01

datascript-js?

tonsky10:03:16

yes, datascript comes with JS integration out of the box

Aron10:03:17

is that something new?

Aron10:03:20

oh, that

Aron10:03:28

i tried that, but then you can't use mori functions

tonsky10:03:37

that’s the idea

Aron10:03:54

not sure what's the point of doing it that way

tonsky10:03:04

it must’ve been a pain to write code like that State.update(ds.db_with(State.db, vector( hashMap(helpers.keywordize(":db/ident"), "history" , helpers.keywordize(":history/location"), mori.conj(toClj(removeNull(history.location)), hashMap(helpers.keywordize(":db/ident"), "location"))))))

tonsky10:03:30

also not sure why do you conj into a map

tonsky10:03:38

is history.location a map?

Aron10:03:48

dunno, someone said i have to use conj to add stuff to clojure data structures

tonsky10:03:57

yes, to vectors

tonsky10:03:02

to maps, use assoc

Aron10:03:07

ok, i will use assoc

Aron10:03:19

thanks 🙂

tonsky10:03:23

and print stuff so you know what’s going on

tonsky10:03:33

right now it seems you’re doing it blindly

tonsky10:03:56

if you’d see what are you actually passing the mistake would’ve been instantly obvious

Aron10:03:15

i am always printing stuff

Aron10:03:27

i saw that it was not adding what i wanted

Aron10:03:13

that is why i stopped using namespaces

tonsky10:03:39

what the result of this looks like? vector( hashMap(helpers.keywordize(":db/ident"), "history" , helpers.keywordize(":history/location"), mori.conj(toClj(removeNull(history.location)), hashMap(helpers.keywordize(":db/ident"), "location")))))

tonsky10:03:59

> that is why i stopped using namespaces This seems like a wrong idea

tonsky10:03:16

I’d say your problem is with conj, not with namespaces

Aron10:03:33

ok, so when i print vector() or any cljs datastructure, i have to use toJs on it, otherwise it's just the ugly thing

tonsky10:03:57

use prn from mori

tonsky10:03:06

makes no sense to convert back to JS

tonsky10:03:25

because you’ll be looking at an interpretation, and you need to get to the cause

Aron10:03:47

yeah 🙂

Aron10:03:49

mori doesn't have prn though 😞

Aron10:03:26

and going to assoc from conj changed nothing in the apparent behavior

tonsky10:03:05

yes that’ll do

tonsky10:03:22

it will print to a string though, you’ll have to console.log that string

tonsky10:03:36

but it’ll use the proper clojure formatter that you need

Aron10:03:45

that would do, but i don't know where it is available 🙂

tonsky10:03:24

how do you mean?

Aron10:03:32

well, mori.prStr is undefined

Aron10:03:54

i am not sure what is chainable thing is, which objects are using this prototype

tonsky10:03:09

well that’s tough luck

tonsky10:03:15

looks like it’s not exported

tonsky10:03:28

yeah, chainable is strange

tonsky10:03:53

no printing :)

Aron19:03:57

thanks again @misha for your help. i used your suggestions and now stuff makes a bit more sense and i feel it's less hackish 🙂

Aron19:03:18

btw, tonsky , regarding how painful code writing can be, i don't believe that writing is too painful, reading is much worse 🙂

mruzekw23:03:38

Do we know how big datascript is after minification and gzip?