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 : super('$name(${_argList(argsAST)})'), | 82 : argsAST = argsAST, |
83 argsAST = argsAST, | 83 name = name, |
84 name = name; | 84 super('$name(${_argList(argsAST)})'); |
85 | 85 |
86 WatchRecord<_Handler> setupWatch(WatchGroup watchGroup) => | 86 WatchRecord<_Handler> setupWatch(WatchGroup watchGroup) => |
87 watchGroup.addFunctionWatch(fn, argsAST, expression); | 87 watchGroup.addFunctionWatch(fn, argsAST, const {}, expression, true); |
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 /** |
91 * SYNTAX: lhs.method(arg0, arg1, ...) | 111 * SYNTAX: lhs.method(arg0, arg1, ...) |
92 * | 112 * |
93 * Invoke a method on [lhs] object. | 113 * Invoke a method on [lhs] object. |
94 */ | 114 */ |
95 class MethodAST extends AST { | 115 class MethodAST extends AST { |
96 final AST lhsAST; | 116 final AST lhsAST; |
97 final String name; | 117 final String name; |
98 final List<AST> argsAST; | 118 final List<AST> argsAST; |
| 119 final Map<Symbol, AST> namedArgsAST; |
99 | 120 |
100 MethodAST(lhsAST, name, argsAST) | 121 MethodAST(lhsAST, name, argsAST, [this.namedArgsAST = const {}]) |
101 : super('$lhsAST.$name(${_argList(argsAST)})'), | 122 : lhsAST = lhsAST, |
102 lhsAST = lhsAST, | |
103 name = name, | 123 name = name, |
104 argsAST = argsAST; | 124 argsAST = argsAST, |
| 125 super('$lhsAST.$name(${_argList(argsAST)})'); |
105 | 126 |
106 WatchRecord<_Handler> setupWatch(WatchGroup watchGroup) => | 127 WatchRecord<_Handler> setupWatch(WatchGroup watchGroup) => |
107 watchGroup.addMethodWatch(lhsAST, name, argsAST, expression); | 128 watchGroup.addMethodWatch(lhsAST, name, argsAST, namedArgsAST, expression)
; |
108 } | 129 } |
109 | 130 |
110 | 131 |
111 class CollectionAST extends AST { | 132 class CollectionAST extends AST { |
112 final AST valueAST; | 133 final AST valueAST; |
113 CollectionAST(valueAST) | 134 CollectionAST(valueAST) |
114 : valueAST = valueAST, | 135 : valueAST = valueAST, |
115 super('#collection($valueAST)'); | 136 super('#collection($valueAST)'); |
116 | 137 |
117 WatchRecord<_Handler> setupWatch(WatchGroup watchGroup) => | 138 WatchRecord<_Handler> setupWatch(WatchGroup watchGroup) => |
118 watchGroup.addCollectionWatch(valueAST); | 139 watchGroup.addCollectionWatch(valueAST); |
119 } | 140 } |
120 | 141 |
121 String _argList(List<AST> items) => items.join(', '); | 142 String _argList(List<AST> items) => items.join(', '); |
122 | 143 |
123 /** | 144 /** |
124 * The name is a bit oxymoron, but it is essentially the NullObject pattern. | 145 * The name is a bit oxymoron, but it is essentially the NullObject pattern. |
125 * | 146 * |
126 * This allows children to set a handler on this ChangeRecord and then let it wr
ite the initial | 147 * This allows children to set a handler on this Record and then let it write |
127 * constant value to the forwarding ChangeRecord. | 148 * the initial constant value to the forwarding Record. |
128 */ | 149 */ |
129 class _ConstantWatchRecord extends WatchRecord<_Handler> { | 150 class _ConstantWatchRecord extends WatchRecord<_Handler> { |
130 final currentValue; | 151 final currentValue; |
131 final _Handler handler; | 152 final _Handler handler; |
132 | 153 |
133 _ConstantWatchRecord(WatchGroup watchGroup, String expression, currentValue) | 154 _ConstantWatchRecord(WatchGroup watchGroup, String expression, currentValue) |
134 : currentValue = currentValue, | 155 : currentValue = currentValue, |
135 handler = new _ConstantHandler(watchGroup, expression, currentValue); | 156 handler = new _ConstantHandler(watchGroup, expression, currentValue); |
136 | 157 |
137 ChangeRecord<_Handler> check() => null; | 158 bool check() => false; |
138 void remove() => null; | 159 void remove() => null; |
139 | 160 |
140 get field => null; | 161 get field => null; |
141 get previousValue => null; | 162 get previousValue => null; |
142 get object => null; | 163 get object => null; |
143 set object(_) => null; | 164 set object(_) => null; |
144 get nextChange => null; | 165 get nextChange => null; |
145 } | 166 } |
146 | 167 |
OLD | NEW |