Skip to content
This repository has been archived by the owner on Feb 22, 2018. It is now read-only.

[WIP] feat(filters): add filters in support of pure fields and methods, and to observe lists and maps #771

Conversation

chalin
Copy link
Contributor

@chalin chalin commented Mar 20, 2014

Addresses: #359, #394, #397, #757.

@chalin
Copy link
Contributor Author

chalin commented Mar 20, 2014

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 toString. The goal, now that #763 has been closed, is to propose something that (I believe) is consistent with Angular design goals.

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 lowercase and uppercase.

@mhevery
Copy link
Contributor

mhevery commented Mar 20, 2014

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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should be "filtered argument"

@vicb
Copy link
Contributor

vicb commented Mar 20, 2014

  • Should field & method be merged into a single filter ?
  • Could you please update the commit comment with "Closes #..., Relates to #...,". Thanks.

class ApplyPureMethodFilter implements Function {
dynamic call(dynamic receiver, String functionName, [List args]) {
if (receiver == null) return null;
var mirror = reflect(receiver),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

final

@chalin
Copy link
Contributor Author

chalin commented Mar 20, 2014

Should field & method be merged into a single filter ?

Not sure what to call it then.

@vicb
Copy link
Contributor

vicb commented Mar 20, 2014

Python calls that attr

@vicb
Copy link
Contributor

vicb commented Mar 20, 2014

I guess Dart would call that "method" (cf noSuchMethod). It makes sense if you see a property as a (getter, setter) pair but it would not be very intuitive.

I wouldn't mind:

  • access
  • field
  • attr(ibute)

In order of preference

@chalin
Copy link
Contributor Author

chalin commented Mar 20, 2014

How about member? That is what fields and methods are collectively referred to in Dart---cf. the "." operator name in DUnR.

@vicb
Copy link
Contributor

vicb commented Mar 20, 2014

member could be good as well...

But in the end the solution is maybe to keep separate directives, the common code is short and the arguments are different anyway.

@chalin
Copy link
Contributor Author

chalin commented Mar 20, 2014

Btw, how about renaming id to something like observe?

@chalin chalin changed the title feat(filters): add general purpose filters in support of pure fields and methods feat(filters): add filters in support of pure fields and methods, and to observe lists and maps Mar 20, 2014
@chalin
Copy link
Contributor Author

chalin commented Mar 20, 2014

Updated:

  • Now properly handles namedArgs.
  • Added tests.
  • Renamed id filter to observe
  • Updated API docs.

Once / if support is added for the Dart/Jinja-like filter argument syntax, then the method filter should be improved to handle arguments a la Dart.

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) {
Copy link
Contributor

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 ?

@chalin
Copy link
Contributor Author

chalin commented Mar 20, 2014

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));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

_namedArgs[new S] = v ?

@@ -1,6 +1,7 @@
library angular.filter;

import 'dart:convert' show JSON;
import 'dart:mirrors';
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mhevery
Copy link
Contributor

mhevery commented Apr 1, 2014

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.

@chalin chalin changed the title feat(filters): add filters in support of pure fields and methods, and to observe lists and maps [WIP] feat(filters): add filters in support of pure fields and methods, and to observe lists and maps Apr 2, 2014
@chalin
Copy link
Contributor Author

chalin commented Apr 2, 2014

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 stringify filter will achieve the effect of the observe filter of this PR. Hence, observe can be dropped. You are likely right that the other two filters might not be usable given that they are generic. Anyhow, I'll have a look as soon as I have finished the date work.

@mhevery
Copy link
Contributor

mhevery commented Apr 18, 2014

I am going to close this due to inactivity. If you can get this working without mirrors then resubmit as new PR.

@mhevery mhevery closed this Apr 18, 2014
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Development

Successfully merging this pull request may close these issues.

6 participants