bhoriuchi / vue-deepset

Deep set Vue.js objects

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Error when the parent property of a child property is a null

pyrostrex opened this issue · comments

Example data:

{
  fields: {
    propertyA: null
  }
}

Example html used:

<input v-model="model['propertyA.childPropertyA']" />

Example of computed (same as example):

model: {
  return this.$deepModel(this.fields);
}

Error:

Error in render function: "TypeError: Cannot convert undefined or null to object"

Expected json output:

{
  fields: {
    propertyA: {}
  }
}

Thank you for this wonderful library.

I will look into this as soon as I can. Thanks!

This has been resolved with a null check in the vueSet method. See source

Original

if (!_.hasPath(obj, prop)) Vue.set(obj, prop, (fields.length >= 1 && typeof fields[0] === 'number') ? [] : {})

Updated

if (!_.hasPath(obj, prop) || obj[prop] === null) {
Vue.set(obj, prop, (fields.length >= 1 && typeof fields[0] === 'number') ? [] : {})
}

v0.5.2 has been published to npm with the fix.

Additionally setting the property to undefined instead of null would have probably worked in the previous version. The current fix could cause issue if the developer tries set a higher path to null and another piece of code tries to set a lower path, the lower path will always win. This is probably the most desired behavior which is why I went ahead and published this change.