OLD | NEW |
---|---|
1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file |
2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
4 | 4 |
5 part of polymer; | 5 part of polymer; |
6 | 6 |
7 /** Annotation used to automatically register polymer elements. */ | 7 /** Annotation used to automatically register polymer elements. */ |
8 class CustomTag { | 8 class CustomTag { |
9 final String tagName; | 9 final String tagName; |
10 const CustomTag(this.tagName); | 10 const CustomTag(this.tagName); |
(...skipping 15 matching lines...) Expand all Loading... | |
26 * is null, first find all libraries that need to be loaded by scanning for | 26 * is null, first find all libraries that need to be loaded by scanning for |
27 * HTML imports in the main document. | 27 * HTML imports in the main document. |
28 * | 28 * |
29 * The initialization on each library is a top-level function and annotated with | 29 * The initialization on each library is a top-level function and annotated with |
30 * [initMethod]. | 30 * [initMethod]. |
31 * | 31 * |
32 * The urls in [libraries] can be absolute or relative to | 32 * The urls in [libraries] can be absolute or relative to |
33 * `currentMirrorSystem().isolate.rootLibrary.uri`. | 33 * `currentMirrorSystem().isolate.rootLibrary.uri`. |
34 */ | 34 */ |
35 void initPolymer([List<String> libraries]) { | 35 void initPolymer([List<String> libraries]) { |
36 runMicrotask(() { | 36 // Note: we synchronously load all libraries because the script invoking |
37 // DOM events don't yet go through microtasks, so we catch those here. | 37 // this is run after all HTML imports are resolved. |
blois
2013/10/21 21:08:12
Should there be a check to validate that HTML impo
Siggi Cherem (dart-lang)
2013/10/21 21:10:24
Note that we are not using the polyfill for this -
Jennifer Messerly
2013/10/21 21:42:56
Siggi do you mind following up and adding a commen
Siggi Cherem (dart-lang)
2013/10/21 21:48:03
Not a problem
| |
38 new Timer.periodic(new Duration(milliseconds: 125), | 38 if (libraries == null) { |
39 (_) => performMicrotaskCheckpoint()); | 39 libraries = _discoverScripts(document, window.location.href); |
40 } | |
41 // TODO(14262): Schedule a dummy microtask in the root Zone to prevent | |
blois
2013/10/21 21:08:12
Still necessary?
Jennifer Messerly
2013/10/21 21:42:56
nope.
| |
42 // dart:html from getting it's Zones mixed up. | |
43 scheduleMicrotask(() {}); | |
44 dirtyCheckZone().run(() => initPolymerOptimized(libraries)); | |
45 } | |
40 | 46 |
41 preventFlashOfUnstyledContent(); | 47 /** |
48 * Same as [initPolymer], but runs the version that is optimized for deployment | |
49 * to the internet. The biggest difference is it omits the [Zone] that | |
50 * automatically invokes [Observable.dirtyCheck], and the list of libraries must | |
51 * be supplied instead of being dynamically searched for at runtime. | |
52 */ | |
53 // TODO(jmesserly): change the Polymer build step to call this directly. | |
54 void initPolymerOptimized(List<String> libraries) { | |
Siggi Cherem (dart-lang)
2013/10/21 21:07:42
mmm.. this might have to change slightly once I le
Jennifer Messerly
2013/10/21 21:42:56
yeah, I expected it would change :)
just illustrat
| |
55 preventFlashOfUnstyledContent(); | |
42 | 56 |
43 // TODO(jmesserly): mdv should use initMdv instead of mdv.initialize. | 57 // TODO(jmesserly): mdv should use initMdv instead of mdv.initialize. |
44 mdv.initialize(); | 58 mdv.initialize(); |
45 document.register(PolymerDeclaration._TAG, PolymerDeclaration); | 59 document.register(PolymerDeclaration._TAG, PolymerDeclaration); |
46 | 60 |
47 // Note: we synchronously load all libraries because the script invoking | 61 _loadLibraries(libraries); |
48 // this is run after all HTML imports are resolved. | |
49 if (libraries == null) { | |
50 libraries = _discoverScripts(document, window.location.href); | |
51 } | |
52 _loadLibraries(libraries); | |
53 }); | |
54 } | 62 } |
55 | 63 |
56 void _loadLibraries(libraries) { | 64 void _loadLibraries(libraries) { |
57 for (var lib in libraries) { | 65 for (var lib in libraries) { |
58 _loadLibrary(lib); | 66 try { |
67 _loadLibrary(lib); | |
68 } catch (e, s) { | |
69 // Deliver errors async, so if a single library fails it doesn't prevent | |
70 // other things from loading. | |
71 new Completer().completeError(e, s); | |
72 } | |
59 } | 73 } |
60 Polymer._ready.complete(); | 74 |
75 customElementsReady.then((_) => Polymer._ready.complete()); | |
61 } | 76 } |
62 | 77 |
63 /** | 78 /** |
64 * Walks the HTML import structure to discover all script tags that are | 79 * Walks the HTML import structure to discover all script tags that are |
65 * implicitly loaded. | 80 * implicitly loaded. |
66 */ | 81 */ |
67 List<String> _discoverScripts(Document doc, String baseUri, | 82 List<String> _discoverScripts(Document doc, String baseUri, |
68 [Set<Document> seen, List<String> scripts]) { | 83 [Set<Document> seen, List<String> scripts]) { |
69 if (seen == null) seen = new Set<Document>(); | 84 if (seen == null) seen = new Set<Document>(); |
70 if (scripts == null) scripts = <String>[]; | 85 if (scripts == null) scripts = <String>[]; |
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
205 print("warning: methods marked with @initMethod should take no " | 220 print("warning: methods marked with @initMethod should take no " |
206 "arguments, ${method.simpleName} expects some."); | 221 "arguments, ${method.simpleName} expects some."); |
207 return; | 222 return; |
208 } | 223 } |
209 obj.invoke(method.simpleName, const []); | 224 obj.invoke(method.simpleName, const []); |
210 } | 225 } |
211 | 226 |
212 class _InitMethodAnnotation { | 227 class _InitMethodAnnotation { |
213 const _InitMethodAnnotation(); | 228 const _InitMethodAnnotation(); |
214 } | 229 } |
OLD | NEW |