Polymer 1.0: Does <iron-meta> support dynamic variable binding?

Question:

I can get my <iron-meta> instance to work correctly when using a static value. But when I bind the value to a dynamic variable (using {{}} ), it <iron-meta> no longer behaves as expected.

Does <iron-meta> support binding its value to dynamic variables?


Code:
 <iron-meta id="meta" key="info" value="foo/bar"></iron-meta> // Works <iron-meta id="meta" key="info" value="{{str}}"></iron-meta> // Fails 


Previous job:

This question is a refinement of this question in order to clarify that ONLY the thing causing the problem is a change from a static value of a string to a binding of a dynamic string value, I received many other sentences that had nothing to do with the change from static to dynamic, so I I thought itโ€™s best to rewrite the question to clarify this. But the whole context of the code is in the links there if that helps.


Alternative solutions:

In a recent talk about using <iron-localstorage> , recent chatter appeared. Perhaps this is the best way to dynamically bind essentially creating global variables?

+6
source share
2 answers

Yes, <iron-meta> supports variable binding, but maybe not the way you think.

Example: http://plnkr.co/edit/QdNepDrg9b3eCTWF6oRO?p=preview

I looked at your code here, here , and here , but I "Itโ€™s not entirely clear what your expectations are. I hope my attached reproducer can shed some light. I see that you are declaratively connected <iron-meta id="meta" key="route" xvalue="foo-bar" value="{{route}}"></iron-meta> , which is good - when the route changes, the iron-meta key="route" will be updated accordingly.

However, keep in mind that in Polymer 1.0, <iron-meta> is essentially one-way parent-child binding in the sense that you set the meta key dynamically by binding to the property; but to get this value, you will need to get it imperatively using the iron-meta byKey() method.

<iron-meta> is a simple implementation of a monostat template without a built-in path notification mechanism. This means that the values do not extend up . Therefore, doing something like

 <!-- this does not work like the way you think --> <iron-meta id="meta" key="foo" value="{{bar}}"> 

to get foo value or listen to foo changes does not work. It behaves more like a setter, where you set the foo value based on your property bound to bar data.

From what I am collecting, it seems that you are trying to implement some kind of global variable. Monostat implementation used to work in Polymer 0.5, but not in 1.0. Unfortunately, until Google approves a โ€œbest practiceโ€ model for this, suggestions prior to the date seem a little speculative to me. You can find it ( Polymer 1.0 Global Variables ).

+10
source

I have had success using <iron-signals> to convey global information. I know that there is a warning in the <iron-signals> documentation that prevents it from being used for related elements, but when broadcasting a shared resource, it looks like something. For instance:

 // source element var db = SomeDB.init(); this.fire('iron-signal', { name: 'database', data: db }); <-- sink element --> <iron-signals on-iron-signal-database="dbChange"></iron-signals> class SinkElement { dbChange(e, detail) { this.db = detail; this.db.getSomeData(); } } 
+4
source

All Articles