- Colocation of requests and where the properties at being used
- Bubbling up/emrging duplicate requests (is this even really possible or good w/ json-api?)
- Helpful warning messages for improving requests (eg "You're requesting all fields, but only selecting 3.")
- Simplify selecting fields from the requested resource (eliminate caller needing to use safe-access)
- Auto namespace requests
- Select request state (use
getLoadingFninternally) - Internalize all things like makeRefReducer… these are implementation details a caller shouldn't care about (maybe a separate module for all this tooling?)
- Avoid abstracting away json-api details… it should be obvious that's the type of api we're working with?
- How do we handle pagination?
Sits on top of react-redux connect. Shooting for similar interface w/ some configuration
around making json-api requests.
import { connectJsonApi } from 'connect-json-api'
import PostList from 'components/PostList'
const requests = {
posts: { // used for namespacing requests… maybe prepend componentName as well?
resourcePath: '/posts', // default to get
includes: ['user'],
fields: ['user.fullName'],
filter: { name: 'drk' }, // and other json api query params
props: { // if `props` ommitted return { posts, postsRequestStatus } by default?
postsRequestStatus: 'requestStatuss', // special key? contains isLoading, isPending?
posts: function (ref) => {
// if you want to do any custom mapping?
},
altPosts: [
'user.fullName' // useful for grabbing exact fields when not specified on requests
], // assumes accessing from the ref so access(ref, 'field.field')
letFieldsDoTheWorkPosts: 'ref' // just grab all the things defined in the `fields` option
}
},
updatePost: {
resourcePath: '/posts',
method: 'PATCH',
dispatch: {
updatePost: payload => payload // dispatches request actions etc
},
props: {
requestStats: 'requestStatus',
}
}
}
export default connectJsonApi({
requests
})(PostList)