Skip to content

Commit 77fdc61

Browse files
committed
fix(bind-*): zone.run scope.apply on bind- change events
Due to dart bug, events registered with addEventListener do no fire scope.apply(). Adds an example of an affected polymer component.
1 parent a760ec1 commit 77fdc61

File tree

5 files changed

+51
-5
lines changed

5 files changed

+51
-5
lines changed

example/web/index.html

+1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
<li><a href="paper.html">paper.html</a></li>
1010
<li><a href="form.html">form.html</a></li>
1111
<li><a href="maps.html">maps.html</a></li>
12+
<li><a href="paper_radio_group.html">paper_radio_group.html</a></li>
1213
</ul>
1314
</body>
1415
</html>

example/web/paper_radio_group.dart

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import 'package:angular/angular.dart';
2+
import 'package:angular/application_factory.dart';
3+
4+
import 'dart:html';
5+
6+
@Component(
7+
selector: 'cmp',
8+
template: '<paper-radio-group bind-selected="cmp.insertOption"> <paper-radio-button name="asis" label="Insert as is"></paper-radio-button> <paper-radio-button name="duplicate" label="Insert as duplicate"></paper-radio-button> </paper-radio-group> {{cmp.insertOption}}',
9+
publishAs: 'cmp'
10+
)
11+
class Cmp {
12+
Object insertOption;
13+
}
14+
15+
main() {
16+
applicationFactory()
17+
.addModule(new Module()..bind(Cmp))
18+
.run();
19+
}

example/web/paper_radio_group.html

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<!DOCTYPE html>
2+
<html>
3+
<head>
4+
<title>Paper radio group example</title>
5+
<!-- 0. bower install; pub serve -->
6+
<!-- 1. Load platform.js for polyfill support. -->
7+
<script src="bower_components/platform/platform.js"></script>
8+
9+
<!-- 2. Use an HTML Import to bring in the element. -->
10+
<link rel="import"
11+
href="bower_components/paper-radio-group/paper-radio-group.html">
12+
</head>
13+
<body>
14+
<cmp></cmp>
15+
<!-- needed for the getter extractor -->
16+
{{cmp}} {{insertOption}}
17+
<script type="application/dart" src="paper_radio_group.dart"></script>
18+
<script src="packages/browser/dart.js"></script>
19+
</body>
20+
</html>

lib/core_dom/element_binder.dart

+10-5
Original file line numberDiff line numberDiff line change
@@ -305,11 +305,16 @@ class ElementBinder {
305305
});
306306

307307
if (bindAssignableProps.isNotEmpty) {
308-
node.addEventListener('change', (_) {
309-
bindAssignableProps.forEach((propAndExp) {
310-
propAndExp[1].assign(scope.context, jsNode[propAndExp[0]]);
311-
});
312-
});
308+
// due to https://code.google.com/p/dart/issues/detail?id=17406
309+
// we have to manually run the zone.
310+
var zone = Zone.current;
311+
node.addEventListener('change', (_) =>
312+
zone.run(() =>
313+
bindAssignableProps.forEach((propAndExp) =>
314+
propAndExp[1].assign(scope.context, jsNode[propAndExp[0]])
315+
)
316+
)
317+
);
313318
}
314319

315320
if (onEvents.isNotEmpty) {

lib/core_dom/module_internal.dart

+1
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ import 'package:angular/directive/module.dart' show NgBaseCss;
3535
import 'package:angular/core_dom/css_shim.dart' as cssShim;
3636

3737
import 'dart:collection';
38+
import 'dart:async';
3839

3940
part 'animation.dart';
4041
part 'cookies.dart';

0 commit comments

Comments
 (0)