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

Side by Side Diff: pkg/template_binding/lib/src/node.dart

Issue 432533002: Run template binding callbacks in the correct zone (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 6 years, 4 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
« no previous file with comments | « pkg/template_binding/CHANGELOG.md ('k') | pkg/template_binding/pubspec.yaml » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 template_binding; 5 part of template_binding;
6 6
7 /** Extensions to the [Node] API. */ 7 /** Extensions to the [Node] API. */
8 class NodeBindExtension { 8 class NodeBindExtension {
9 final Node _node; 9 final Node _node;
10 final JsObject _js; 10 final JsObject _js;
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after
130 // For performance, unwrap the Dart bindable if we find one. 130 // For performance, unwrap the Dart bindable if we find one.
131 // Note: in the unlikely event some code messes with our __dartBindable 131 // Note: in the unlikely event some code messes with our __dartBindable
132 // property we can simply fallback to a _JsBindable wrapper. 132 // property we can simply fallback to a _JsBindable wrapper.
133 return b is Bindable ? b : new _JsBindable(obj); 133 return b is Bindable ? b : new _JsBindable(obj);
134 } 134 }
135 135
136 class _JsBindable extends Bindable { 136 class _JsBindable extends Bindable {
137 final JsObject _js; 137 final JsObject _js;
138 _JsBindable(JsObject obj) : _js = obj; 138 _JsBindable(JsObject obj) : _js = obj;
139 139
140 open(callback) => _js.callMethod('open', [callback]); 140 open(callback) => _js.callMethod('open',
141 [Zone.current.bindUnaryCallback(callback)]);
141 142
142 close() => _js.callMethod('close'); 143 close() => _js.callMethod('close');
143 144
144 get value => _js.callMethod('discardChanges'); 145 get value => _js.callMethod('discardChanges');
145 146
146 set value(newValue) { 147 set value(newValue) {
147 _js.callMethod('setValue', [newValue]); 148 _js.callMethod('setValue', [newValue]);
148 } 149 }
149 150
150 deliver() => _js.callMethod('deliver'); 151 deliver() => _js.callMethod('deliver');
151 } 152 }
152 153
153 /// Given a [bindable], create a JS object proxy for it. 154 /// Given a [bindable], create a JS object proxy for it.
154 /// This is the inverse of [jsObjectToBindable]. 155 /// This is the inverse of [jsObjectToBindable].
155 JsObject bindableToJsObject(Bindable bindable) { 156 JsObject bindableToJsObject(Bindable bindable) {
156 if (bindable is _JsBindable) return bindable._js; 157 if (bindable is _JsBindable) return bindable._js;
157 158
159 var zone = Zone.current;
160 inZone(f) => zone.bindCallback(f);
161 inZone1(f) => zone.bindUnaryCallback(f);
jakemac 2014/07/30 21:05:06 might want to rename inZoneUnary, usually you don'
Siggi Cherem (dart-lang) 2014/07/30 21:21:47 Done.
162
158 return new JsObject.jsify({ 163 return new JsObject.jsify({
159 'open': (callback) => bindable.open((x) => callback.apply([x])), 164 'open': inZone1((callback) => bindable.open((x) => callback.apply([x]))),
160 'close': () => bindable.close(), 165 'close': inZone(() => bindable.close()),
161 'discardChanges': () => bindable.value, 166 'discardChanges': inZone(() => bindable.value),
162 'setValue': (x) => bindable.value = x, 167 'setValue': inZone1((x) => bindable.value = x),
163 // NOTE: this is not used by Node.bind, but it's used by Polymer: 168 // NOTE: this is not used by Node.bind, but it's used by Polymer:
164 // https://github.com/Polymer/polymer-dev/blob/ba2b68fe5a5721f60b5994135f327 0e63588809a/src/declaration/properties.js#L130 169 // https://github.com/Polymer/polymer-dev/blob/ba2b68fe5a5721f60b5994135f327 0e63588809a/src/declaration/properties.js#L130
165 // Technically this works because 'deliver' is on PathObserver and 170 // Technically this works because 'deliver' is on PathObserver and
166 // CompoundObserver. But ideally Polymer-JS would not assume that. 171 // CompoundObserver. But ideally Polymer-JS would not assume that.
167 'deliver': () => bindable.deliver(), 172 'deliver': inZone(() => bindable.deliver()),
168 // Save this so we can return it from [jsObjectToBindable] 173 // Save this so we can return it from [jsObjectToBindable]
169 '__dartBindable': bindable 174 '__dartBindable': bindable
170 }); 175 });
171 } 176 }
172 177
173 /** Information about the instantiated template. */ 178 /** Information about the instantiated template. */
174 class TemplateInstance { 179 class TemplateInstance {
175 // TODO(rafaelw): firstNode & lastNode should be read-synchronous 180 // TODO(rafaelw): firstNode & lastNode should be read-synchronous
176 // in cases where script has modified the template instance boundary. 181 // in cases where script has modified the template instance boundary.
177 182
178 /** The first node of this template instantiation. */ 183 /** The first node of this template instantiation. */
179 Node get firstNode => _firstNode; 184 Node get firstNode => _firstNode;
180 185
181 /** 186 /**
182 * The last node of this template instantiation. 187 * The last node of this template instantiation.
183 * This could be identical to [firstNode] if the template only expanded to a 188 * This could be identical to [firstNode] if the template only expanded to a
184 * single node. 189 * single node.
185 */ 190 */
186 Node get lastNode => _lastNode; 191 Node get lastNode => _lastNode;
187 192
188 /** The model used to instantiate the template. */ 193 /** The model used to instantiate the template. */
189 final model; 194 final model;
190 195
191 Node _firstNode, _lastNode; 196 Node _firstNode, _lastNode;
192 197
193 TemplateInstance(this.model); 198 TemplateInstance(this.model);
194 } 199 }
OLDNEW
« no previous file with comments | « pkg/template_binding/CHANGELOG.md ('k') | pkg/template_binding/pubspec.yaml » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698