Polymer: Polymer Component Communication

Created on 22 Nov 2015  路  3Comments  路  Source: Polymer/polymer

Hello,

One challenge I find with Polymer is in component communication model. Often times I have elements nested 3 or more levels deep. Especially when laying out components, I run into problems passing messages between components.

In Angular, I have access to a ($broadcast)[https://docs.angularjs.org/api/ng/type/$rootScope.Scope#$broadcast] method to send messages to children elements. There is also the ($emit)[https://docs.angularjs.org/api/ng/type/$rootScope.Scope#$emit] method to send messages up the chain.

From what I can tell, Polymer has listeners. However, listeners only work with the immediate parent. In addition, there isn't a good way to send a message down the tree. The only way I could figure out is to use a DOM selector and then call a method on a component that way. Is my understanding correct or is there something I'm missing. The Angular approach seems easier to work with.

question

All 3 comments

Maybe Pub/Sub could help you.

I wrote a lengthy article on approaches for communicating between elements:
https://www.polymer-project.org/0.5/articles/communication.html

It's targeted at Polymer 0.5, but the ideas are still sound. As @LM450N points out, for 1.0 https://elements.polymer-project.org/elements/iron-signals exists for pub/sub.

Closing as this is a question and not an issue.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

abdonrd picture abdonrd  路  4Comments

ghost picture ghost  路  4Comments

SergRZ picture SergRZ  路  3Comments

myuseringithub picture myuseringithub  路  3Comments

nazar-pc picture nazar-pc  路  4Comments