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'; | 14 import 'dart:async'; |
15 import 'dart:mirrors'; | 15 import 'dart:mirrors'; |
16 | 16 |
17 import 'package:mdv/mdv.dart' as mdv; | 17 import 'package:mdv/mdv.dart' as mdv; |
18 import 'package:observe/observe.dart' show Observable; | 18 import 'package:observe/src/microtask.dart'; |
19 import 'package:path/path.dart' as path; | 19 import 'package:path/path.dart' as path; |
20 import 'polymer_element.dart' show registerPolymerElement; | 20 import 'polymer_element.dart' show registerPolymerElement; |
21 | 21 |
22 export 'package:custom_element/custom_element.dart'; | 22 export 'package:custom_element/custom_element.dart'; |
23 export 'package:observe/observe.dart'; | 23 export 'package:observe/observe.dart'; |
| 24 export 'package:observe/src/microtask.dart'; |
24 | 25 |
25 export 'event.dart'; | |
26 export 'observe.dart'; | 26 export 'observe.dart'; |
27 export 'observe_html.dart'; | 27 export 'observe_html.dart'; |
28 export 'polymer_element.dart'; | 28 export 'polymer_element.dart'; |
29 export 'safe_html.dart'; | 29 export 'safe_html.dart'; |
30 export 'scoped_css.dart'; | |
31 | 30 |
32 | 31 |
33 /** Annotation used to automatically register polymer elements. */ | 32 /** Annotation used to automatically register polymer elements. */ |
34 class CustomTag { | 33 class CustomTag { |
35 final String tagName; | 34 final String tagName; |
36 const CustomTag(this.tagName); | 35 const CustomTag(this.tagName); |
37 } | 36 } |
38 | 37 |
39 /** | 38 /** |
40 * Metadata used to label static or top-level methods that are called | 39 * Metadata used to label static or top-level methods that are called |
41 * automatically when loading the library of a custom element. | 40 * automatically when loading the library of a custom element. |
42 */ | 41 */ |
43 const polymerInitMethod = const _InitPolymerAnnotation(); | 42 const polymerInitMethod = const _InitPolymerAnnotation(); |
44 | 43 |
45 /** | 44 /** |
46 * Initializes a polymer application by: setting up polling for observable | 45 * Initializes a polymer application by: setting up polling for observable |
47 * changes, initializing MDV, registering and initializing custom elements from | 46 * changes, initializing MDV, registering and initializing custom elements from |
48 * each library in [elementLibraries], and finally invoking [userMain]. | 47 * each library in [elementLibraries], and finally invoking [userMain]. |
49 * | 48 * |
50 * There are two mechanisms by which custom elements can be initialized: | 49 * There are two mechanisms by which custom elements can be initialized: |
51 * annotating the class that declares a custom element with [CustomTag] or | 50 * annotating the class that declares a custom element with [CustomTag] or |
52 * programatically registering the element in a static or top-level function and | 51 * programatically registering the element in a static or top-level function and |
53 * annotating that function with [polymerInitMethod]. | 52 * annotating that function with [polymerInitMethod]. |
54 * | 53 * |
55 * The urls in [elementLibraries] can be absolute or relative to [srcUrl]. | 54 * The urls in [elementLibraries] can be absolute or relative to [srcUrl]. |
56 */ | 55 */ |
57 initPolymer(List<String> elementLibraries, void userMain(), [String srcUrl]) { | 56 void initPolymer(List<String> elementLibraries, void userMain(), [String srcUrl]
) { |
58 new Timer.periodic(new Duration(milliseconds: 125), | 57 wrapMicrotask(() { |
59 (_) => Observable.dirtyCheck()); | 58 // DOM events don't yet go through microtasks, so we catch those here. |
| 59 new Timer.periodic(new Duration(milliseconds: 125), |
| 60 (_) => performMicrotaskCheckpoint()); |
60 | 61 |
61 // TODO(jmesserly): mdv should use initMdv instead of mdv.initialize. | 62 // TODO(jmesserly): mdv should use initMdv instead of mdv.initialize. |
62 mdv.initialize(); | 63 mdv.initialize(); |
63 for (var lib in elementLibraries) { | 64 for (var lib in elementLibraries) { |
64 _registerPolymerElementsOf(lib, srcUrl); | 65 _registerPolymerElementsOf(lib, srcUrl); |
65 } | 66 } |
66 userMain(); | 67 userMain(); |
| 68 })(); |
67 } | 69 } |
68 | 70 |
69 /** All libraries in the current isolate. */ | 71 /** All libraries in the current isolate. */ |
70 var _libs = currentMirrorSystem().libraries; | 72 final _libs = currentMirrorSystem().libraries; |
71 | 73 |
72 /** | 74 /** |
73 * Reads the library at [uriString] (which can be an absolute URI or a relative | 75 * Reads the library at [uriString] (which can be an absolute URI or a relative |
74 * URI from [srcUrl]), and: | 76 * URI from [srcUrl]), and: |
75 * | 77 * |
76 * * Invokes top-level and static functions marked with the | 78 * * Invokes top-level and static functions marked with the |
77 * [polymerInitMethod] annotation. | 79 * [polymerInitMethod] annotation. |
78 * | 80 * |
79 * * Registers any [PolymerElement] that is marked with the [CustomTag] | 81 * * Registers any [PolymerElement] that is marked with the [CustomTag] |
80 * annotation. | 82 * annotation. |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
132 print("warning: methods marked with @polymerInitMethod should take no " | 134 print("warning: methods marked with @polymerInitMethod should take no " |
133 "arguments, ${method.simpleName} expects some."); | 135 "arguments, ${method.simpleName} expects some."); |
134 return; | 136 return; |
135 } | 137 } |
136 obj.invoke(method.simpleName, const []); | 138 obj.invoke(method.simpleName, const []); |
137 } | 139 } |
138 | 140 |
139 class _InitPolymerAnnotation { | 141 class _InitPolymerAnnotation { |
140 const _InitPolymerAnnotation(); | 142 const _InitPolymerAnnotation(); |
141 } | 143 } |
OLD | NEW |