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

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

Issue 26051002: Updating Polymer to derive from custom elements. (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 final Type type;
11 const CustomTag(this.tagName, {Type type}) : this.type = type;
Siggi Cherem (dart-lang) 2013/10/10 22:25:51 how about: const CustomTag(this.tagName, {this.ty
blois 2013/10/11 22:40:12 Done.
11 } 12 }
12 13
13 /** 14 /**
14 * Metadata used to label static or top-level methods that are called 15 * Metadata used to label static or top-level methods that are called
15 * automatically when loading the library of a custom element. 16 * automatically when loading the library of a custom element.
16 */ 17 */
17 const initMethod = const _InitMethodAnnotation(); 18 const initMethod = const _InitMethodAnnotation();
18 19
19 /** 20 /**
20 * Initializes a polymer application as follows: 21 * Initializes a polymer application as follows:
21 * * set up up polling for observable changes 22 * * set up up polling for observable changes
22 * * initialize MDV 23 * * initialize MDV
23 * * for each library in [libraries], register custom elements labeled with 24 * * for each library in [libraries], register custom elements labeled with
24 * [CustomTag] and invoke the initialization method on it. 25 * [CustomTag] and invoke the initialization method on it.
25 * 26 *
26 * The initialization on each library is either a method named `main` or 27 * The initialization on each library is either a method named `main` or
27 * a top-level function and annotated with [initMethod]. 28 * a top-level function and annotated with [initMethod].
28 * 29 *
29 * The urls in [libraries] can be absolute or relative to [srcUrl]. 30 * The urls in [libraries] can be absolute or relative to [srcUrl].
30 */ 31 */
31 void initPolymer(List<String> libraries, [String srcUrl]) { 32 void initPolymer(List<String> libraries, [String srcUrl]) {
32 runMicrotask(() { 33 runMicrotask(() {
33 // DOM events don't yet go through microtasks, so we catch those here. 34 // DOM events don't yet go through microtasks, so we catch those here.
34 new Timer.periodic(new Duration(milliseconds: 125), 35 new Timer.periodic(new Duration(milliseconds: 125),
35 (_) => performMicrotaskCheckpoint()); 36 (_) => performMicrotaskCheckpoint());
36 37
37 // TODO(jmesserly): mdv should use initMdv instead of mdv.initialize. 38 // TODO(jmesserly): mdv should use initMdv instead of mdv.initialize.
38 mdv.initialize(); 39 mdv.initialize();
39 registerCustomElement('polymer-element', () => new PolymerDeclaration()); 40 document.register(PolymerDeclaration._TAG, PolymerDeclaration);
40 41
41 for (var lib in libraries) { 42 for (var lib in libraries) {
42 _loadLibrary(lib, srcUrl); 43 _loadLibrary(lib, srcUrl);
43 } 44 }
44 45
45 // TODO(jmesserly): this should be in the custom_element polyfill, not here. 46 // TODO(jmesserly): this should be in the custom_element polyfill, not here.
46 // notify the system that we are bootstrapped 47 // notify the system that we are bootstrapped
47 document.body.dispatchEvent( 48 document.body.dispatchEvent(
48 new CustomEvent('WebComponentsReady', canBubble: true)); 49 new CustomEvent('WebComponentsReady', canBubble: true));
49 }); 50 });
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
83 // Search top-level functions marked with @initMethod 84 // Search top-level functions marked with @initMethod
84 for (var f in lib.functions.values) { 85 for (var f in lib.functions.values) {
85 _maybeInvoke(lib, f); 86 _maybeInvoke(lib, f);
86 } 87 }
87 88
88 for (var c in lib.classes.values) { 89 for (var c in lib.classes.values) {
89 // Search for @CustomTag on classes 90 // Search for @CustomTag on classes
90 for (var m in c.metadata) { 91 for (var m in c.metadata) {
91 var meta = m.reflectee; 92 var meta = m.reflectee;
92 if (meta is CustomTag) { 93 if (meta is CustomTag) {
93 Polymer._registerClassMirror(meta.tagName, c); 94 Polymer.register(meta.tagName, meta.type);
Jennifer Messerly 2013/10/10 22:35:17 it's a bummer that we're going to have a breaking
blois 2013/10/11 22:40:12 Evil. Done.
Siggi Cherem (dart-lang) 2013/10/14 17:02:52 Now that you have the workaround, can't we get rid
94 } 95 }
95 } 96 }
96 97
97 // TODO(sigmund): check also static methods marked with @initMethod. 98 // TODO(sigmund): check also static methods marked with @initMethod.
98 // This is blocked on two bugs: 99 // This is blocked on two bugs:
99 // - dartbug.com/12133 (static methods are incorrectly listed as top-level 100 // - dartbug.com/12133 (static methods are incorrectly listed as top-level
100 // in dart2js, so they end up being called twice) 101 // in dart2js, so they end up being called twice)
101 // - dartbug.com/12134 (sometimes "method.metadata" throws an exception, 102 // - dartbug.com/12134 (sometimes "method.metadata" throws an exception,
102 // we could wrap and hide those exceptions, but it's not ideal). 103 // we could wrap and hide those exceptions, but it's not ideal).
103 } 104 }
(...skipping 17 matching lines...) Expand all
121 print("warning: methods marked with @initMethod should take no " 122 print("warning: methods marked with @initMethod should take no "
122 "arguments, ${method.simpleName} expects some."); 123 "arguments, ${method.simpleName} expects some.");
123 return; 124 return;
124 } 125 }
125 obj.invoke(method.simpleName, const []); 126 obj.invoke(method.simpleName, const []);
126 } 127 }
127 128
128 class _InitMethodAnnotation { 129 class _InitMethodAnnotation {
129 const _InitMethodAnnotation(); 130 const _InitMethodAnnotation();
130 } 131 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698