Skip to content

$broadcast not working in some instances #474

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
tim-smart opened this issue Oct 8, 2014 · 7 comments
Closed

$broadcast not working in some instances #474

tim-smart opened this issue Oct 8, 2014 · 7 comments

Comments

@tim-smart
Copy link

I have a case where I dynamically create a list of components:

<div v-repeat="actions" v-component="{{$value}}"></div>

After adding something to the list (this.actions.push('some-component')), then changing an element (this.actions = ['some-other-component']) - that component will no longer receive $broadcast events.

Let me know if you have issues reproducing this.

@tim-smart
Copy link
Author

It seems to fix itself when you reset (this.actions = []), wait for the nextTick, then update again.

@yyx990803
Copy link
Member

When you change this.actions, the components are instantiated on next tick. If you broadcast events before that happens (since events a synchronous) the new components will miss them. That might be the case.

@tim-smart
Copy link
Author

What I mean is they don’t receive broadcast events at all - no matter when they fire. Also the this._children array is empty after reproducing this issue.

It took me a bit of diving though the chrome script debugging tool to find this!

@yyx990803
Copy link
Member

Wow, can't believe how stupid this bug is... you'll know why if you look at the fix commit :P

@tim-smart
Copy link
Author

Haha, splice removing 0 elements... nice!

@yyx990803
Copy link
Member

It actually deletes all elements after that index! (hence the empty _children array)

@tim-smart
Copy link
Author

Oh wow, learn something every day

# 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

2 participants