feathers-vuex icon indicating copy to clipboard operation
feathers-vuex copied to clipboard

FeathersVuexFormWrapper: watch prop is not used and default value is not in sync with the doc

Open J3m5 opened this issue 3 years ago • 2 comments

The watch prop in the FeathersVuexFormWrapper component doesn't seem to be used. And it's default value is set to true when the docs say the opposite.

J3m5 avatar Jul 04 '20 12:07 J3m5

hah! Thanks for filing. That deserves some cleanup.

marshallswain avatar Jul 07 '20 01:07 marshallswain

IMO, the default value of the watch prop should be true.

I ended up heavily customizing the FormWrapper for my use case. I needed it for a table and I thought that cloning every item would be unnecessary and would hurt perfomance if it was used with too many items. So I added a computed with a getter and a setter, the getter return the clone or the original item and the setter clone the item if the clone doesn't exist and then mutate the clone.

The only down side is that you must handle object property assignment differently as the setter doesn't handle it. You can't use v-model on the itemOrClone object so you must use :value and @input on your form inputs. So I created a utility function that forward the new value and the key for that value. With all that we can get rid of the clone watcher and only watch the item when a clone is created (when the item is edited for the first time).

I created a gist

I also fixed a bug where the clone is marked as dirty when you reset it, I did it by adding a isReset prop. And I used the deepEqual lodash function to verify if the original and clone are the same when editing. This take care of the case where the clone is edited and then reverted to the original value.

And it handle the removal of the clone in the copyByIds, but this could be an option as you could want to reset the original item even after you saved it into the DB.

I don't know what to do with all that, some changes could be applied but it might go in its own component, what do you think ?

J3m5 avatar Jul 07 '20 08:07 J3m5