Chromium Code Reviews| Index: lib/polymer.dart |
| diff --git a/lib/polymer.dart b/lib/polymer.dart |
| index b81a01d3001886e591acfc09832317ca57c5e804..60eba1b7d473a2eb2977e98d3d27895b1eaac752 100644 |
| --- a/lib/polymer.dart |
| +++ b/lib/polymer.dart |
| @@ -11,10 +11,61 @@ |
| */ |
| library polymer; |
| +import 'dart:async'; |
| +import 'dart:mirrors' show currentMirrorSystem; |
| + |
| +import 'package:mdv/mdv.dart' as mdv; |
| +import 'package:observe/observe.dart' show Observable; |
| +import 'polymer_element.dart' show registerPolymerElement; |
| + |
| export 'custom_element.dart'; |
| export 'event.dart'; |
| export 'observe.dart'; |
| +export 'package:observe/observe.dart'; |
| export 'observe_html.dart'; |
| export 'polymer_element.dart'; |
| export 'safe_html.dart'; |
| export 'scoped_css.dart'; |
| + |
| + |
| +/** Annotation used to automatically register polymer elements. */ |
| +class CustomTag { |
| + final String tagName; |
| + const CustomTag(this.tagName); |
| +} |
| + |
| +/** All libraries in the current isolate. */ |
| +var _libs = currentMirrorSystem().libraries; |
| + |
| +/** |
| + * Registers any [PolymerElement] in the library at [uri] that is marked |
| + * with the [CustomTag] annotation. |
|
Jennifer Messerly
2013/07/30 00:56:12
did we lose support for "_init"? I'm worried a lit
Siggi Cherem (dart-lang)
2013/07/30 23:32:04
Ok, I added it back. Now we have both options. I c
|
| + */ |
| +void _registerPolymerElementsOf(String uri) { |
| + for (var c in _libs[Uri.parse(uri)].classes.values) { |
| + for (var m in c.metadata) { |
| + var meta = m.reflectee; |
| + if (meta is CustomTag) { |
| + registerPolymerElement(meta.tagName, |
| + () => c.newInstance(const Symbol(''), const []).reflectee); |
| + } |
| + } |
| + } |
| +} |
| + |
| +/** |
| + * Initializes a polymer application by: setting up polling for observable |
| + * changes, initializing MDV, registering custom eleemnts from each library in |
| + * [elementLibraries], and finally invoking [userMain]. |
| + */ |
| +initPolymer(List<String> elementLibraries, void userMain()) { |
| + new Timer.periodic(new Duration(milliseconds: 125), |
| + (_) => Observable.dirtyCheck()); |
| + |
| + // TODO(jmesserly): mdv should use initMdv instead of mdv.initialize. |
| + mdv.initialize(); |
| + for (var lib in elementLibraries) { |
| + _registerPolymerElementsOf(lib); |
| + } |
| + userMain(); |
| +} |