outlandishideas/kasia

Expose action creators to fetch posts and run arbitrary queries outside decorators

sdgluck opened this issue · 2 comments

Exposing action creators would allow the developer to dispatch requests for data from WordPress without having to declare that data as attached to a component using the included decorators, and also have it stored implicitly under the wordpress namespace in the store.

It would look something like:

import { fetchPost, fetchQuery } from 'kasia/creators'

store.dispatch(fetchPost(Page, 'page-slug'))
store.dispatch(fetchQuery((wpapi) => wpapi.news().embed().get()))

Probably best to pull out the query reconciliation stuff from the HOCs and share it between the various data fetching pathways.

Another thing to consider is actions whose response from the API are not normalised and placed on the store. For example, actions for creating and modifying posts:

import { createPost, modifyPost } from 'kasia/creators'

store.dispatch(createPost(post))
store.dispatch(modifyPost(id, post))

I enhance my store with actions so returning them from the kasia({ wpapi }) call made the most sense to me. Not opposed to having them exposed elsewhere.

See here: #70

Thanks @nickpalmer! I have published that onto beta.