| 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 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 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 if (initializers == null) { | 58 if (initializers == null) { |
| 59 throw 'Missing initialization of polymer elements. ' | 59 throw 'Missing initialization of polymer elements. ' |
| 60 'Please check that the list of entry points in your pubspec.yaml ' | 60 'Please check that the list of entry points in your pubspec.yaml ' |
| 61 'is correct. If you are using pub-serve, you may need to restart it.'; | 61 'is correct. If you are using pub-serve, you may need to restart it.'; |
| 62 } | 62 } |
| 63 |
| 64 Polymer.registerSync('d-auto-binding', AutoBindingElement, |
| 65 extendsTag: 'template'); |
| 66 |
| 63 for (var initializer in initializers) { | 67 for (var initializer in initializers) { |
| 64 initializer(); | 68 initializer(); |
| 65 } | 69 } |
| 66 } | 70 } |
| 67 | 71 |
| 68 /// Configures [initPolymer] making it optimized for deployment to the internet. | 72 /// Configures [initPolymer] making it optimized for deployment to the internet. |
| 69 /// With this setup the initializer list is supplied instead of searched for | 73 /// With this setup the initializer list is supplied instead of searched for |
| 70 /// at runtime. Additionally, after this method is called [initPolymer] omits | 74 /// at runtime. Additionally, after this method is called [initPolymer] omits |
| 71 /// the [Zone] that automatically invokes [Observable.dirtyCheck]. | 75 /// the [Zone] that automatically invokes [Observable.dirtyCheck]. |
| 72 void configureForDeployment(List<Function> initializers) { | 76 void configureForDeployment(List<Function> initializers) { |
| (...skipping 17 matching lines...) Expand all Loading... |
| 90 ' version of polymer.js by following the instructions at' | 94 ' version of polymer.js by following the instructions at' |
| 91 ' http://www.polymer-project.org; if you do that be sure to include' | 95 ' http://www.polymer-project.org; if you do that be sure to include' |
| 92 ' the platform polyfills.'); | 96 ' the platform polyfills.'); |
| 93 } | 97 } |
| 94 | 98 |
| 95 // 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: |
| 96 // https://code.google.com/p/dart/issues/detail?id=17301 | 100 // https://code.google.com/p/dart/issues/detail?id=17301 |
| 97 var zone = Zone.current; | 101 var zone = Zone.current; |
| 98 | 102 |
| 99 polymerJs.callMethod('whenPolymerReady', | 103 polymerJs.callMethod('whenPolymerReady', |
| 100 [zone.bindCallback(() => Polymer._ready.complete())]); | 104 [zone.bindCallback(() => Polymer._onReady.complete())]); |
| 101 | 105 |
| 102 var polyElem = document.createElement('polymer-element'); | 106 var polyElem = document.createElement('polymer-element'); |
| 103 var proto = new JsObject.fromBrowserObject(polyElem)['__proto__']; | 107 var proto = new JsObject.fromBrowserObject(polyElem)['__proto__']; |
| 104 if (proto is Node) proto = new JsObject.fromBrowserObject(proto); | 108 if (proto is Node) proto = new JsObject.fromBrowserObject(proto); |
| 105 | 109 |
| 106 JsFunction originalRegister = proto['register']; | 110 JsFunction originalRegister = proto['register']; |
| 107 if (originalRegister == null) { | 111 if (originalRegister == null) { |
| 108 throw new StateError('polymer.js must expose "register" function on ' | 112 throw new StateError('polymer.js must expose "register" function on ' |
| 109 'polymer-element to enable polymer.dart to interoperate.'); | 113 'polymer-element to enable polymer.dart to interoperate.'); |
| 110 } | 114 } |
| 111 | 115 |
| 112 registerDart(jsElem, String name, String extendee) { | 116 registerDart(jsElem, String name, String extendee) { |
| 113 // By the time we get here, we'll know for sure if it is a Dart object | 117 // By the time we get here, we'll know for sure if it is a Dart object |
| 114 // or not, because polymer-element will wait for us to notify that | 118 // or not, because polymer-element will wait for us to notify that |
| 115 // the @CustomTag was found. | 119 // the @CustomTag was found. |
| 116 final type = _getRegisteredType(name); | 120 final type = _getRegisteredType(name); |
| 117 if (type != null) { | 121 if (type != null) { |
| 118 final extendsDecl = _getDeclaration(extendee); | 122 final extendsDecl = _getDeclaration(extendee); |
| 119 return zone.run(() => | 123 return zone.run(() => |
| 120 new PolymerDeclaration(jsElem, name, type, extendsDecl).register()); | 124 new PolymerDeclaration(jsElem, name, type, extendsDecl).register()); |
| 121 } | 125 } |
| 122 // It's a JavaScript polymer element, fall back to the original register. | 126 // It's a JavaScript polymer element, fall back to the original register. |
| 123 return originalRegister.apply([name, extendee], thisArg: jsElem); | 127 return originalRegister.apply([name, extendee], thisArg: jsElem); |
| 124 } | 128 } |
| 125 | 129 |
| 126 proto['register'] = new JsFunction.withThis(registerDart); | 130 proto['register'] = new JsFunction.withThis(registerDart); |
| 127 } | 131 } |
| OLD | NEW |