| 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 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 48 /// using the experimental bootstrap API, this would be invoked by an entry | 48 /// using the experimental bootstrap API, this would be invoked by an entry |
| 49 /// point that is automatically generated somehow. In particular, during | 49 /// point that is automatically generated somehow. In particular, during |
| 50 /// development, the entry point would be generated dynamically in `boot.js`. | 50 /// development, the entry point would be generated dynamically in `boot.js`. |
| 51 /// Similarly, pub-build would generate the entry point for deployment. | 51 /// Similarly, pub-build would generate the entry point for deployment. |
| 52 void startPolymer(List<Function> initializers, [bool deployMode = true]) { | 52 void startPolymer(List<Function> initializers, [bool deployMode = true]) { |
| 53 if (_startPolymerCalled) throw 'Initialization was already done.'; | 53 if (_startPolymerCalled) throw 'Initialization was already done.'; |
| 54 _startPolymerCalled = true; | 54 _startPolymerCalled = true; |
| 55 _hookJsPolymer(); | 55 _hookJsPolymer(); |
| 56 _deployMode = deployMode; | 56 _deployMode = deployMode; |
| 57 | 57 |
| 58 Polymer.registerSync('d-auto-binding', AutoBindingElement, |
| 59 extendsTag: 'template'); |
| 60 |
| 58 for (var initializer in initializers) { | 61 for (var initializer in initializers) { |
| 59 initializer(); | 62 initializer(); |
| 60 } | 63 } |
| 61 } | 64 } |
| 62 | 65 |
| 63 /// Configures [initPolymer] making it optimized for deployment to the internet. | 66 /// Configures [initPolymer] making it optimized for deployment to the internet. |
| 64 /// With this setup the initializer list is supplied instead of searched for | 67 /// With this setup the initializer list is supplied instead of searched for |
| 65 /// at runtime. Additionally, after this method is called [initPolymer] omits | 68 /// at runtime. Additionally, after this method is called [initPolymer] omits |
| 66 /// the [Zone] that automatically invokes [Observable.dirtyCheck]. | 69 /// the [Zone] that automatically invokes [Observable.dirtyCheck]. |
| 67 void configureForDeployment(List<Function> initializers) { | 70 void configureForDeployment(List<Function> initializers) { |
| (...skipping 17 matching lines...) Expand all Loading... |
| 85 ' version of polymer.js by following the instructions at' | 88 ' version of polymer.js by following the instructions at' |
| 86 ' http://www.polymer-project.org; if you do that be sure to include' | 89 ' http://www.polymer-project.org; if you do that be sure to include' |
| 87 ' the platform polyfills.'); | 90 ' the platform polyfills.'); |
| 88 } | 91 } |
| 89 | 92 |
| 90 // TODO(jmesserly): dart:js appears to not callback in the correct zone: | 93 // TODO(jmesserly): dart:js appears to not callback in the correct zone: |
| 91 // https://code.google.com/p/dart/issues/detail?id=17301 | 94 // https://code.google.com/p/dart/issues/detail?id=17301 |
| 92 var zone = Zone.current; | 95 var zone = Zone.current; |
| 93 | 96 |
| 94 polymerJs.callMethod('whenPolymerReady', | 97 polymerJs.callMethod('whenPolymerReady', |
| 95 [zone.bindCallback(() => Polymer._ready.complete())]); | 98 [zone.bindCallback(() => Polymer._onReady.complete())]); |
| 96 | 99 |
| 97 var polyElem = document.createElement('polymer-element'); | 100 var polyElem = document.createElement('polymer-element'); |
| 98 var proto = new JsObject.fromBrowserObject(polyElem)['__proto__']; | 101 var proto = new JsObject.fromBrowserObject(polyElem)['__proto__']; |
| 99 if (proto is Node) proto = new JsObject.fromBrowserObject(proto); | 102 if (proto is Node) proto = new JsObject.fromBrowserObject(proto); |
| 100 | 103 |
| 101 JsFunction originalRegister = proto['register']; | 104 JsFunction originalRegister = proto['register']; |
| 102 if (originalRegister == null) { | 105 if (originalRegister == null) { |
| 103 throw new StateError('polymer.js must expose "register" function on ' | 106 throw new StateError('polymer.js must expose "register" function on ' |
| 104 'polymer-element to enable polymer.dart to interoperate.'); | 107 'polymer-element to enable polymer.dart to interoperate.'); |
| 105 } | 108 } |
| 106 | 109 |
| 107 registerDart(jsElem, String name, String extendee) { | 110 registerDart(jsElem, String name, String extendee) { |
| 108 // By the time we get here, we'll know for sure if it is a Dart object | 111 // By the time we get here, we'll know for sure if it is a Dart object |
| 109 // or not, because polymer-element will wait for us to notify that | 112 // or not, because polymer-element will wait for us to notify that |
| 110 // the @CustomTag was found. | 113 // the @CustomTag was found. |
| 111 final type = _getRegisteredType(name); | 114 final type = _getRegisteredType(name); |
| 112 if (type != null) { | 115 if (type != null) { |
| 113 final extendsDecl = _getDeclaration(extendee); | 116 final extendsDecl = _getDeclaration(extendee); |
| 114 return zone.run(() => | 117 return zone.run(() => |
| 115 new PolymerDeclaration(jsElem, name, type, extendsDecl).register()); | 118 new PolymerDeclaration(jsElem, name, type, extendsDecl).register()); |
| 116 } | 119 } |
| 117 // It's a JavaScript polymer element, fall back to the original register. | 120 // It's a JavaScript polymer element, fall back to the original register. |
| 118 return originalRegister.apply([name, extendee], thisArg: jsElem); | 121 return originalRegister.apply([name, extendee], thisArg: jsElem); |
| 119 } | 122 } |
| 120 | 123 |
| 121 proto['register'] = new JsFunction.withThis(registerDart); | 124 proto['register'] = new JsFunction.withThis(registerDart); |
| 122 } | 125 } |
| OLD | NEW |