@@ -2,6 +2,7 @@ import 'package:di/di.dart';
2
2
import 'package:angular/angular.dart' ;
3
3
import 'package:angular/core_dom/module_internal.dart' ;
4
4
import 'package:angular/application_factory.dart' ;
5
+ import 'package:angular/change_detection/ast_parser.dart' ;
5
6
6
7
import 'dart:html' ;
7
8
import 'dart:math' ;
@@ -80,6 +81,7 @@ class NgFreeTree implements ShadowRootAware {
80
81
}
81
82
}
82
83
84
+ var treeValueAST, treeRightNotNullAST, treeLeftNotNullAST, treeRightAST, treeLeftAST, treeAST;
83
85
/**
84
86
* A baseline version of TreeComponent which uses Angular's Scope to
85
87
* manage data. This version is setting up data binding so arbitrary
@@ -116,28 +118,28 @@ class NgFreeTreeScoped implements ShadowRootAware {
116
118
var root = elt.createShadowRoot ();
117
119
var scope = parentScope.createChild ({});
118
120
119
- parentScope.watch (treeExpr, (v, _) {
121
+ parentScope.watchAST (treeExpr, (v, _) {
120
122
scope.context['tree' ] = v;
121
123
});
122
124
123
125
var s = new SpanElement ();
124
126
root.append (s);
125
- scope.watch ( 'tree.value' , (v, _) {
127
+ scope.watchAST (treeValueAST , (v, _) {
126
128
if (v != null ) {
127
129
s.text = " $v " ;
128
130
}
129
131
});
130
132
131
- scope.watch ( 'tree.right != null' , (v, _) {
133
+ scope.watchAST (treeRightNotNullAST , (v, _) {
132
134
if (v != true ) return ;
133
135
s.append (new SpanElement ()
134
- ..append (newFreeTree (scope, 'tree.right' )));
136
+ ..append (newFreeTree (scope, treeRightAST )));
135
137
});
136
138
137
- scope.watch ( 'tree.left != null' , (v, _) {
139
+ scope.watchAST (treeLeftNotNullAST , (v, _) {
138
140
if (v != true ) return ;
139
141
s.append (new SpanElement ()
140
- ..append (newFreeTree (scope, 'tree.left' )));
142
+ ..append (newFreeTree (scope, treeLeftAST )));
141
143
});
142
144
143
145
return elt;
@@ -152,7 +154,7 @@ class NgFreeTreeScoped implements ShadowRootAware {
152
154
treeScope = scope.createChild ({});
153
155
treeScope.context['tree' ] = tree;
154
156
root.innerHtml = '' ;
155
- root.append (newFreeTree (treeScope, 'tree' ));
157
+ root.append (newFreeTree (treeScope, treeAST ));
156
158
}
157
159
}
158
160
@@ -170,7 +172,7 @@ class FreeTreeClass {
170
172
Scope parentScope;
171
173
172
174
FreeTreeClass (this .parentScope, treeExpr) {
173
- parentScope.watch (treeExpr, (v, _) {
175
+ parentScope.watchAST (treeExpr, (v, _) {
174
176
tree = v;
175
177
});
176
178
}
@@ -182,22 +184,22 @@ class FreeTreeClass {
182
184
183
185
var s = new SpanElement ();
184
186
root.append (s);
185
- scope.watch ( 'tree.value' , (v, _) {
187
+ scope.watchAST (treeValueAST , (v, _) {
186
188
if (v != null ) {
187
189
s.text = " $v " ;
188
190
}
189
191
});
190
192
191
- scope.watch ( 'tree.right != null' , (v, _) {
193
+ scope.watchAST (treeRightNotNullAST , (v, _) {
192
194
if (v != true ) return ;
193
195
s.append (new SpanElement ()
194
- ..append (new FreeTreeClass (scope, 'tree.right' ).element ()));
196
+ ..append (new FreeTreeClass (scope, treeRightAST ).element ()));
195
197
});
196
198
197
- scope.watch ( 'tree.left != null' , (v, _) {
199
+ scope.watchAST (treeLeftNotNullAST , (v, _) {
198
200
if (v != true ) return ;
199
201
s.append (new SpanElement ()
200
- ..append (new FreeTreeClass (scope, 'tree.left' ).element ()));
202
+ ..append (new FreeTreeClass (scope, treeLeftAST ).element ()));
201
203
});
202
204
203
205
return elt;
@@ -237,7 +239,7 @@ class NgFreeTreeClass implements ShadowRootAware {
237
239
treeScope = scope.createChild ({});
238
240
treeScope.context['tree' ] = tree;
239
241
root.innerHtml = '' ;
240
- root.append (new FreeTreeClass (treeScope, 'tree' ).element ());
242
+ root.append (new FreeTreeClass (treeScope, treeAST ).element ());
241
243
}
242
244
}
243
245
@@ -252,10 +254,21 @@ main() {
252
254
..type (NgFreeTree )
253
255
..type (NgFreeTreeScoped )
254
256
..type (NgFreeTreeClass )
255
- ..factory (ScopeDigestTTL , (i) => new ScopeDigestTTL .value (15 ));
257
+ ..factory (ScopeDigestTTL , (i) => new ScopeDigestTTL .value (15 ))
258
+ ..bind (CompilerConfig , toValue: new CompilerConfig .withOptions (elementProbeEnabled: false ));
256
259
257
260
var injector = applicationFactory ().addModule (module).run ();
258
261
assert (injector != null );
262
+
263
+ // Set up ASTs
264
+ var parser = injector.get (ASTParser );
265
+ treeValueAST = parser ('tree.value' );
266
+ treeRightNotNullAST = parser ('tree.right != null' );
267
+ treeLeftNotNullAST = parser ('tree.left != null' );
268
+ treeRightAST = parser ('tree.right' );
269
+ treeLeftAST = parser ('tree.left' );
270
+ treeAST = parser ('tree' );
271
+
259
272
VmTurnZone zone = injector.get (VmTurnZone );
260
273
Scope scope = injector.get (Scope );
261
274
0 commit comments