Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(234)

Side by Side Diff: pkg/polymer/lib/src/loader.dart

Issue 293023008: Bring back initPolymer, allow boot.js only if using "polymer_experimental.html". (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 6 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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);
11 } 11 }
12 12
13 /// Metadata used to label static or top-level methods that are called 13 /// Metadata used to label static or top-level methods that are called
14 /// automatically when loading the library of a custom element. 14 /// automatically when loading the library of a custom element.
15 const initMethod = const InitMethodAnnotation(); 15 const initMethod = const InitMethodAnnotation();
16 16
17 /// Implementation behind [initMethod]. Only exposed for internal implementation 17 /// Implementation behind [initMethod]. Only exposed for internal implementation
18 /// details 18 /// details
19 class InitMethodAnnotation { 19 class InitMethodAnnotation {
20 const InitMethodAnnotation(); 20 const InitMethodAnnotation();
21 } 21 }
22 22
23 /// This method is deprecated. It used to be where polymer initialization 23 /// Initializes a polymer application as follows:
24 /// happens, now this is done automatically from bootstrap.dart. 24 /// * if running in development mode, set up a dirty-checking zone that polls
25 @deprecated 25 /// for observable changes
26 /// * initialize template binding and polymer-element
27 /// * 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
28 /// * for each library included transitively from HTML and HTML imports,
29 /// register custom elements declared there (labeled with [CustomTag]) and
30 /// invoke the initialization method on it (top-level functions annotated with
31 /// [initMethod]).
26 Zone initPolymer() { 32 Zone initPolymer() {
27 window.console.error(_ERROR); 33 if (loader.deployMode) {
28 return Zone.current; 34 startPolymer(loader.initializers, loader.deployMode);
35 return Zone.current;
36 }
37 return dirtyCheckZone()..run(
38 () => startPolymer(loader.initializers, loader.deployMode));
29 } 39 }
30 40
31 const _ERROR = '''
32 initPolymer is now deprecated. To initialize a polymer app:
33 * add to your page: <link rel="import" href="packages/polymer/polymer.html">
34 * replace "application/dart" mime-types with "application/dart;component=1"
35 * if you use "init.dart", remove it
36 * if you have a main, change it into a method annotated with @initMethod
37 ''';
38
39 /// True if we're in deployment mode. 41 /// True if we're in deployment mode.
40 bool _deployMode = false; 42 bool _deployMode = false;
41 43
44 bool _startPolymerCalled = false;
45
42 /// Starts polymer by running all [initializers] and hooking the polymer.js 46 /// Starts polymer by running all [initializers] and hooking the polymer.js
43 /// code. **Note**: this function is not meant to be invoked directly by 47 /// code. **Note**: this function is not meant to be invoked directly by
44 /// application developers. It is invoked by a bootstrap entry point that is 48 /// application developers. It is invoked either by [initPolymer] or, if you are
45 /// automatically generated. During development, this entry point is generated 49 /// using the experimental bootstrap API, this would be invoked by an entry
46 /// dynamically in `boot.js`. Similarly, pub-build generates this entry point 50 /// point that is automatically generated somehow. In particular, during
47 /// for deployment. 51 /// development, the entry point would be generated dynamically in `boot.js`.
52 /// Similarly, pub-build would generate the entry point for deployment.
48 void startPolymer(List<Function> initializers, [bool deployMode = true]) { 53 void startPolymer(List<Function> initializers, [bool deployMode = true]) {
54 if (_startPolymerCalled) throw 'Initialization was already done.';
55 _startPolymerCalled = true;
49 _hookJsPolymer(); 56 _hookJsPolymer();
50 _deployMode = deployMode; 57 _deployMode = deployMode;
51 58
52 for (var initializer in initializers) { 59 for (var initializer in initializers) {
53 initializer(); 60 initializer();
54 } 61 }
55 } 62 }
56 63
64 /// Configures [initPolymer] making it optimized for deployment to the internet.
65 /// With this setup the initializer list is supplied instead of searched for
66 /// at runtime. Additionally, after this method is called [initPolymer] omits
67 /// the [Zone] that automatically invokes [Observable.dirtyCheck].
68 void configureForDeployment(List<Function> initializers) {
69 loader.initializers = initializers;
70 loader.deployMode = true;
71 }
72
57 /// To ensure Dart can interoperate with polymer-element registered by 73 /// To ensure Dart can interoperate with polymer-element registered by
58 /// polymer.js, we need to be able to execute Dart code if we are registering 74 /// polymer.js, we need to be able to execute Dart code if we are registering
59 /// a Dart class for that element. We trigger Dart logic by patching 75 /// a Dart class for that element. We trigger Dart logic by patching
60 /// polymer-element's register function and: 76 /// polymer-element's register function and:
61 /// 77 ///
62 /// * if it has a Dart class, run PolymerDeclaration's register. 78 /// * if it has a Dart class, run PolymerDeclaration's register.
63 /// * otherwise it is a JS prototype, run polymer-element's normal register. 79 /// * otherwise it is a JS prototype, run polymer-element's normal register.
64 void _hookJsPolymer() { 80 void _hookJsPolymer() {
65 var polymerJs = js.context['Polymer']; 81 var polymerJs = js.context['Polymer'];
66 if (polymerJs == null) { 82 if (polymerJs == null) {
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
98 final extendsDecl = _getDeclaration(extendee); 114 final extendsDecl = _getDeclaration(extendee);
99 return zone.run(() => 115 return zone.run(() =>
100 new PolymerDeclaration(jsElem, name, type, extendsDecl).register()); 116 new PolymerDeclaration(jsElem, name, type, extendsDecl).register());
101 } 117 }
102 // It's a JavaScript polymer element, fall back to the original register. 118 // It's a JavaScript polymer element, fall back to the original register.
103 return originalRegister.apply([name, extendee], thisArg: jsElem); 119 return originalRegister.apply([name, extendee], thisArg: jsElem);
104 } 120 }
105 121
106 proto['register'] = new JsFunction.withThis(registerDart); 122 proto['register'] = new JsFunction.withThis(registerDart);
107 } 123 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698