Lymp
Lymp

Reputation: 973

dart-polymer scaffold. main() called for each shadowdom. Top level DART variables lose value

I'm a newbie to DART. Spent many years doing OO (PDC) Prolog. I have a beginner's knowledge of HTML5 and CSS3.

I've started playing around with Polymer paper elements, and (sampler-scaffold). I have (paper-item)s as a menu on the left, and each item opens a different HTML page. Visually, it looks and behaves fine.

1) As I understand it, main() is called for each of these HTML pages, since they're shadow doms. So my app has multiple main()s - is that OK? Each main() is called each time I choose its page from the menu. I'm trying to control what each main() does by using a global variable...next.

2) I have a top level DART variable - bool is_init, not initialised. In the main() call from index.dart, I set it to a value. I read it to check it is correct. After clicking the menu to open a "sub page", it is already NULL in that page's main().

I've also tried doing the same within a class in a library - but of course, the initialised object becomes null because of the said problem!

I obviously misunderstand something here. Clues and advice most appreciated. cheers Steve

Upvotes: 0

Views: 46

Answers (1)

Günter Zöchbauer
Günter Zöchbauer

Reputation: 657058

1) You have only one single main() for an Polymer app (entry page like index.html). You can have more than one Polymer app within one your_package/web directory though where each app has one main() method.

If all your custom code is within Polymer elements you don't even need this one main() method because there is a default one provided by Polymer.dart (see how to implement a main function in polymer apps for more details)

main() has nothing to do with Shadow DOM, nothing at all.

Each main() is called each time I choose its page from the menu.

If each of your menu items link to different Polymer applications, this might be true, but with Dart and Polymer.dart you usually build Single Page Applications where a click on a menu doesn't load a different application but instead changes what the current application displays (see http://en.wikipedia.org/wiki/Single-page_application).

2) I don't fully understand what this is about. Maybe you should provide some concrete code and name some concrete filenames which contain that code. Please edit your question accordingly.

Upvotes: 2

Related Questions