Skip to content

Uncaught TypeError: Cannot read property 'update' of undefined #685

New issue

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

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

Already on GitHub? # to your account

Closed
fullfs opened this issue Jan 22, 2015 · 3 comments
Closed

Uncaught TypeError: Cannot read property 'update' of undefined #685

fullfs opened this issue Jan 22, 2015 · 3 comments

Comments

@fullfs
Copy link

fullfs commented Jan 22, 2015

The error points to the code

p.notify = function () {
  for (var i = 0, l = this.subs.length; i < l; i++) {
    this.subs[i].update()
  }
}

The problem occurs at the setting a big amount of data to a single property (this.offer = offer) in a complex component.
Can't reproduce it in fiddle, but it looks like subs array changes its length while iterating it in notify.

Giving up on saving up subs length fixes the problem:

for (var i = 0; i < this.subs.length; i++) {
@bdaglish
Copy link

I've had this a couple of times, but it seems to be when there's a watched/referenced property that isn't originally specified in the data {} section. Adding the property usually cures it.

@anfinil
Copy link

anfinil commented Jan 23, 2015

This issue also repeats if you try to nullify some data property that was bind several times. For example,

<div v-if='customer'>
  <div v-show='customer'>{{customer.id}}</div>
  <div v-show='customer'>{{customer.name}}</div>
</div>

When you try to set customer to null it will raise error because this.subs.length will be 3. But after first this.subs[i].update() run it will modify this.stubs and it will raise error on next loop.

@anfinil
Copy link

anfinil commented Jan 23, 2015

Changing to for (var i = 0; i < this.subs.length; i++) { fixes the problem.

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

No branches or pull requests

4 participants