4

With Polymer, I have implemented a custom form, which is using polymer_signals.html for listening to changes from arbitrary other polymer elements.

It is implemented like this:

<link rel="import" href="packages/polymer_elements/polymer_signals/polymer_signals.html">

<polymer-element name="user-settings" extends="form">
<template>
<polymer-signals on-polymer-signalauth-changed="{{onAuth}}"></polymer-signals>
...

This element is dynamically instantiated in a parent polymer element like this:

var userSettings = new Element.tag('form', 'user-settings');
$['main'].children.add(userSettings);

This raises the exception:

Exception: Concurrent modification during iteration: Instance(length:4) of '_GrowableList'._notify@0x1c4cf589 (http://127.0.0.1:3030/buddy/web/packages/polymer_elements/polymer_signals/polymer_signals.dart:39:12)
<anonymous closure> (http://127.0.0.1:3030/buddy/web/packages/polymer_elements/polymer_signals/polymer_signals.dart:49:12)

If I statically instantiate the polymer-form, I don't get this error. How can I prevent this?

David C
  • 7,204
  • 5
  • 46
  • 65
tusj
  • 287
  • 2
  • 11
  • Cool you are using polymer_elements. Hopefully we will publish a new release soon (still a few issues to solve though). Sorry, I'm already too tired to investigate. I'll check tomorrow and answer then. At first sight it seems like a Polymer bug. It might be that a workaround is possible. I'll have to try a few things... – Günter Zöchbauer Apr 02 '14 at 20:04

1 Answers1

2

I can't reproduce your problem.

There are two common things that are often missed

  1. if you have a custom main method
    see the answer to Polymer querySelector working on DartVM but not in Chrome after compile

  2. call of super.polymerCreated() in the constructor of elements that extend DOM elements. see the answer to Custom Polymer element extending AElement in Dart

If you still can't solve the problem please add more code to your question (for example how your user-settings element looks like).

Community
  • 1
  • 1
Günter Zöchbauer
  • 623,577
  • 216
  • 2,003
  • 1,567
  • I will see if I can isolate the problem better. From the exception it looks like some concurrency issues, because I am having several instances of ``````. But only one is dynamically added. – tusj Apr 03 '14 at 08:45
  • I had it two times added statically and two times dynamically (one inside a normal polymer element and one in an polymer element that derives from a form element). Did you verify the points in my answer? I executed the code to add the elements dynamically in `main()` not in a method of another element. In which method is your `new Element.tag()` code? – Günter Zöchbauer Apr 03 '14 at 08:48
  • I have done some more testing now. I have made sure to check your suggestions, but it is not the problem. I think the problem is because the code adding the element containing the ```` is called when listening to an event fired by polymer-signal. Because polymer-signals is currently iterating all its listeners about an event, it fails adding another listener, because it does not have a concurrent protection. I tested adding my element outside of polymer-signals, and it works. It also works to wrap the creation of the new element within a Future, or after a delay. Bug? – tusj Apr 03 '14 at 12:34
  • I haven't ported this element and not used yet so my knowledge is limited. I agree with your reasoning. This was my first thought when I saw the code where the exception is thrown. But how can this be connected with the method you add the element? I guess a workaround would be to iterate over a copy of the `_signals` list. – Günter Zöchbauer Apr 03 '14 at 12:46
  • Do you use a hosted release of polymer_elements or a clone from the GitHub repo? – Günter Zöchbauer Apr 03 '14 at 12:50
  • The release is fetched with pub, so i guess pub.dartlang.org would be the host. Should I rather use the github repo? – tusj Apr 03 '14 at 13:20
  • I was thinking what is the easiest way to bring the workaround to you so you can test it. It would be cool if you could try the version from the GitHub repo. – Günter Zöchbauer Apr 03 '14 at 13:30
  • I have checked the source on github now. I see your fix. – tusj Apr 03 '14 at 13:47
  • And does it help? :D I can't verify if it works because I can't reproduce your issue. – Günter Zöchbauer Apr 03 '14 at 13:49
  • Your fix seems to work fine. Thanks! But I am skeptic towards my explanations based on what I see from the source, as I can't see the concurrent add and read issue. Every polymer-signal instance will define it's own list. --Just needed some time to test:) – tusj Apr 03 '14 at 13:55
  • Your comment is not entirely clear to me. Does it all work as expected now or do you still have some kind of issue? – Günter Zöchbauer Apr 03 '14 at 13:58
  • The original problem with the exception is solved, because it now works without a delay or wrapping in a future. So yes, I consider it to be working. But, I now seem to have issues with actually catching a polymer-signal, which for now needs to be delayed. Might be related, but I have to investigate more. – tusj Apr 03 '14 at 14:15