Fork me on GitHub
#keechma
<
2018-01-24
>
sooheon12:01:30

@mihaelkonjevic In the edb docs, get-item-by-id et al need a reference to the schema and the store. How do you hand these over in the context of a component?

sooheon12:01:00

Say I have a dropdown select, and I want an on-change handler for the selection to look up something in edb by key and display it

mihaelkonjevic12:01:13

I use subscriptions for that. They know about the scheme and the store

mihaelkonjevic12:01:56

You can have subscriptions that accept args, or you can read some other data from the app-db

mihaelkonjevic12:01:41

If you need to select something based on the form value, you can access the form state in the app-db.

mihaelkonjevic12:01:03

I can give you an example in ~30 mins when I’m back in the office

sooheon12:01:16

Awesome, thanks

sooheon12:01:08

I don’t want to make it a form because it’s a one off selection. The subscription taking args sounds like what I need.

sooheon12:01:03

“They know about the scheme and the store” the subscription gets the app-db-atom as its argument, right? And I can just refer the edb-schema inside the subscriptions ns?

mihaelkonjevic13:01:15

defentitydb macro exports the dbal functions from here https://github.com/keechma/entitydb/blob/master/src/entitydb/core.cljs#L503 with schema partially applied as a first argument

mihaelkonjevic13:01:29

so if you call defentitydb inside a namespace all of these functions will be defined

mihaelkonjevic13:01:56

and you can use them as for instance edb/insert-item

sooheon13:01:13

Ah nice, I got it working, I didn’t realize the schema was partially appplied

sooheon13:01:33

being generated by macros is bad for this :( you can’t inspect args

sooheon13:01:36

or docstrings

mihaelkonjevic13:01:31

which is verbose

sooheon13:01:41

Also it seems the function accepts the whole app-db, rather than (:entity-db app-db)

mihaelkonjevic13:01:21

yes, these generated by macro work like that, macro does something like the file I just pasted

sooheon13:01:55

Is it possible (not asking you to do it) to add like ^:args and ^:docstring metadata to macro generated fns?

mihaelkonjevic13:01:45

I guess it is, macro is here https://github.com/keechma/keechma-toolbox/blob/master/src/clj/keechma/toolbox/edb.clj . It’s incredibly ugly since this is one of the first macros I wrote 🙂

sooheon13:01:40

yeah macros are beyond my understanding right now, but will keep it in mind--if I ever contribute to keechma it should be in-library documentation (rather than blogposts)

mihaelkonjevic13:01:36

Yeah, I’m planning to reorganize everything

mihaelkonjevic13:01:55

I’ll pull the content from blog posts to examples / docs

mihaelkonjevic13:01:07

and probably create a gitbook for that

sooheon13:01:27

yeah that’d be awesome

sooheon13:01:44

I still think editor integrated/in-code documentation is the best :)

mihaelkonjevic13:01:58

anyhoo, here’s an example subscription that’s having extra arguments:

mihaelkonjevic13:01:56

and then you can use it from the component (keechma.toolbox.ui/sub> ctx :some-subscription cart)

sooheon14:01:06

Thanks, this makes sense. I ended up putting it int he controller for the component--referring edb namespace in a controller is an OK pattern, right?

sooheon14:01:41

I guess it would have to be, because it’s just the equivalent of using get-in or assoc-in on :kv, just for :edb

mihaelkonjevic15:01:36

yeah, it’s a good pattern. I usually have a lot of controllers like that, any user action that is not a form is implemented with controllers https://github.com/gothinkster/clojurescript-keechma-realworld-example-app/blob/master/src/cljs/realworld/controllers/user_actions.cljs#L35