OLD | NEW |
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 const CustomTag(this.tagName); |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
80 } | 80 } |
81 | 81 |
82 /// To ensure Dart can interoperate with polymer-element registered by | 82 /// To ensure Dart can interoperate with polymer-element registered by |
83 /// polymer.js, we need to be able to execute Dart code if we are registering | 83 /// polymer.js, we need to be able to execute Dart code if we are registering |
84 /// a Dart class for that element. We trigger Dart logic by patching | 84 /// a Dart class for that element. We trigger Dart logic by patching |
85 /// polymer-element's register function and: | 85 /// polymer-element's register function and: |
86 /// | 86 /// |
87 /// * if it has a Dart class, run PolymerDeclaration's register. | 87 /// * if it has a Dart class, run PolymerDeclaration's register. |
88 /// * otherwise it is a JS prototype, run polymer-element's normal register. | 88 /// * otherwise it is a JS prototype, run polymer-element's normal register. |
89 void _hookJsPolymer() { | 89 void _hookJsPolymer() { |
90 // Note: platform.js is not used directly here, but we check that it is loaded | |
91 // to provide a good error message in Dartium if people forgot to include it. | |
92 // Otherwise, polymer.js below will fail with a hard to understand error | |
93 // message. | |
94 var platform = js.context['Platform']; | |
95 if (platform == null) { | |
96 throw new StateError('platform.js, dart_support.js must be loaded at' | |
97 ' the top of your application, before any other scripts or HTML' | |
98 ' imports that use polymer. Putting these two script tags at the top of' | |
99 ' your <head> element should address this issue:' | |
100 ' <script src="packages/web_components/platform.js"></script> and ' | |
101 ' <script src="packages/web_components/dart_support.js"></script>.'); | |
102 } | |
103 var polymerJs = js.context['Polymer']; | 90 var polymerJs = js.context['Polymer']; |
104 if (polymerJs == null) { | 91 if (polymerJs == null) { |
105 throw new StateError('polymer.js must be loaded before polymer.dart, please' | 92 throw new StateError('polymer.js must be loaded before polymer.dart, please' |
106 ' add <link rel="import" href="packages/polymer/polymer.html"> to your' | 93 ' add <link rel="import" href="packages/polymer/polymer.html"> to your' |
107 ' <head> before any Dart scripts. Alternatively you can get a different' | 94 ' <head> before any Dart scripts. Alternatively you can get a different' |
108 ' version of polymer.js by following the instructions at' | 95 ' version of polymer.js by following the instructions at' |
109 ' http://www.polymer-project.org.'); | 96 ' http://www.polymer-project.org.'); |
110 } | 97 } |
111 | 98 |
112 // TODO(jmesserly): dart:js appears to not callback in the correct zone: | 99 // TODO(jmesserly): dart:js appears to not callback in the correct zone: |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
148 return proto; | 135 return proto; |
149 }(); | 136 }(); |
150 | 137 |
151 // Add support for the polymer js style of enabling logging. The global logging | 138 // Add support for the polymer js style of enabling logging. The global logging |
152 // level is respected for specified loggers (see http://goo.gl/btfDe1). All | 139 // level is respected for specified loggers (see http://goo.gl/btfDe1). All |
153 // other loggers will be set to [Level.OFF]. Logs will also be printed to the | 140 // other loggers will be set to [Level.OFF]. Logs will also be printed to the |
154 // console automatically if any are supplied. | 141 // console automatically if any are supplied. |
155 void _initializeLogging() { | 142 void _initializeLogging() { |
156 hierarchicalLoggingEnabled = true; | 143 hierarchicalLoggingEnabled = true; |
157 var logFlags = js.context['logFlags']; | 144 var logFlags = js.context['logFlags']; |
| 145 if (logFlags == null) logFlags = {}; |
158 var loggers = | 146 var loggers = |
159 [_observeLog, _eventsLog, _unbindLog, _bindLog, _watchLog, _readyLog]; | 147 [_observeLog, _eventsLog, _unbindLog, _bindLog, _watchLog, _readyLog]; |
160 var polymerLogger = new Logger('polymer'); | 148 var polymerLogger = new Logger('polymer'); |
161 | 149 |
162 // If no loggers specified then disable globally and return. | 150 // If no loggers specified then disable globally and return. |
163 if (!loggers.any((logger) => logFlags[logger.name] == true)) { | 151 if (!loggers.any((logger) => logFlags[logger.name] == true)) { |
164 polymerLogger.level = Level.OFF; | 152 polymerLogger.level = Level.OFF; |
165 return; | 153 return; |
166 } | 154 } |
167 | 155 |
168 // Disable the loggers that were not specified. | 156 // Disable the loggers that were not specified. |
169 loggers.where((logger) => logFlags[logger.name] != true) | 157 loggers.where((logger) => logFlags[logger.name] != true) |
170 .forEach((logger) {logger.level = Level.OFF;}); | 158 .forEach((logger) {logger.level = Level.OFF;}); |
171 | 159 |
172 // Listen to the polymer logs and print them to the console. | 160 // Listen to the polymer logs and print them to the console. |
173 polymerLogger.onRecord.listen((rec) {print(rec);}); | 161 polymerLogger.onRecord.listen((rec) {print(rec);}); |
174 } | 162 } |
OLD | NEW |