| OLD | NEW |
| (Empty) |
| 1 part of angular.watch_group; | |
| 2 | |
| 3 | |
| 4 /** | |
| 5 * RULES: | |
| 6 * - ASTs are reusable. Don't store scope/instance refs there | |
| 7 * - Parent knows about children, not the other way around. | |
| 8 */ | |
| 9 abstract class AST { | |
| 10 static final String _CONTEXT = '#'; | |
| 11 final String expression; | |
| 12 AST(expression) | |
| 13 : expression = expression.startsWith('#.') | |
| 14 ? expression.substring(2) | |
| 15 : expression | |
| 16 { | |
| 17 assert(expression!=null); | |
| 18 } | |
| 19 WatchRecord<_Handler> setupWatch(WatchGroup watchGroup); | |
| 20 String toString() => expression; | |
| 21 } | |
| 22 | |
| 23 /** | |
| 24 * SYNTAX: _context_ | |
| 25 * | |
| 26 * This represent the initial _context_ for evaluation. | |
| 27 */ | |
| 28 class ContextReferenceAST extends AST { | |
| 29 ContextReferenceAST(): super(AST._CONTEXT); | |
| 30 WatchRecord<_Handler> setupWatch(WatchGroup watchGroup) => | |
| 31 new _ConstantWatchRecord(watchGroup, expression, watchGroup.context); | |
| 32 } | |
| 33 | |
| 34 /** | |
| 35 * SYNTAX: _context_ | |
| 36 * | |
| 37 * This represent the initial _context_ for evaluation. | |
| 38 */ | |
| 39 class ConstantAST extends AST { | |
| 40 final constant; | |
| 41 | |
| 42 ConstantAST(constant, [String expression]) | |
| 43 : constant = constant, | |
| 44 super(expression == null | |
| 45 ? constant is String ? '"$constant"' : '$constant' | |
| 46 : expression); | |
| 47 | |
| 48 WatchRecord<_Handler> setupWatch(WatchGroup watchGroup) => | |
| 49 new _ConstantWatchRecord(watchGroup, expression, constant); | |
| 50 } | |
| 51 | |
| 52 /** | |
| 53 * SYNTAX: lhs.name. | |
| 54 * | |
| 55 * This is the '.' dot operator. | |
| 56 */ | |
| 57 class FieldReadAST extends AST { | |
| 58 AST lhs; | |
| 59 final String name; | |
| 60 | |
| 61 FieldReadAST(lhs, name) | |
| 62 : lhs = lhs, | |
| 63 name = name, | |
| 64 super('$lhs.$name'); | |
| 65 | |
| 66 WatchRecord<_Handler> setupWatch(WatchGroup watchGroup) => | |
| 67 watchGroup.addFieldWatch(lhs, name, expression); | |
| 68 } | |
| 69 | |
| 70 /** | |
| 71 * SYNTAX: fn(arg0, arg1, ...) | |
| 72 * | |
| 73 * Invoke a pure function. Pure means that the function has no state, and | |
| 74 * therefore it needs to be re-computed only if its args change. | |
| 75 */ | |
| 76 class PureFunctionAST extends AST { | |
| 77 final String name; | |
| 78 final /* dartbug.com/16401 Function */ fn; | |
| 79 final List<AST> argsAST; | |
| 80 | |
| 81 PureFunctionAST(name, this.fn, argsAST) | |
| 82 : super('$name(${_argList(argsAST)})'), | |
| 83 argsAST = argsAST, | |
| 84 name = name; | |
| 85 | |
| 86 WatchRecord<_Handler> setupWatch(WatchGroup watchGroup) => | |
| 87 watchGroup.addFunctionWatch(fn, argsAST, expression); | |
| 88 } | |
| 89 | |
| 90 /** | |
| 91 * SYNTAX: lhs.method(arg0, arg1, ...) | |
| 92 * | |
| 93 * Invoke a method on [lhs] object. | |
| 94 */ | |
| 95 class MethodAST extends AST { | |
| 96 final AST lhsAST; | |
| 97 final String name; | |
| 98 final List<AST> argsAST; | |
| 99 | |
| 100 MethodAST(lhsAST, name, argsAST) | |
| 101 : super('$lhsAST.$name(${_argList(argsAST)})'), | |
| 102 lhsAST = lhsAST, | |
| 103 name = name, | |
| 104 argsAST = argsAST; | |
| 105 | |
| 106 WatchRecord<_Handler> setupWatch(WatchGroup watchGroup) => | |
| 107 watchGroup.addMethodWatch(lhsAST, name, argsAST, expression); | |
| 108 } | |
| 109 | |
| 110 | |
| 111 class CollectionAST extends AST { | |
| 112 final AST valueAST; | |
| 113 CollectionAST(valueAST) | |
| 114 : valueAST = valueAST, | |
| 115 super('#collection($valueAST)'); | |
| 116 | |
| 117 WatchRecord<_Handler> setupWatch(WatchGroup watchGroup) => | |
| 118 watchGroup.addCollectionWatch(valueAST); | |
| 119 } | |
| 120 | |
| 121 String _argList(List<AST> items) => items.join(', '); | |
| 122 | |
| 123 /** | |
| 124 * The name is a bit oxymoron, but it is essentially the NullObject pattern. | |
| 125 * | |
| 126 * This allows children to set a handler on this ChangeRecord and then let it wr
ite the initial | |
| 127 * constant value to the forwarding ChangeRecord. | |
| 128 */ | |
| 129 class _ConstantWatchRecord extends WatchRecord<_Handler> { | |
| 130 final currentValue; | |
| 131 final _Handler handler; | |
| 132 | |
| 133 _ConstantWatchRecord(WatchGroup watchGroup, String expression, currentValue) | |
| 134 : currentValue = currentValue, | |
| 135 handler = new _ConstantHandler(watchGroup, expression, currentValue); | |
| 136 | |
| 137 ChangeRecord<_Handler> check() => null; | |
| 138 void remove() => null; | |
| 139 | |
| 140 get field => null; | |
| 141 get previousValue => null; | |
| 142 get object => null; | |
| 143 set object(_) => null; | |
| 144 get nextChange => null; | |
| 145 } | |
| 146 | |
| OLD | NEW |