Skip to content

makeFindMixin uses the same object instance for data #605

Open
@kornalius

Description

@kornalius

Steps to reproduce

This is a though one to explain, however I found the solution. I spent a few days on this one.

  1. Create 2 components that are called recursively within each other, where one of them use a makeFindMixin.
  2. Put a watcher on the is{name}FindPending data and console.log the newValue and the this._uid of the component instance.
mixins: [
  makeFindMixin({ service: 'documents', name: 'documents' })
],

watch: {
  isDocumentsFindPending (newValue) {
    console.log(newValue, this._uid)
  }
}

It will always log on the first component instance instead of on the proper instance the makeFindMixin is being used.

Solution

When you define the data function, you reuse the same data const in all instances of the makeFindMixin.
By recreating a new object from the data const, all is good.

data () {
  return { ...data }
}

An object.assign should do the job here too.

Expected behavior

The is{name}FindPending (or all props of the data object) should be changed only on the instance of the component where the mixin is defined.

Actual behavior

The is{name}FindPending data is reused on all component instances instead of having one data instance object per component instance. In other words, the dynamic data props are reused by all component instances that use the makeFindMixin mixin.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions