How one component can listen to another component ready event

44 views
Skip to first unread message

chintu m

unread,
Feb 13, 2017, 1:39:40 AM2/13/17
to Polymer
Hello,

I have a Component A and inside this component, i want to listen to Component B ready event without dispatching any custom events  from Component B.

to.ks...@gmail.com

unread,
Feb 13, 2017, 10:33:29 AM2/13/17
to Polymer
I'm not sure it's possible, unless there is a way to do so with a JavaScript listener somehow. Otherwise, I believe a custom event would have to be fired from component B and listened for by component A, or alternatively you could use an iron-signal. However, since component A is a parent of component B, firing a custom event would make more sense rather than using a signal.

Arthur Evans

unread,
Feb 13, 2017, 3:41:24 PM2/13/17
to chintu m, Polymer
If by "inside," you mean, "in component A's local DOM template," then component A's `ready` callback isn't invoked until after component B's `ready` callback. If you're adding component B dynamically, or component B is in component A's light DOM, it's more complicated.

The element does have an isAttached property, which you could check. This won't be true until the element is ready and attached. But there's no event fired when the component is ready unless you add one yourself.

If you add a component dynamically, you could call `Polymer.dom.flush` to force it to ready itself--among other things, I believe that call flushes the queue of elements waiting to be upgraded--but forcing that kind of synchronous behavior is probably a performance antipattern.

Cheers,
Arthur


On Sun, Feb 12, 2017 at 10:39 PM, chintu m <chint...@gmail.com> wrote:
Hello,

I have a Component A and inside this component, i want to listen to Component B ready event without dispatching any custom events  from Component B.

Follow Polymer on Google+: plus.google.com/107187849809354688692
---
You received this message because you are subscribed to the Google Groups "Polymer" group.
To unsubscribe from this group and stop receiving emails from it, send an email to polymer-dev+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/polymer-dev/496dbbb9-8b68-4efa-b8f5-51c63b45115d%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages