Actually - this is a very nice feature, e.g. to use in behaviors, as there 
are no other clean (including data binding) way AFAIK to obtain 
singleton-ish behavior.  PLEASE don't try to 'fix' in the framework so it 
disappears :)

On Friday, March 18, 2016 at 3:42:20 PM UTC+1, Rob Stone wrote:
>
> I've just discovered something that is a little confusing and was hoping a 
> polymer expert could explain what is going on :)
>
> I've defined an element with an array property (initialised to empty) with 
> an attach method that then uses 'this.push' to add items to the array. If I 
> then create multiple instances of the element, in the browser debugger it 
> looks like the array is shared across all of these instances as each 
> subsequent copy of the element seems to inherit the array values from 
> previous elements. What's even more confusing is that if I create a 
> dom-repeat that iterates over the array, it shows the 'correct' values for 
> each instance, ie. it seems to be using an array that doesn't have 
> duplicate values in it.
>
> I have a very small test project that shows this problem, however I 
> haven't got anywhere to host it so cannot put a link up.
>
> Cut down code follows:
>
> <dom-module id="test-element">
>     <template>
>         <template is="dom-repeat" items="[[items]]">
>             <content></content>
>             <div>[[item]]</div>
>         </template>
>     </template>
>
>
>     <script>
>     (function () {
>         Polymer({
>             is: 'test-element',
>             properties: {
>                 items: {
>                     type: Array,
>                     value: []
>                 }
>             },
>
>
>             attached: function () {
>                 console.log('attached');
>                 this.push('items', "1");
>                 this.push('items', "2");
>                 this.push('items', "3");
>                 console.log('items=' + this.items); // The 1st instance 
> of the element displays 'items=1,2,3' the 2nd displays 'items=1,2,3,1,2,3' 
> !!!!
>             }
>         });
>     })();
>     </script>
> </dom-module>
>
> <!DOCTYPE html>
> <head>
>     <title>instance test</title>
>     <script 
> src="bower_components/webcomponentsjs/webcomponents-list.min.js"></script>
>     <link rel="import" href="test-element.html"></link>
> </head>
> <body>
>     <test-element>One</test-element>
>     <test-element>Two</test-element>
> </body>
> </html>
>
>
>
> I'm hoping this is a simple misunderstanding on my part, but it does have 
> some slightly annoying implications for a project I am working on.
>
> Rob
>

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 [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/polymer-dev/b6ecb9a0-2e69-4e7d-91ae-30f651053278%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to