@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?
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
I use subscriptions for that. They know about the scheme and the store
You can have subscriptions that accept args, or you can read some other data from the app-db
If you need to select something based on the form value, you can access the form state in the app-db.
I can give you an example in ~30 mins when I’m back in the office
Awesome, thanks
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.
“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?
yes
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
so if you call defentitydb
inside a namespace all of these functions will be defined
and you can use them as for instance edb/insert-item
Ah nice, I got it working, I didn’t realize the schema was partially appplied
being generated by macros is bad for this :( you can’t inspect args
or docstrings
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
which is verbose
Also it seems the function accepts the whole app-db, rather than (:entity-db app-db)
yes, these generated by macro work like that, macro does something like the file I just pasted
Is it possible (not asking you to do it) to add like ^:args and ^:docstring metadata to macro generated fns?
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 🙂
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)
Yeah, I’m planning to reorganize everything
I’ll pull the content from blog posts to examples / docs
and probably create a gitbook for that
yeah that’d be awesome
I still think editor integrated/in-code documentation is the best :)
anyhoo, here’s an example subscription that’s having extra arguments:
@mihaelkonjevic uploaded a file: https://clojurians.slack.com/files/U050986L9/F8X6C7QSU/-.clj
and then you can use it from the component (keechma.toolbox.ui/sub> ctx :some-subscription cart)
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?
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
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