keechma

Keechma stack. Mention @U050986L9 or @U2J1PHYNM if you have any questions
sooheon 2018-01-24T12:18:30.000376Z

@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?

sooheon 2018-01-24T12:19:00.000361Z

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

mihaelkonjevic 2018-01-24T12:20:13.000277Z

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

mihaelkonjevic 2018-01-24T12:20:56.000328Z

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

mihaelkonjevic 2018-01-24T12:21:41.000202Z

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

mihaelkonjevic 2018-01-24T12:22:03.000014Z

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

sooheon 2018-01-24T12:22:16.000021Z

Awesome, thanks

sooheon 2018-01-24T12:23:08.000068Z

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.

sooheon 2018-01-24T12:24:03.000070Z

“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?

mihaelkonjevic 2018-01-24T13:06:36.000478Z

yes

mihaelkonjevic 2018-01-24T13:08:15.000233Z

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

mihaelkonjevic 2018-01-24T13:08:29.000466Z

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

mihaelkonjevic 2018-01-24T13:08:56.000216Z

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

sooheon 2018-01-24T13:09:13.000361Z

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

sooheon 2018-01-24T13:09:33.000326Z

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

sooheon 2018-01-24T13:09:36.000124Z

or docstrings

mihaelkonjevic 2018-01-24T13:10:25.000272Z

yeah, but I don’t know if there’s another way except like here https://github.com/keechma/example-place-my-order/blob/master/client/src/client/edb.cljs

mihaelkonjevic 2018-01-24T13:10:31.000390Z

which is verbose

sooheon 2018-01-24T13:10:41.000299Z

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

mihaelkonjevic 2018-01-24T13:11:21.000020Z

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

sooheon 2018-01-24T13:11:55.000453Z

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

mihaelkonjevic 2018-01-24T13:12:45.000153Z

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 🙂

sooheon 2018-01-24T13:13:40.000339Z

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)

mihaelkonjevic 2018-01-24T13:14:36.000002Z

Yeah, I’m planning to reorganize everything

mihaelkonjevic 2018-01-24T13:14:55.000319Z

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

mihaelkonjevic 2018-01-24T13:15:07.000432Z

and probably create a gitbook for that

sooheon 2018-01-24T13:15:27.000134Z

yeah that’d be awesome

sooheon 2018-01-24T13:15:44.000438Z

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

mihaelkonjevic 2018-01-24T13:17:58.000103Z

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

mihaelkonjevic 2018-01-24T13:18:09.000003Z

@mihaelkonjevic uploaded a file: https://clojurians.slack.com/files/U050986L9/F8X6C7QSU/-.clj

mihaelkonjevic 2018-01-24T13:19:56.000428Z

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

sooheon 2018-01-24T14:52:06.000214Z

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?

sooheon 2018-01-24T14:53:41.000142Z

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

mihaelkonjevic 2018-01-24T15:31:36.000364Z

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