-
Notifications
You must be signed in to change notification settings - Fork 248
[WIP] feat(filters): add filters in support of pure fields and methods, and to observe lists and maps #771
Conversation
One last(?) attempt at providing a general solution to partly address some of the concerns raised in #705, and to salvage some lecture material and the AngularDart tutorial ... without requiring each user to write a bunch of "utility" filters, like Of course these filters might not be as efficient as custom filters, but users are always free to write their own. These may even subsume |
Yes this is great. Look at https://github.com/mhevery/angular.dart/tree/no-mirrors notice how I have moved all of the mirrors to a separate import. We need to do this so that we have reasonable size outputs. Transforms which generate all reflective code are coming here https://github.com/mhevery/angular.dart/tree/transformers Your PR needs to work with these changes which will be merged in the next few days. |
|
||
/** | ||
* General purpose filter used to perform a "get field" operation on the named | ||
* field of the filter argument. Use this when the "get field" operation is |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should be "filtered argument"
|
class ApplyPureMethodFilter implements Function { | ||
dynamic call(dynamic receiver, String functionName, [List args]) { | ||
if (receiver == null) return null; | ||
var mirror = reflect(receiver), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
final
Not sure what to call it then. |
Python calls that attr |
I guess Dart would call that "method" (cf I wouldn't mind:
In order of preference |
How about |
But in the end the solution is maybe to keep separate directives, the common code is short and the arguments are different anyway. |
Btw, how about renaming |
Updated:
Once / if support is added for the Dart/Jinja-like filter argument syntax, then the I will work on trying to create a version of pure.dart over Misko's no-mirrors branch (or should I just wait for it to get merged into master?). |
args = const []; | ||
} | ||
Map<Symbol,dynamic> _namedArgs; | ||
if (namedArgs != null) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't have time to check right now but couldn't this be simpler ?
- We should be using final where possible, see https://groups.google.com/a/dartlang.org/forum/#!topic/misc/qccnux8c6BE
- Do you really need to copy the map ? the may be Map.from
- Couldn't invoke be invoked with null / {} as a last arg ?
Simplified. (You were correct, it accepts an empty map.) |
final Map<Symbol,dynamic> _namedArgs = namedArgs == null ? | ||
const <Symbol,dynamic>{} : <Symbol,dynamic>{}; | ||
if (namedArgs != null) { | ||
namedArgs.forEach((k,v) => _namedArgs.putIfAbsent(new Symbol(k), () => v)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
_namedArgs[new S] = v ?
… to observe lists and maps Closes dart-archive#359, dart-archive#394, dart-archive#397, dart-archive#757. Relates to dart-archive#772, dart-archive#773.
@@ -1,6 +1,7 @@ | |||
library angular.filter; | |||
|
|||
import 'dart:convert' show JSON; | |||
import 'dart:mirrors'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Mirrors can not be used in Angular. See
https://github.com/angular/angular.dart/blob/master/lib/angular_dynamic.dart
https://github.com/angular/angular.dart/blob/master/lib/angular_static.dart
and
https://github.com/angular/angular.dart/blob/master/example/pubspec.yaml#L10
Basically mirrors get replaced with generated code using the transformers during the compilation phase.
I am skeptical that we will be able to get this in due to the way this uses mirrors. We now have a compile step which removes all the mirrors from the code base using the transformers, and this code would break the transformers. To get this in, we need to solve this in a way which does not use mirrors API. |
I was waiting for your the new angular_dynamic/static code to be in before looking into this further. Now that it is part of master I will have a look. @vicb's |
I am going to close this due to inactivity. If you can get this working without mirrors then resubmit as new PR. |
Addresses: #359, #394, #397, #757.