| OLD | NEW |
| 1 part of angular.watch_group; | 1 part of angular.watch_group; |
| 2 | 2 |
| 3 | 3 |
| 4 /** | 4 /** |
| 5 * RULES: | 5 * RULES: |
| 6 * - ASTs are reusable. Don't store scope/instance refs there | 6 * - ASTs are reusable. Don't store scope/instance refs there |
| 7 * - Parent knows about children, not the other way around. | 7 * - Parent knows about children, not the other way around. |
| 8 */ | 8 */ |
| 9 abstract class AST { | 9 abstract class AST { |
| 10 static final String _CONTEXT = '#'; | 10 static final String _CONTEXT = '#'; |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 72 * | 72 * |
| 73 * Invoke a pure function. Pure means that the function has no state, and | 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. | 74 * therefore it needs to be re-computed only if its args change. |
| 75 */ | 75 */ |
| 76 class PureFunctionAST extends AST { | 76 class PureFunctionAST extends AST { |
| 77 final String name; | 77 final String name; |
| 78 final /* dartbug.com/16401 Function */ fn; | 78 final /* dartbug.com/16401 Function */ fn; |
| 79 final List<AST> argsAST; | 79 final List<AST> argsAST; |
| 80 | 80 |
| 81 PureFunctionAST(name, this.fn, argsAST) | 81 PureFunctionAST(name, this.fn, argsAST) |
| 82 : argsAST = argsAST, | 82 : super('$name(${_argList(argsAST)})'), |
| 83 name = name, | 83 argsAST = argsAST, |
| 84 super('$name(${_argList(argsAST)})'); | 84 name = name; |
| 85 | 85 |
| 86 WatchRecord<_Handler> setupWatch(WatchGroup watchGroup) => | 86 WatchRecord<_Handler> setupWatch(WatchGroup watchGroup) => |
| 87 watchGroup.addFunctionWatch(fn, argsAST, const {}, expression, true); | 87 watchGroup.addFunctionWatch(fn, argsAST, expression); |
| 88 } | 88 } |
| 89 | 89 |
| 90 /** | 90 /** |
| 91 * SYNTAX: fn(arg0, arg1, ...) | |
| 92 * | |
| 93 * Invoke a pure function. Pure means that the function has no state, and | |
| 94 * therefore it needs to be re-computed only if its args change. | |
| 95 */ | |
| 96 class ClosureAST extends AST { | |
| 97 final String name; | |
| 98 final /* dartbug.com/16401 Function */ fn; | |
| 99 final List<AST> argsAST; | |
| 100 | |
| 101 ClosureAST(name, this.fn, argsAST) | |
| 102 : argsAST = argsAST, | |
| 103 name = name, | |
| 104 super('$name(${_argList(argsAST)})'); | |
| 105 | |
| 106 WatchRecord<_Handler> setupWatch(WatchGroup watchGroup) => | |
| 107 watchGroup.addFunctionWatch(fn, argsAST, const {}, expression, false); | |
| 108 } | |
| 109 | |
| 110 /** | |
| 111 * SYNTAX: lhs.method(arg0, arg1, ...) | 91 * SYNTAX: lhs.method(arg0, arg1, ...) |
| 112 * | 92 * |
| 113 * Invoke a method on [lhs] object. | 93 * Invoke a method on [lhs] object. |
| 114 */ | 94 */ |
| 115 class MethodAST extends AST { | 95 class MethodAST extends AST { |
| 116 final AST lhsAST; | 96 final AST lhsAST; |
| 117 final String name; | 97 final String name; |
| 118 final List<AST> argsAST; | 98 final List<AST> argsAST; |
| 119 final Map<Symbol, AST> namedArgsAST; | |
| 120 | 99 |
| 121 MethodAST(lhsAST, name, argsAST, [this.namedArgsAST = const {}]) | 100 MethodAST(lhsAST, name, argsAST) |
| 122 : lhsAST = lhsAST, | 101 : super('$lhsAST.$name(${_argList(argsAST)})'), |
| 102 lhsAST = lhsAST, |
| 123 name = name, | 103 name = name, |
| 124 argsAST = argsAST, | 104 argsAST = argsAST; |
| 125 super('$lhsAST.$name(${_argList(argsAST)})'); | |
| 126 | 105 |
| 127 WatchRecord<_Handler> setupWatch(WatchGroup watchGroup) => | 106 WatchRecord<_Handler> setupWatch(WatchGroup watchGroup) => |
| 128 watchGroup.addMethodWatch(lhsAST, name, argsAST, namedArgsAST, expression)
; | 107 watchGroup.addMethodWatch(lhsAST, name, argsAST, expression); |
| 129 } | 108 } |
| 130 | 109 |
| 131 | 110 |
| 132 class CollectionAST extends AST { | 111 class CollectionAST extends AST { |
| 133 final AST valueAST; | 112 final AST valueAST; |
| 134 CollectionAST(valueAST) | 113 CollectionAST(valueAST) |
| 135 : valueAST = valueAST, | 114 : valueAST = valueAST, |
| 136 super('#collection($valueAST)'); | 115 super('#collection($valueAST)'); |
| 137 | 116 |
| 138 WatchRecord<_Handler> setupWatch(WatchGroup watchGroup) => | 117 WatchRecord<_Handler> setupWatch(WatchGroup watchGroup) => |
| 139 watchGroup.addCollectionWatch(valueAST); | 118 watchGroup.addCollectionWatch(valueAST); |
| 140 } | 119 } |
| 141 | 120 |
| 142 String _argList(List<AST> items) => items.join(', '); | 121 String _argList(List<AST> items) => items.join(', '); |
| 143 | 122 |
| 144 /** | 123 /** |
| 145 * The name is a bit oxymoron, but it is essentially the NullObject pattern. | 124 * The name is a bit oxymoron, but it is essentially the NullObject pattern. |
| 146 * | 125 * |
| 147 * This allows children to set a handler on this Record and then let it write | 126 * This allows children to set a handler on this ChangeRecord and then let it wr
ite the initial |
| 148 * the initial constant value to the forwarding Record. | 127 * constant value to the forwarding ChangeRecord. |
| 149 */ | 128 */ |
| 150 class _ConstantWatchRecord extends WatchRecord<_Handler> { | 129 class _ConstantWatchRecord extends WatchRecord<_Handler> { |
| 151 final currentValue; | 130 final currentValue; |
| 152 final _Handler handler; | 131 final _Handler handler; |
| 153 | 132 |
| 154 _ConstantWatchRecord(WatchGroup watchGroup, String expression, currentValue) | 133 _ConstantWatchRecord(WatchGroup watchGroup, String expression, currentValue) |
| 155 : currentValue = currentValue, | 134 : currentValue = currentValue, |
| 156 handler = new _ConstantHandler(watchGroup, expression, currentValue); | 135 handler = new _ConstantHandler(watchGroup, expression, currentValue); |
| 157 | 136 |
| 158 bool check() => false; | 137 ChangeRecord<_Handler> check() => null; |
| 159 void remove() => null; | 138 void remove() => null; |
| 160 | 139 |
| 161 get field => null; | 140 get field => null; |
| 162 get previousValue => null; | 141 get previousValue => null; |
| 163 get object => null; | 142 get object => null; |
| 164 set object(_) => null; | 143 set object(_) => null; |
| 165 get nextChange => null; | 144 get nextChange => null; |
| 166 } | 145 } |
| 167 | 146 |
| OLD | NEW |