Merge records in update
See original GitHub issueRe: updateStart and updateSuccess. The API says the updated records are ‘merged with the current state’. I took this to mean that the results of the update operation are merged with the current record, i.e. if the application state for the resource looks like
[0: {id: 'exampleId', width: 10}]
and we dispatch an action thus:
updateStart({id: 'exampleId', height: 20})
the updated state would look like:
[0: {id: 'exampleId', width: 10, height: 20}]
As it is, though, the width property is lost, and I’m getting
[0: {id: 'exampleId', height: 10}]
Is this expected behaviour, that is to say, update operations update records in the current state, using the given key, but overwrite the record contents, rather than merging them? Or am I using the library incorrectly? I’ll submit code to reproduce if needed.
Thanks for your help, this library looks like just what I need!
Issue Analytics
- State:
- Created 7 years ago
- Reactions:1
- Comments:9 (6 by maintainers)
Is there going to be a future update for this ? Maybe an option like this: updateSuccess(item, {merge: true}) ?
Thanks for your reply!
I wonder whether this is desirable behaviour. In order to dispatch updateStart or updateSuccess, the user must have merged their desired changes with the entire preexisting record, or lose their existing model data.
This action almost always necessitates a call to a selector, because it’s unlikely that the part of the app making the update call knows about the entire model. As in the example above, a form that edits width but not height will need to pull the model beforehand and merge before calling
updateStart
orupdateSuccess
:Whereas if we were merging in the library, this operation would look like
I’m probably missing something, but is there a use case in which not merging (the current behaviour) is necessary or desirable? If not, I’d be happy to submit a PR either changing this behaviour or making it configurable.