feathersjs-ecosystem / feathers-vuex

Integration of FeathersJS, Vue, and Nuxt for the artisan developer
https://vuex.feathersjs.com
MIT License
445 stars 108 forks source link

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

Open J3m5 opened 3 years ago

J3m5 commented 3 years ago

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. https://github.com/feathersjs-ecosystem/feathers-vuex/blob/0d76efdcf7c7ca35c8dda1020a5dc4ca0dc6a59d/src/service-module/service-module.mutations.ts#L88-L94

Then in the base model constructor, the mergeInstance mutation is called. https://github.com/feathersjs-ecosystem/feathers-vuex/blob/0d76efdcf7c7ca35c8dda1020a5dc4ca0dc6a59d/src/service-module/make-base-model.ts#L129-L133 Which then call the mergeWithAccessor function https://github.com/feathersjs-ecosystem/feathers-vuex/blob/0d76efdcf7c7ca35c8dda1020a5dc4ca0dc6a59d/src/service-module/service-module.mutations.ts#L124-L131

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 commented 3 years ago

Hi, is this fix in a release?

J3m5 commented 3 years ago

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