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

style: rename Filter to Formatter #983

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions lib/core/annotation_src.dart
Original file line number Diff line number Diff line change
Expand Up @@ -553,21 +553,21 @@ abstract class DetachAware {
* Usage:
*
* // Declaration
* @Formatter(name:'myFilter')
* class MyFilter {
* call(valueToFilter, optArg1, optArg2) {
* @Formatter(name:'myFormatter')
* class MyFormatter {
* call(valueToFormat, optArg1, optArg2) {
* return ...;
* }
* }
*
*
* // Registration
* var module = ...;
* module.type(MyFilter);
* module.type(MyFormatter);
*
*
* <!-- Usage -->
* <span>{{something | myFilter:arg1:arg2}}</span>
* <span>{{something | myFormatter:arg1:arg2}}</span>
*/
class Formatter {
final String name;
Expand Down
6 changes: 3 additions & 3 deletions lib/core/formatter.dart
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ class FormatterMap extends AnnotationMap<Formatter> {
super(injector, extractMetadata);

call(String name) {
var filter = new Formatter(name: name);
var filterType = this[filter];
return _injector.get(filterType);
var formatter = new Formatter(name: name);
var formatterType = this[formatter];
return _injector.get(formatterType);
}
}

1 change: 0 additions & 1 deletion lib/core/module.dart
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,6 @@ export "package:angular/core_dom/module_internal.dart" show
export "package:angular/core/module_internal.dart" show
CacheStats,
ExceptionHandler,
FilterMap,
Interpolate,
VmTurnZone,
PrototypeMap,
Expand Down
2 changes: 1 addition & 1 deletion lib/core/module_internal.dart
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export 'package:angular/change_detection/watch_group.dart';
import 'package:angular/change_detection/change_detection.dart';
import 'package:angular/change_detection/dirty_checking_change_detector.dart';
import 'package:angular/core/parser/utils.dart';
import 'package:angular/core/parser/syntax.dart';
import 'package:angular/core/parser/syntax.dart' as syntax;
import 'package:angular/core/registry.dart';

part "cache.dart";
Expand Down
6 changes: 3 additions & 3 deletions lib/core/parser/dynamic_parser.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
library angular.core.parser.dynamic_parser;

import 'package:angular/core/annotation_src.dart';
import 'package:angular/core/annotation_src.dart' hide Formatter;
import 'package:angular/core/module_internal.dart' show FormatterMap;

import 'package:angular/core/parser/parser.dart';
Expand Down Expand Up @@ -72,11 +72,11 @@ class DynamicParserBackend extends ParserBackend {

bool isAssignable(Expression expression) => expression.isAssignable;

Expression newFilter(expression, name, arguments) {
Expression newFormatter(expression, name, arguments) {
List allArguments = new List(arguments.length + 1);
allArguments[0] = expression;
allArguments.setAll(1, arguments);
return new Filter(expression, name, arguments, allArguments);
return new Formatter(expression, name, arguments, allArguments);
}

Expression newChain(expressions) => new Chain(expressions);
Expand Down
10 changes: 5 additions & 5 deletions lib/core/parser/dynamic_parser_impl.dart
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,12 @@ class DynamicParserImpl {
next.isCharacter($RBRACKET)) {
error('Unconsumed token $next');
}
var expr = parseFilter();
var expr = parseFormatter();
expressions.add(expr);
while (optionalCharacter($SEMICOLON)) {
isChain = true;
}
if (isChain && expr is Filter) {
if (isChain && expr is Formatter) {
error('Cannot have a formatter in a chain');
}
if (!isChain && index < tokens.length) {
Expand All @@ -49,7 +49,7 @@ class DynamicParserImpl {
: backend.newChain(expressions);
}

parseFilter() {
parseFormatter() {
var result = parseExpression();
while (optionalOperator('|')) {
String name = expectIdentifierOrKeyword();
Expand All @@ -58,7 +58,7 @@ class DynamicParserImpl {
// TODO(kasperl): Is this really supposed to be expressions?
arguments.add(parseExpression());
}
result = backend.newFilter(result, name, arguments);
result = backend.newFormatter(result, name, arguments);
}
return result;
}
Expand Down Expand Up @@ -217,7 +217,7 @@ class DynamicParserImpl {

parsePrimary() {
if (optionalCharacter($LPAREN)) {
var result = parseFilter();
var result = parseFormatter();
expectCharacter($RPAREN);
return result;
} else if (next.isKeywordNull || next.isKeywordUndefined) {
Expand Down
4 changes: 2 additions & 2 deletions lib/core/parser/eval.dart
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ class Chain extends syntax.Chain {
}
}

class Filter extends syntax.Filter {
class Formatter extends syntax.Formatter {
final List<syntax.Expression> allArguments;
Filter(syntax.Expression expression, String name, List<syntax.Expression> arguments,
Formatter(syntax.Expression expression, String name, List<syntax.Expression> arguments,
this.allArguments)
: super(expression, name, arguments);

Expand Down
2 changes: 1 addition & 1 deletion lib/core/parser/parser.dart
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ abstract class ParserBackend<T> {
bool isAssignable(T expression);

T newChain(List expressions) => null;
T newFilter(T expression, String name, List arguments) => null;
T newFormatter(T expression, String name, List arguments) => null;

T newAssign(T target, T value) => null;
T newConditional(T condition, T yes, T no) => null;
Expand Down
8 changes: 4 additions & 4 deletions lib/core/parser/syntax.dart
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ abstract class Visitor {

visitExpression(Expression expression) => null;
visitChain(Chain expression) => visitExpression(expression);
visitFilter(Filter expression) => visitExpression(expression);
visitFormatter(Formatter expression) => visitExpression(expression);

visitAssign(Assign expression) => visitExpression(expression);
visitConditional(Conditional expression) => visitExpression(expression);
Expand Down Expand Up @@ -73,12 +73,12 @@ class Chain extends Expression {
accept(Visitor visitor) => visitor.visitChain(this);
}

class Filter extends Expression {
class Formatter extends Expression {
final Expression expression;
final String name;
final List<Expression> arguments;
Filter(this.expression, this.name, this.arguments);
accept(Visitor visitor) => visitor.visitFilter(this);
Formatter(this.expression, this.name, this.arguments);
accept(Visitor visitor) => visitor.visitFormatter(this);
}

class Assign extends Expression {
Expand Down
10 changes: 5 additions & 5 deletions lib/core/parser/unparser.dart
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,13 @@ class Unparser extends Visitor {
}
}

void visitFilter(Filter filter) {
void visitFormatter(Formatter formatter) {
write('(');
visit(filter.expression);
write('|${filter.name}');
for (int i = 0; i < filter.arguments.length; i++) {
visit(formatter.expression);
write('|${formatter.name}');
for (int i = 0; i < formatter.arguments.length; i++) {
write(' :');
visit(filter.arguments[i]);
visit(formatter.arguments[i]);
}
write(')');
}
Expand Down
62 changes: 31 additions & 31 deletions lib/core/scope.dart
Original file line number Diff line number Diff line change
Expand Up @@ -1061,7 +1061,7 @@ class _AstParser {
}
}

class ExpressionVisitor implements Visitor {
class ExpressionVisitor implements syntax.Visitor {
static final ContextReferenceAST scopeContextRef = new ContextReferenceAST();
final ClosureMap _closureMap;
AST contextRef = scopeContextRef;
Expand All @@ -1072,7 +1072,7 @@ class ExpressionVisitor implements Visitor {
AST ast;
FormatterMap formatters;

AST visit(Expression exp) {
AST visit(syntax.Expression exp) {
exp.accept(this);
assert(ast != null);
try {
Expand All @@ -1082,68 +1082,68 @@ class ExpressionVisitor implements Visitor {
}
}

AST visitCollection(Expression exp) => new CollectionAST(visit(exp));
AST _mapToAst(Expression expression) => visit(expression);
AST visitCollection(syntax.Expression exp) => new CollectionAST(visit(exp));
AST _mapToAst(syntax.Expression expression) => visit(expression);

List<AST> _toAst(List<Expression> expressions) =>
List<AST> _toAst(List<syntax.Expression> expressions) =>
expressions.map(_mapToAst).toList();

Map<Symbol, AST> _toAstMap(Map<String, Expression> expressions) {
Map<Symbol, AST> _toAstMap(Map<String, syntax.Expression> expressions) {
if (expressions.isEmpty) return const {};
Map<Symbol, AST> result = new Map<Symbol, AST>();
expressions.forEach((String name, Expression expression) {
expressions.forEach((String name, syntax.Expression expression) {
result[_closureMap.lookupSymbol(name)] = _mapToAst(expression);
});
return result;
}

void visitCallScope(CallScope exp) {
void visitCallScope(syntax.CallScope exp) {
List<AST> positionals = _toAst(exp.arguments.positionals);
Map<Symbol, AST> named = _toAstMap(exp.arguments.named);
ast = new MethodAST(contextRef, exp.name, positionals, named);
}
void visitCallMember(CallMember exp) {
void visitCallMember(syntax.CallMember exp) {
List<AST> positionals = _toAst(exp.arguments.positionals);
Map<Symbol, AST> named = _toAstMap(exp.arguments.named);
ast = new MethodAST(visit(exp.object), exp.name, positionals, named);
}
visitAccessScope(AccessScope exp) {
void visitAccessScope(syntax.AccessScope exp) {
ast = new FieldReadAST(contextRef, exp.name);
}
visitAccessMember(AccessMember exp) {
void visitAccessMember(syntax.AccessMember exp) {
ast = new FieldReadAST(visit(exp.object), exp.name);
}
visitBinary(Binary exp) {
void visitBinary(syntax.Binary exp) {
ast = new PureFunctionAST(exp.operation,
_operationToFunction(exp.operation),
[visit(exp.left), visit(exp.right)]);
}
void visitPrefix(Prefix exp) {
void visitPrefix(syntax.Prefix exp) {
ast = new PureFunctionAST(exp.operation,
_operationToFunction(exp.operation),
[visit(exp.expression)]);
}
void visitConditional(Conditional exp) {
void visitConditional(syntax.Conditional exp) {
ast = new PureFunctionAST('?:', _operation_ternary,
[visit(exp.condition), visit(exp.yes),
visit(exp.no)]);
}
void visitAccessKeyed(AccessKeyed exp) {
void visitAccessKeyed(syntax.AccessKeyed exp) {
ast = new ClosureAST('[]', _operation_bracket,
[visit(exp.object), visit(exp.key)]);
}
void visitLiteralPrimitive(LiteralPrimitive exp) {
void visitLiteralPrimitive(syntax.LiteralPrimitive exp) {
ast = new ConstantAST(exp.value);
}
void visitLiteralString(LiteralString exp) {
void visitLiteralString(syntax.LiteralString exp) {
ast = new ConstantAST(exp.value);
}
void visitLiteralArray(LiteralArray exp) {
void visitLiteralArray(syntax.LiteralArray exp) {
List<AST> items = _toAst(exp.elements);
ast = new PureFunctionAST('[${items.join(', ')}]', new ArrayFn(), items);
}

void visitLiteralObject(LiteralObject exp) {
void visitLiteralObject(syntax.LiteralObject exp) {
List<String> keys = exp.keys;
List<AST> values = _toAst(exp.values);
assert(keys.length == values.length);
Expand All @@ -1154,31 +1154,31 @@ class ExpressionVisitor implements Visitor {
ast = new PureFunctionAST('{${kv.join(', ')}}', new MapFn(keys), values);
}

void visitFilter(Filter exp) {
void visitFormatter(syntax.Formatter exp) {
if (formatters == null) {
throw new Exception("No formatters have been registered");
}
Function filterFunction = formatters(exp.name);
Function formatterFunction = formatters(exp.name);
List<AST> args = [visitCollection(exp.expression)];
args.addAll(_toAst(exp.arguments).map((ast) => new CollectionAST(ast)));
ast = new PureFunctionAST('|${exp.name}',
new _FilterWrapper(filterFunction, args.length), args);
new _FormatterWrapper(formatterFunction, args.length), args);
}

// TODO(misko): this is a corner case. Choosing not to implement for now.
void visitCallFunction(CallFunction exp) {
void visitCallFunction(syntax.CallFunction exp) {
_notSupported("function's returing functions");
}
void visitAssign(Assign exp) {
void visitAssign(syntax.Assign exp) {
_notSupported('assignement');
}
void visitLiteral(Literal exp) {
void visitLiteral(syntax.Literal exp) {
_notSupported('literal');
}
void visitExpression(Expression exp) {
void visitExpression(syntax.Expression exp) {
_notSupported('?');
}
void visitChain(Chain exp) {
void visitChain(syntax.Chain exp) {
_notSupported(';');
}

Expand Down Expand Up @@ -1249,11 +1249,11 @@ class MapFn extends FunctionApply {
}
}

class _FilterWrapper extends FunctionApply {
final Function filterFn;
class _FormatterWrapper extends FunctionApply {
final Function formatterFn;
final List args;
final List<Watch> argsWatches;
_FilterWrapper(this.filterFn, length):
_FormatterWrapper(this.formatterFn, length):
args = new List(length),
argsWatches = new List(length);

Expand All @@ -1271,7 +1271,7 @@ class _FilterWrapper extends FunctionApply {
}
}
}
var value = Function.apply(filterFn, args);
var value = Function.apply(formatterFn, args);
if (value is Iterable) {
// Since formatters are pure we can guarantee that this well never change.
// By wrapping in UnmodifiableListView we can hint to the dirty checker
Expand Down
2 changes: 1 addition & 1 deletion lib/core_dom/common.dart
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ class DirectiveRef {
* Creates a child injector that allows loading new directives, formatters and
* services from the provided modules.
*/
Injector forceNewDirectivesAndFilters(Injector injector, List<Module> modules) {
Injector forceNewDirectivesAndFormatters(Injector injector, List<Module> modules) {
modules.add(new Module()
..factory(Scope, (i) {
var scope = i.parent.get(Scope);
Expand Down
2 changes: 1 addition & 1 deletion lib/directive/ng_repeat.dart
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ part of angular.directive;
* specified the ng-repeat associates elements by identity in the collection.
* It is an error to have more than one tracking function to resolve to the
* same key. (This would mean that two distinct objects are mapped to the same
* DOM element, which is not possible.) Filters should be applied to the
* DOM element, which is not possible.) Formatters should be applied to the
* expression, before specifying a tracking expression.
*
* For example: `item in items` is equivalent to `item in items track by
Expand Down
2 changes: 1 addition & 1 deletion lib/routing/ng_view.dart
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ class NgView implements DetachAware, RouteProvider {

var viewInjector = modules == null ?
_injector :
forceNewDirectivesAndFilters(_injector, modules);
forceNewDirectivesAndFormatters(_injector, modules);

var newDirectives = viewInjector.get(DirectiveMap);
var viewFuture = viewDef.templateHtml != null ?
Expand Down
Loading