contactually / redux-capacitor

An easy-to-use and powerful caching REST API client for React.
9 stars 0 forks source link

Associations which have not yet been fetched are undefined #10

Open apiv opened 6 years ago

apiv commented 6 years ago

See https://github.com/paularmstrong/normalizr/issues/267

If a normalized record looks like this...

{
  id: 'contact_123',
  buckets: ['bucket_1', 'bucket_2', 'bucket_3']
}

...And bucket_2 has not yet been fetched, the denormalized result for this contact will be:

{
  id: 'contact_123',
  buckets: [
    { id: 'bucket_1', /* ...the rest... */ },
    undefined, /* <- no bueno */
    { id: 'bucket_3', /* ...the rest... */ }
  ]
}

This isn't a problem in our app yet, since we always return nested resources. When we start optimizing performance and implementing sparse fields support, this will need to be handled.

Abdull commented 6 years ago

It would be great to have redux-capacitor "lazy-load" entities when accessing them via a relationship for the first time.

As much as I understand redux-capacitor, currently it is required to explicitly fetch entities before it is possible to access them. E.g. in demo-redux-capacitor, some person's homeworld must first be fetched before it can be shown ( https://github.com/contactually/demo-redux-capacitor/blob/9087796c97638b908e8db556ad52ff50c4d6f76d/src/ConnectedPeople.js#L22 ).

Could we envision to have redux-capacitor automatically fetch entities when navigating the entity graph, i.e. when accessing an entity's relationship?