2

I have some code:

// main.dart:
void main{
  initPolymer();
  var view = new ChatAppConsumer();
}

//chat_app.dart
@CustomTag('chat-app')
class ChatApp extends PolymerElement{
  ChatApp.created():super.created();
}

class ChatAppConsumer{
  final ChatApp view = new Element.tag('chat-app');
}

as far as I can tell I have all my files properly referenced and Im calling initPolymer(); before I attempt to create my custom tag, but I get the type error that the HtmlElement returned by new Element.tag('chat-app'); is not of typeChatApp` but I use this exact same pattern in another package I have and it works perfectly there. Anyone come across something like this before?

Günter Zöchbauer
  • 623,577
  • 216
  • 2,003
  • 1,567
Daniel Robinson
  • 13,806
  • 18
  • 64
  • 112

1 Answers1

2

initPolymer is not enough, you should pass a closure to initPolymer.run(() => ...) which executes your Polymer related code.

See how to implement a main function in polymer apps for more details

= Polymer 0.16.0 // main.dart: void main{ initPolymer().then((zone) => zone.run(() { var view = new ChatAppConsumer(); })); }

< Polymer 0.16.0

// main.dart:
void main{
  initPolymer().run(() {
    var view = new ChatAppConsumer();
  });
}
Community
  • 1
  • 1
Günter Zöchbauer
  • 623,577
  • 216
  • 2,003
  • 1,567
  • I'll give this ago but I don't see it as necessary as I do the exact same thing [here](https://github.com/0xor1/purity_stopwatch_example/blob/dev/test/integration/index_without_purity.dart#L13) and as you can see [it works](http://0xor1.github.io/purity_stopwatch_example/without_purity/) – Daniel Robinson Nov 12 '14 at 08:53
  • It is a timing issue that doesn't occur in all configurations but to ensure the correct timing you should definitely do it this way. As far as I remember this didn't cause problems until run as JavaScript. The Polymer initialization is changing often from one Polymer version to the next so this might work in one version but not in the next. I do not have a lot of experience with this problem because I either don't use a custom `main()` at all in Polymer applications or when I have to, I ensure proper initialization (see my answer). – Günter Zöchbauer Nov 12 '14 at 08:58
  • as an aside if .run(()=>) is supposed to be run after init is complete that would seem to be just like a future so it seems odd they didnt choose to just use, .then(()=>), ah well, thanks for the answer – Daniel Robinson Nov 12 '14 at 09:00
  • I wondered about the same thing but didn't investigate or ask. Maybe they choose this form because it's similar in Polymer.js (don't know if it actually is) or maybe because the have to run some code after your passed closure was executed (doubt it). – Günter Zöchbauer Nov 12 '14 at 09:03