Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, 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 /** |
| 6 * This library exports all of the commonly used functions and types for | 6 * This library exports all of the commonly used functions and types for |
| 7 * building UI's. | 7 * building UI's. |
| 8 * | 8 * |
| 9 * See this article for more information: | 9 * See this article for more information: |
| 10 * <http://www.dartlang.org/articles/dart-web-components/>. | 10 * <http://www.dartlang.org/articles/dart-web-components/>. |
| 11 */ | 11 */ |
| 12 library polymer; | 12 library polymer; |
| 13 | 13 |
| 14 import 'dart:async'; | |
| 15 import 'dart:mirrors' show currentMirrorSystem; | |
| 16 | |
| 17 import 'package:mdv/mdv.dart' as mdv; | |
| 18 import 'package:observe/observe.dart' show Observable; | |
| 19 import 'polymer_element.dart' show registerPolymerElement; | |
| 20 | |
| 14 export 'custom_element.dart'; | 21 export 'custom_element.dart'; |
| 15 export 'event.dart'; | 22 export 'event.dart'; |
| 16 export 'observe.dart'; | 23 export 'observe.dart'; |
| 24 export 'package:observe/observe.dart'; | |
| 17 export 'observe_html.dart'; | 25 export 'observe_html.dart'; |
| 18 export 'polymer_element.dart'; | 26 export 'polymer_element.dart'; |
| 19 export 'safe_html.dart'; | 27 export 'safe_html.dart'; |
| 20 export 'scoped_css.dart'; | 28 export 'scoped_css.dart'; |
| 29 | |
| 30 | |
| 31 /** Annotation used to automatically register polymer elements. */ | |
| 32 class CustomTag { | |
| 33 final String tagName; | |
| 34 const CustomTag(this.tagName); | |
| 35 } | |
| 36 | |
| 37 /** All libraries in the current isolate. */ | |
| 38 var _libs = currentMirrorSystem().libraries; | |
| 39 | |
| 40 /** | |
| 41 * Registers any [PolymerElement] in the library at [uri] that is marked | |
| 42 * 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
| |
| 43 */ | |
| 44 void _registerPolymerElementsOf(String uri) { | |
| 45 for (var c in _libs[Uri.parse(uri)].classes.values) { | |
| 46 for (var m in c.metadata) { | |
| 47 var meta = m.reflectee; | |
| 48 if (meta is CustomTag) { | |
| 49 registerPolymerElement(meta.tagName, | |
| 50 () => c.newInstance(const Symbol(''), const []).reflectee); | |
| 51 } | |
| 52 } | |
| 53 } | |
| 54 } | |
| 55 | |
| 56 /** | |
| 57 * Initializes a polymer application by: setting up polling for observable | |
| 58 * changes, initializing MDV, registering custom eleemnts from each library in | |
| 59 * [elementLibraries], and finally invoking [userMain]. | |
| 60 */ | |
| 61 initPolymer(List<String> elementLibraries, void userMain()) { | |
| 62 new Timer.periodic(new Duration(milliseconds: 125), | |
| 63 (_) => Observable.dirtyCheck()); | |
| 64 | |
| 65 // TODO(jmesserly): mdv should use initMdv instead of mdv.initialize. | |
| 66 mdv.initialize(); | |
| 67 for (var lib in elementLibraries) { | |
| 68 _registerPolymerElementsOf(lib); | |
| 69 } | |
| 70 userMain(); | |
| 71 } | |
| OLD | NEW |