Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(206)

Side by Side Diff: pkg/polymer/lib/src/loader.dart

Issue 27903006: Improves how to initialize polymer apps and fixes polymer build and linter to (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 7 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 14 matching lines...) Expand all
25 * [CustomTag] and invoke the initialization method on it. If [libraries] 25 * [CustomTag] and invoke the initialization method on it. If [libraries]
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() {
36 runMicrotask(() { 36 runMicrotask(() {
37 // DOM events don't yet go through microtasks, so we catch those here. 37 // DOM events don't yet go through microtasks, so we catch those here.
38 new Timer.periodic(new Duration(milliseconds: 125), 38 new Timer.periodic(new Duration(milliseconds: 125),
39 (_) => performMicrotaskCheckpoint()); 39 (_) => performMicrotaskCheckpoint());
40 40
41 preventFlashOfUnstyledContent(); 41 preventFlashOfUnstyledContent();
42 42
43 // TODO(jmesserly): mdv should use initMdv instead of mdv.initialize. 43 // TODO(jmesserly): mdv should use initMdv instead of mdv.initialize.
44 mdv.initialize(); 44 mdv.initialize();
45 document.register(PolymerDeclaration._TAG, PolymerDeclaration); 45 document.register(PolymerDeclaration._TAG, PolymerDeclaration);
46 46
47 // Note: we synchronously load all libraries because the script invoking 47 // Note: we synchronously load all libraries because the script invoking
48 // this is run after all HTML imports are resolved. 48 // this is run after all HTML imports are resolved.
49 if (libraries == null) { 49 _loadLibraries();
50 libraries = _discoverScripts(document, window.location.href);
51 }
52 _loadLibraries(libraries);
53 }); 50 });
54 } 51 }
55 52
56 void _loadLibraries(libraries) { 53 List<String> librariesToLoad =
57 for (var lib in libraries) { 54 _discoverScripts(document, window.location.href);
55
56 void _loadLibraries() {
57 for (var lib in librariesToLoad) {
58 _loadLibrary(lib); 58 _loadLibrary(lib);
59 } 59 }
60 Polymer._ready.complete(); 60 Polymer._ready.complete();
61 } 61 }
62 62
63 /** 63 /**
64 * Walks the HTML import structure to discover all script tags that are 64 * Walks the HTML import structure to discover all script tags that are
65 * implicitly loaded. 65 * implicitly loaded.
66 */ 66 */
67 List<String> _discoverScripts(Document doc, String baseUri, 67 List<String> _discoverScripts(Document doc, String baseUri,
(...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after
205 print("warning: methods marked with @initMethod should take no " 205 print("warning: methods marked with @initMethod should take no "
206 "arguments, ${method.simpleName} expects some."); 206 "arguments, ${method.simpleName} expects some.");
207 return; 207 return;
208 } 208 }
209 obj.invoke(method.simpleName, const []); 209 obj.invoke(method.simpleName, const []);
210 } 210 }
211 211
212 class _InitMethodAnnotation { 212 class _InitMethodAnnotation {
213 const _InitMethodAnnotation(); 213 const _InitMethodAnnotation();
214 } 214 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698