Chromium Code Reviews| Index: pkg/polymer/lib/src/loader.dart |
| diff --git a/pkg/polymer/lib/src/loader.dart b/pkg/polymer/lib/src/loader.dart |
| index 13e8b1c765fdef0f6e61a17c6aa74487ca9e86ea..3b058bab8085c866714f6ea7b7238ec7636c8041 100644 |
| --- a/pkg/polymer/lib/src/loader.dart |
| +++ b/pkg/polymer/lib/src/loader.dart |
| @@ -20,32 +20,39 @@ class InitMethodAnnotation { |
| const InitMethodAnnotation(); |
| } |
| -/// This method is deprecated. It used to be where polymer initialization |
| -/// happens, now this is done automatically from bootstrap.dart. |
| -@deprecated |
| +/// Initializes a polymer application as follows: |
| +/// * if running in development mode, set up a dirty-checking zone that polls |
| +/// for observable changes |
| +/// * initialize template binding and polymer-element |
| +/// * Include some style to prevent flash of unstyled content (FOUC) |
|
Jennifer Messerly
2014/05/23 07:20:06
just curious, is the FOUC code still there? I thou
Siggi Cherem (dart-lang)
2014/05/23 17:56:33
Good point. This commment came with the revert, bu
|
| +/// * for each library included transitively from HTML and HTML imports, |
| +/// register custom elements declared there (labeled with [CustomTag]) and |
| +/// invoke the initialization method on it (top-level functions annotated with |
| +/// [initMethod]). |
| Zone initPolymer() { |
| - window.console.error(_ERROR); |
| - return Zone.current; |
| + if (loader.deployMode) { |
| + startPolymer(loader.initializers, loader.deployMode); |
| + return Zone.current; |
| + } |
| + return dirtyCheckZone()..run( |
| + () => startPolymer(loader.initializers, loader.deployMode)); |
| } |
| -const _ERROR = ''' |
| -initPolymer is now deprecated. To initialize a polymer app: |
| - * add to your page: <link rel="import" href="packages/polymer/polymer.html"> |
| - * replace "application/dart" mime-types with "application/dart;component=1" |
| - * if you use "init.dart", remove it |
| - * if you have a main, change it into a method annotated with @initMethod |
| -'''; |
| - |
| /// True if we're in deployment mode. |
| bool _deployMode = false; |
| +bool _startPolymerCalled = false; |
| + |
| /// Starts polymer by running all [initializers] and hooking the polymer.js |
| /// code. **Note**: this function is not meant to be invoked directly by |
| -/// application developers. It is invoked by a bootstrap entry point that is |
| -/// automatically generated. During development, this entry point is generated |
| -/// dynamically in `boot.js`. Similarly, pub-build generates this entry point |
| -/// for deployment. |
| +/// application developers. It is invoked either by [initPolymer] or, if you are |
| +/// using the experimental bootstrap API, this would be invoked by an entry |
| +/// point that is automatically generated somehow. In particular, during |
| +/// development, the entry point would be generated dynamically in `boot.js`. |
| +/// Similarly, pub-build would generate the entry point for deployment. |
| void startPolymer(List<Function> initializers, [bool deployMode = true]) { |
| + if (_startPolymerCalled) throw 'Initialization was already done.'; |
| + _startPolymerCalled = true; |
| _hookJsPolymer(); |
| _deployMode = deployMode; |
| @@ -54,6 +61,15 @@ void startPolymer(List<Function> initializers, [bool deployMode = true]) { |
| } |
| } |
| +/// Configures [initPolymer] making it optimized for deployment to the internet. |
| +/// With this setup the initializer list is supplied instead of searched for |
| +/// at runtime. Additionally, after this method is called [initPolymer] omits |
| +/// the [Zone] that automatically invokes [Observable.dirtyCheck]. |
| +void configureForDeployment(List<Function> initializers) { |
| + loader.initializers = initializers; |
| + loader.deployMode = true; |
| +} |
| + |
| /// To ensure Dart can interoperate with polymer-element registered by |
| /// polymer.js, we need to be able to execute Dart code if we are registering |
| /// a Dart class for that element. We trigger Dart logic by patching |