Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ReplaceItems option doesn't works when patching/updating value with null #599

Open
J3m5 opened this issue May 26, 2021 · 2 comments
Open

Comments

@J3m5
Copy link
Contributor

J3m5 commented May 26, 2021

Steps to reproduce

If you make an update with deleted properties or a patch with properties with null values, you'll get back the new items from the api without those properties.
When adding the replaceItems for the items to be completely replaced, this doesn't works because a merge is still done at the end, the items are not replaced.

Expected behavior

The replaceItems option should really replace the item.

Actual behavior

With replaceItems set to true and with an existing item, a new instance is created with the item received from the api.

if (replaceItems) {
if (Model && !(item instanceof Model)) {
item = new Model(item)
}
Vue.set(state.keyedById, id, item)
// Merge in changes
} else {

Then in the base model constructor, the mergeInstance mutation is called.

if (existingItem) {
data = setupInstance.call(this, data, { models, store }) || data
_commit.call(this.constructor, 'mergeInstance', data)
return existingItem
}

Which then call the mergeWithAccessor function
function mergeInstance(state, item) {
const { idField } = state
const id = getId(item, idField)
const existingItem = state.keyedById[id]
if (existingItem) {
mergeWithAccessors(existingItem, item)
}
}

Possible solution

The mergeInstance mutation in the base model should be called only if replaceItems is not set to true.

System configuration

Module versions: 3.16.0

NodeJS version: 14.17.0

@corepay
Copy link

corepay commented Jul 1, 2021

Hi, is this fix in a release?

@J3m5
Copy link
Contributor Author

J3m5 commented Jul 1, 2021

Hi, not yet @corepay
Any idea when you can take a look @marshallswain ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants