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

Unified Diff: third_party/pkg/angular/lib/change_detection/ast.dart

Issue 180873006: Update the Angular/DI tests to latest from github. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Review feedback Created 6 years, 10 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 side-by-side diff with in-line comments
Download patch
Index: third_party/pkg/angular/lib/change_detection/ast.dart
diff --git a/third_party/pkg/angular/lib/change_detection/ast.dart b/third_party/pkg/angular/lib/change_detection/ast.dart
new file mode 100644
index 0000000000000000000000000000000000000000..66c55fba3c05bfdd627096c16cd5912a7506a37b
--- /dev/null
+++ b/third_party/pkg/angular/lib/change_detection/ast.dart
@@ -0,0 +1,146 @@
+part of angular.watch_group;
+
+
+/**
+ * RULES:
+ * - ASTs are reusable. Don't store scope/instance refs there
+ * - Parent knows about children, not the other way around.
+ */
+abstract class AST {
+ static final String _CONTEXT = '#';
+ final String expression;
+ AST(expression)
+ : expression = expression.startsWith('#.')
+ ? expression.substring(2)
+ : expression
+ {
+ assert(expression!=null);
+ }
+ WatchRecord<_Handler> setupWatch(WatchGroup watchGroup);
+ String toString() => expression;
+}
+
+/**
+ * SYNTAX: _context_
+ *
+ * This represent the initial _context_ for evaluation.
+ */
+class ContextReferenceAST extends AST {
+ ContextReferenceAST(): super(AST._CONTEXT);
+ WatchRecord<_Handler> setupWatch(WatchGroup watchGroup) =>
+ new _ConstantWatchRecord(watchGroup, expression, watchGroup.context);
+}
+
+/**
+ * SYNTAX: _context_
+ *
+ * This represent the initial _context_ for evaluation.
+ */
+class ConstantAST extends AST {
+ final constant;
+
+ ConstantAST(constant, [String expression])
+ : constant = constant,
+ super(expression == null
+ ? constant is String ? '"$constant"' : '$constant'
+ : expression);
+
+ WatchRecord<_Handler> setupWatch(WatchGroup watchGroup) =>
+ new _ConstantWatchRecord(watchGroup, expression, constant);
+}
+
+/**
+ * SYNTAX: lhs.name.
+ *
+ * This is the '.' dot operator.
+ */
+class FieldReadAST extends AST {
+ AST lhs;
+ final String name;
+
+ FieldReadAST(lhs, name)
+ : lhs = lhs,
+ name = name,
+ super('$lhs.$name');
+
+ WatchRecord<_Handler> setupWatch(WatchGroup watchGroup) =>
+ watchGroup.addFieldWatch(lhs, name, expression);
+}
+
+/**
+ * SYNTAX: fn(arg0, arg1, ...)
+ *
+ * Invoke a pure function. Pure means that the function has no state, and
+ * therefore it needs to be re-computed only if its args change.
+ */
+class PureFunctionAST extends AST {
+ final String name;
+ final /* dartbug.com/16401 Function */ fn;
+ final List<AST> argsAST;
+
+ PureFunctionAST(name, this.fn, argsAST)
+ : super('$name(${_argList(argsAST)})'),
+ argsAST = argsAST,
+ name = name;
+
+ WatchRecord<_Handler> setupWatch(WatchGroup watchGroup) =>
+ watchGroup.addFunctionWatch(fn, argsAST, expression);
+}
+
+/**
+ * SYNTAX: lhs.method(arg0, arg1, ...)
+ *
+ * Invoke a method on [lhs] object.
+ */
+class MethodAST extends AST {
+ final AST lhsAST;
+ final String name;
+ final List<AST> argsAST;
+
+ MethodAST(lhsAST, name, argsAST)
+ : super('$lhsAST.$name(${_argList(argsAST)})'),
+ lhsAST = lhsAST,
+ name = name,
+ argsAST = argsAST;
+
+ WatchRecord<_Handler> setupWatch(WatchGroup watchGroup) =>
+ watchGroup.addMethodWatch(lhsAST, name, argsAST, expression);
+}
+
+
+class CollectionAST extends AST {
+ final AST valueAST;
+ CollectionAST(valueAST)
+ : valueAST = valueAST,
+ super('#collection($valueAST)');
+
+ WatchRecord<_Handler> setupWatch(WatchGroup watchGroup) =>
+ watchGroup.addCollectionWatch(valueAST);
+}
+
+String _argList(List<AST> items) => items.join(', ');
+
+/**
+ * The name is a bit oxymoron, but it is essentially the NullObject pattern.
+ *
+ * This allows children to set a handler on this ChangeRecord and then let it write the initial
+ * constant value to the forwarding ChangeRecord.
+ */
+class _ConstantWatchRecord extends WatchRecord<_Handler> {
+ final currentValue;
+ final _Handler handler;
+
+ _ConstantWatchRecord(WatchGroup watchGroup, String expression, currentValue)
+ : currentValue = currentValue,
+ handler = new _ConstantHandler(watchGroup, expression, currentValue);
+
+ ChangeRecord<_Handler> check() => null;
+ void remove() => null;
+
+ get field => null;
+ get previousValue => null;
+ get object => null;
+ set object(_) => null;
+ get nextChange => null;
+}
+
« no previous file with comments | « third_party/pkg/angular/lib/bootstrap.dart ('k') | third_party/pkg/angular/lib/change_detection/change_detection.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698