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

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

Issue 225043004: Replace bootstrap logic with 'boot.js', use 'component/dart' mime-type and add (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 6 years, 8 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 /// Initializes a polymer application as follows: 23 /// This method is deprecated. It used to be where polymer initialization
24 /// * set up up polling for observable changes 24 /// happens, now this is done automatically from bootstrap.dart.
25 /// * initialize Model-Driven Views 25 @deprecated
26 /// * Include some style to prevent flash of unstyled content (FOUC) 26 Zone initPolymer() {
27 /// * for each library included transitively from HTML and HTML imports, 27 window.console.error(_ERROR);
28 /// register custom elements declared there (labeled with [CustomTag]) and
29 /// invoke the initialization method on it (top-level functions annotated with
30 /// [initMethod]).
31 Zone initPolymer() => loader.deployMode
32 // In deployment mode, we rely on change notifiers instead of dirty checking.
33 ? _initPolymerOptimized() : (dirtyCheckZone()..run(_initPolymerOptimized));
34
35 /// Same as [initPolymer], but runs the version that is optimized for deployment
36 /// to the internet. The biggest difference is it omits the [Zone] that
37 /// automatically invokes [Observable.dirtyCheck], and the list of initializers
38 /// must be supplied instead of being dynamically searched for at runtime using
39 /// mirrors.
40 Zone _initPolymerOptimized() {
41 _hookJsPolymer();
42
43 for (var initializer in loader.initializers) {
44 initializer();
45 }
46
47 return Zone.current; 28 return Zone.current;
48 } 29 }
49 30
50 /// Configures [initPolymer] making it optimized for deployment to the internet. 31 const _ERROR = '''
51 /// With this setup the initializer list is supplied instead of searched for 32 initPolymer is now deprecated. To initialize a polymer app:
52 /// at runtime. Additionally, after this method is called [initPolymer] omits 33 * add to your page: <link rel="import" href="packages/polymer/polymer.html">
53 /// the [Zone] that automatically invokes [Observable.dirtyCheck]. 34 * replace "application/dart" mime-types with "application/dart;component=1"
54 void configureForDeployment(List<Function> initializers) { 35 * if you use "init.dart", remove it
55 loader.initializers = initializers; 36 * if you have a main, change it into a method annotated with @initMethod
56 loader.deployMode = true; 37 ''';
38
39 /// True if we're in deployment mode.
40 bool _deployMode = false;
41
42 /// Starts polymer by running all [initializers] and hooking the polymer.js
43 /// 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
45 /// automatically generated. During development, this entry point is generated
46 /// dynamically in `boot.js`. Similarly, pub-build generates this entry point
47 /// for deployment.
48 void startPolymer(List<Function> initializers, [bool deployMode = true]) {
49 _hookJsPolymer();
50 _deployMode = deployMode;
51
52 for (var initializer in initializers) {
53 initializer();
54 }
57 } 55 }
58 56
59 /// To ensure Dart can interoperate with polymer-element registered by 57 /// To ensure Dart can interoperate with polymer-element registered by
60 /// polymer.js, we need to be able to execute Dart code if we are registering 58 /// polymer.js, we need to be able to execute Dart code if we are registering
61 /// a Dart class for that element. We trigger Dart logic by patching 59 /// a Dart class for that element. We trigger Dart logic by patching
62 /// polymer-element's register function and: 60 /// polymer-element's register function and:
63 /// 61 ///
64 /// * if it has a Dart class, run PolymerDeclaration's register. 62 /// * if it has a Dart class, run PolymerDeclaration's register.
65 /// * otherwise it is a JS prototype, run polymer-element's normal register. 63 /// * otherwise it is a JS prototype, run polymer-element's normal register.
66 void _hookJsPolymer() { 64 void _hookJsPolymer() {
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
100 final extendsDecl = _getDeclaration(extendee); 98 final extendsDecl = _getDeclaration(extendee);
101 return zone.run(() => 99 return zone.run(() =>
102 new PolymerDeclaration(jsElem, name, type, extendsDecl).register()); 100 new PolymerDeclaration(jsElem, name, type, extendsDecl).register());
103 } 101 }
104 // It's a JavaScript polymer element, fall back to the original register. 102 // It's a JavaScript polymer element, fall back to the original register.
105 return originalRegister.apply([name, extendee], thisArg: jsElem); 103 return originalRegister.apply([name, extendee], thisArg: jsElem);
106 } 104 }
107 105
108 proto['register'] = new JsFunction.withThis(registerDart); 106 proto['register'] = new JsFunction.withThis(registerDart);
109 } 107 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698