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

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

Issue 24149003: Port of github.com/polymer/polymer. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: rebase 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
« no previous file with comments | « pkg/polymer/lib/src/instance.dart ('k') | pkg/polymer/lib/src/utils.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012, 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 /** 5 part of polymer;
6 * Custom HTML tags, data binding, and templates for building
7 * structured, encapsulated, client-side web apps.
8 *
9 * Polymer.dart, the next evolution of Web UI,
10 * is an in-progress Dart port of the
11 * [Polymer project](http://www.polymer-project.org/).
12 * Polymer.dart compiles to JavaScript and runs across the modern web.
13 *
14 * To use polymer.dart in your application,
15 * first add a
16 * [dependency](http://pub.dartlang.org/doc/dependencies.html)
17 * to the app's pubspec.yaml file.
18 * Instead of using the open-ended `any` version specifier,
19 * we recommend using a range of version numbers, as in this example:
20 *
21 * dependencies:
22 * polymer: '>=0.7.1 <0.8'
23 *
24 * Then import the library into your application:
25 *
26 * import 'package:polymer/polymer.dart';
27 *
28 * ## Other resources
29 *
30 * * [Polymer.dart homepage](http://www.dartlang.org/polymer-dart/):
31 * Example code, project status, and
32 * information about how to get started using Polymer.dart in your apps.
33 *
34 * * [polymer.dart package](http://pub.dartlang.org/packages/polymer):
35 * More details, such as the current major release number.
36 *
37 * * [Upgrading to Polymer.dart](http://www.dartlang.org/polymer-dart/upgrading- to-polymer-from-web-ui.html):
38 * Tips for converting your apps from Web UI to Polymer.dart.
39 */
40 library polymer;
41
42 import 'dart:async';
43 import 'dart:mirrors';
44
45 import 'package:mdv/mdv.dart' as mdv;
46 import 'package:observe/src/microtask.dart';
47 import 'package:path/path.dart' as path;
48 import 'polymer_element.dart' show registerPolymerElement;
49
50 export 'package:custom_element/custom_element.dart';
51 export 'package:observe/observe.dart';
52 export 'package:observe/html.dart';
53 export 'package:observe/src/microtask.dart';
54
55 export 'polymer_element.dart';
56
57 6
58 /** Annotation used to automatically register polymer elements. */ 7 /** Annotation used to automatically register polymer elements. */
59 class CustomTag { 8 class CustomTag {
60 final String tagName; 9 final String tagName;
61 const CustomTag(this.tagName); 10 const CustomTag(this.tagName);
62 } 11 }
63 12
64 /** 13 /**
65 * Metadata used to label static or top-level methods that are called 14 * Metadata used to label static or top-level methods that are called
66 * automatically when loading the library of a custom element. 15 * automatically when loading the library of a custom element.
67 */ 16 */
68 const initMethod = const _InitMethodAnnotation(); 17 const initMethod = const _InitMethodAnnotation();
69 18
70 /** 19 /**
71 * Initializes a polymer application as follows: 20 * Initializes a polymer application as follows:
72 * * set up up polling for observable changes 21 * * set up up polling for observable changes
73 * * initialize MDV 22 * * initialize MDV
74 * * for each library in [libraries], register custom elements labeled with 23 * * for each library in [libraries], register custom elements labeled with
75 * [CustomTag] and invoke the initialization method on it. 24 * [CustomTag] and invoke the initialization method on it.
76 * 25 *
77 * The initialization on each library is either a method named `main` or 26 * The initialization on each library is either a method named `main` or
78 * a top-level function and annotated with [initMethod]. 27 * a top-level function and annotated with [initMethod].
79 * 28 *
80 * The urls in [libraries] can be absolute or relative to [srcUrl]. 29 * The urls in [libraries] can be absolute or relative to [srcUrl].
81 */ 30 */
82 void initPolymer(List<String> libraries, [String srcUrl]) { 31 void initPolymer(List<String> libraries, [String srcUrl]) {
83 wrapMicrotask(() { 32 runMicrotask(() {
84 // DOM events don't yet go through microtasks, so we catch those here. 33 // DOM events don't yet go through microtasks, so we catch those here.
85 new Timer.periodic(new Duration(milliseconds: 125), 34 new Timer.periodic(new Duration(milliseconds: 125),
86 (_) => performMicrotaskCheckpoint()); 35 (_) => performMicrotaskCheckpoint());
87 36
88 // TODO(jmesserly): mdv should use initMdv instead of mdv.initialize. 37 // TODO(jmesserly): mdv should use initMdv instead of mdv.initialize.
89 mdv.initialize(); 38 mdv.initialize();
39 registerCustomElement('polymer-element', () => new PolymerDeclaration());
40
90 for (var lib in libraries) { 41 for (var lib in libraries) {
91 _loadLibrary(lib, srcUrl); 42 _loadLibrary(lib, srcUrl);
92 } 43 }
93 })(); 44
45 // TODO(jmesserly): this should be in the custom_element polyfill, not here.
46 // notify the system that we are bootstrapped
47 document.body.dispatchEvent(
48 new CustomEvent('WebComponentsReady', canBubble: true));
49 });
94 } 50 }
95 51
96 /** All libraries in the current isolate. */ 52 /** All libraries in the current isolate. */
97 final _libs = currentMirrorSystem().libraries; 53 final _libs = currentMirrorSystem().libraries;
98 54
99 /** 55 /**
100 * Reads the library at [uriString] (which can be an absolute URI or a relative 56 * Reads the library at [uriString] (which can be an absolute URI or a relative
101 * URI from [srcUrl]), and: 57 * URI from [srcUrl]), and:
102 * 58 *
103 * * If present, invokes `main`. 59 * * If present, invokes `main`.
(...skipping 23 matching lines...) Expand all
127 // Search top-level functions marked with @initMethod 83 // Search top-level functions marked with @initMethod
128 for (var f in lib.functions.values) { 84 for (var f in lib.functions.values) {
129 _maybeInvoke(lib, f); 85 _maybeInvoke(lib, f);
130 } 86 }
131 87
132 for (var c in lib.classes.values) { 88 for (var c in lib.classes.values) {
133 // Search for @CustomTag on classes 89 // Search for @CustomTag on classes
134 for (var m in c.metadata) { 90 for (var m in c.metadata) {
135 var meta = m.reflectee; 91 var meta = m.reflectee;
136 if (meta is CustomTag) { 92 if (meta is CustomTag) {
137 registerPolymerElement(meta.tagName, 93 Polymer._registerClassMirror(meta.tagName, c);
138 () => c.newInstance(const Symbol(''), const []).reflectee);
139 } 94 }
140 } 95 }
141 96
142 // TODO(sigmund): check also static methods marked with @initMethod. 97 // TODO(sigmund): check also static methods marked with @initMethod.
143 // This is blocked on two bugs: 98 // This is blocked on two bugs:
144 // - dartbug.com/12133 (static methods are incorrectly listed as top-level 99 // - dartbug.com/12133 (static methods are incorrectly listed as top-level
145 // in dart2js, so they end up being called twice) 100 // in dart2js, so they end up being called twice)
146 // - dartbug.com/12134 (sometimes "method.metadata" throws an exception, 101 // - dartbug.com/12134 (sometimes "method.metadata" throws an exception,
147 // we could wrap and hide those exceptions, but it's not ideal). 102 // we could wrap and hide those exceptions, but it's not ideal).
148 } 103 }
(...skipping 17 matching lines...) Expand all
166 print("warning: methods marked with @initMethod should take no " 121 print("warning: methods marked with @initMethod should take no "
167 "arguments, ${method.simpleName} expects some."); 122 "arguments, ${method.simpleName} expects some.");
168 return; 123 return;
169 } 124 }
170 obj.invoke(method.simpleName, const []); 125 obj.invoke(method.simpleName, const []);
171 } 126 }
172 127
173 class _InitMethodAnnotation { 128 class _InitMethodAnnotation {
174 const _InitMethodAnnotation(); 129 const _InitMethodAnnotation();
175 } 130 }
OLDNEW
« no previous file with comments | « pkg/polymer/lib/src/instance.dart ('k') | pkg/polymer/lib/src/utils.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698