Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

events firing before nested components load #308

Open
flohdot opened this issue Aug 27, 2013 · 1 comment
Open

events firing before nested components load #308

flohdot opened this issue Aug 27, 2013 · 1 comment

Comments

@flohdot
Copy link

flohdot commented Aug 27, 2013

I have an Aura app with a component which initializes nested components. After initializing these, I use this.sandbox.emit to send a message that the children are subscribed to. Unfortunately, the event is emitted before the child components load and it is therefore not received. Is there a way to pass a callback on child initialization?

Here is some sample code:

"parent' component

render: function() {
    var childComponents = "";
    for (var i = 0; i< this.queue.length; i++) {
      childComponents += "<div data-aura-component='"+ this.queue[i].type"' data-aura-container-index='"+ i +"'></div>";
    }
    this.html(childComponents); 
    this.showNext();
  }

loop: function() {
    if(this.index < this.queue.length) {
      setTimeout(this.showNext, this.duration);
      this.index++;
    } 
  },

  showNext: function() {
    this.sandbox.emit('play', this.index);
    this.loop();
  },

'child' component

initialize: function() { 
        this.sandbox.on('play', this.checkPlayStatus, this);
        this.render();
      },

Note: The event in question is being emitted over and over. It works all except the first time. My debugging has shown me that the issue is that the first occurrence of the event is fired before the child components are initialized. If I delay the first call of showNext() by a second, the first event does work.

Thanks!

@flohdot
Copy link
Author

flohdot commented Aug 27, 2013

Related to #307 and #304, upon further inspection. Maybe the use case is helpful for developing some promise or callback system....

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

No branches or pull requests

1 participant