Skip to content

Commit 20a8f0d

Browse files
committed
refactor(pipes): removed pipes from properties
BREAKING CHANGE: This PR remove an ability to use pipes in the properties config. Instead, inject the pipe registry.
1 parent ad7aca6 commit 20a8f0d

31 files changed

+260
-269
lines changed

modules/angular2/src/change_detection/change_detection_jit_generator.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ export class ChangeDetectorJITGenerator {
145145
_getNonNullPipeNames(): List<string> {
146146
var pipes = [];
147147
this.records.forEach((r) => {
148-
if (r.mode === RecordType.PIPE || r.mode === RecordType.BINDING_PIPE) {
148+
if (r.isPipeRecord()) {
149149
pipes.push(this._pipeNames[r.selfIndex]);
150150
}
151151
});
@@ -245,7 +245,7 @@ export class ChangeDetectorJITGenerator {
245245
var change = this._changeNames[r.selfIndex];
246246

247247
var pipe = this._pipeNames[r.selfIndex];
248-
var cdRef = r.mode === RecordType.BINDING_PIPE ? "this.ref" : "null";
248+
var cdRef = "this.ref";
249249

250250
var protoIndex = r.selfIndex - 1;
251251
var pipeType = r.name;

modules/angular2/src/change_detection/dynamic_change_detector.ts

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -269,14 +269,7 @@ export class DynamicChangeDetector extends AbstractChangeDetector {
269269
if (isPresent(storedPipe)) {
270270
storedPipe.onDestroy();
271271
}
272-
273-
// Currently, only pipes that used in bindings in the template get
274-
// the changeDetectorRef of the encompassing component.
275-
//
276-
// In the future, pipes declared in the bind configuration should
277-
// be able to access the changeDetectorRef of that component.
278-
var cdr = proto.mode === RecordType.BINDING_PIPE ? this.ref : null;
279-
var pipe = this.pipeRegistry.get(proto.name, context, cdr);
272+
var pipe = this.pipeRegistry.get(proto.name, context, this.ref);
280273
this._writePipe(proto, pipe);
281274
return pipe;
282275
}

modules/angular2/src/change_detection/parser/ast.ts

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -141,11 +141,8 @@ export class KeyedAccess extends AST {
141141
visit(visitor: AstVisitor) { return visitor.visitKeyedAccess(this); }
142142
}
143143

144-
export class Pipe extends AST {
145-
constructor(public exp: AST, public name: string, public args: List<any>,
146-
public inBinding: boolean) {
147-
super();
148-
}
144+
export class BindingPipe extends AST {
145+
constructor(public exp: AST, public name: string, public args: List<any>) { super(); }
149146

150147
visit(visitor: AstVisitor) { return visitor.visitPipe(this); }
151148
}
@@ -336,7 +333,7 @@ export interface AstVisitor {
336333
visitChain(ast: Chain): any;
337334
visitConditional(ast: Conditional): any;
338335
visitIf(ast: If): any;
339-
visitPipe(ast: Pipe): any;
336+
visitPipe(ast: BindingPipe): any;
340337
visitFunctionCall(ast: FunctionCall): any;
341338
visitImplicitReceiver(ast: ImplicitReceiver): any;
342339
visitInterpolation(ast: Interpolation): any;
@@ -394,8 +391,8 @@ export class AstTransformer implements AstVisitor {
394391
ast.falseExp.visit(this));
395392
}
396393

397-
visitPipe(ast: Pipe) {
398-
return new Pipe(ast.exp.visit(this), ast.name, this.visitAll(ast.args), ast.inBinding);
394+
visitPipe(ast: BindingPipe) {
395+
return new BindingPipe(ast.exp.visit(this), ast.name, this.visitAll(ast.args));
399396
}
400397

401398
visitKeyedAccess(ast: KeyedAccess) {

modules/angular2/src/change_detection/parser/parser.ts

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ import {
3434
PrefixNot,
3535
Conditional,
3636
If,
37-
Pipe,
37+
BindingPipe,
3838
Assignment,
3939
Chain,
4040
KeyedAccess,
@@ -73,15 +73,6 @@ export class Parser {
7373
return new ASTWithSource(ast, input, location);
7474
}
7575

76-
addPipes(bindingAst: ASTWithSource, pipes: List<string>): ASTWithSource {
77-
if (ListWrapper.isEmpty(pipes)) return bindingAst;
78-
79-
var res: AST = ListWrapper.reduce(
80-
pipes, (result, currentPipeName) => new Pipe(result, currentPipeName, [], false),
81-
bindingAst.ast);
82-
return new ASTWithSource(res, bindingAst.source, bindingAst.location);
83-
}
84-
8576
parseTemplateBindings(input: string, location: any): List<TemplateBinding> {
8677
var tokens = this._lexer.tokenize(input);
8778
return new _ParseAST(input, location, tokens, this._reflector, false).parseTemplateBindings();
@@ -224,7 +215,7 @@ class _ParseAST {
224215
while (this.optionalCharacter($COLON)) {
225216
args.push(this.parsePipe());
226217
}
227-
result = new Pipe(result, name, args, true);
218+
result = new BindingPipe(result, name, args);
228219
} while (this.optionalOperator("|"));
229220
}
230221

modules/angular2/src/change_detection/pipes/iterable_changes.ts

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,10 @@ import {
1515
isArray
1616
} from 'angular2/src/facade/lang';
1717

18-
import {WrappedValue, Pipe, PipeFactory} from './pipe';
18+
import {WrappedValue, Pipe, BasePipe, PipeFactory} from './pipe';
1919

2020
@CONST()
21-
export class IterableChangesFactory extends PipeFactory {
22-
constructor() { super(); }
23-
21+
export class IterableChangesFactory implements PipeFactory {
2422
supports(obj): boolean { return IterableChanges.supportsObj(obj); }
2523

2624
create(cdRef): Pipe { return new IterableChanges(); }
@@ -29,7 +27,7 @@ export class IterableChangesFactory extends PipeFactory {
2927
/**
3028
* @exportedAs angular2/pipes
3129
*/
32-
export class IterableChanges extends Pipe {
30+
export class IterableChanges extends BasePipe {
3331
private _collection = null;
3432
private _length: int = null;
3533
// Keeps track of the used records at any point in time (during & across `_check()` calls)
@@ -95,7 +93,7 @@ export class IterableChanges extends Pipe {
9593
if (this.check(collection)) {
9694
return WrappedValue.wrap(this);
9795
} else {
98-
return this;
96+
return null;
9997
}
10098
}
10199

modules/angular2/src/change_detection/pipes/json_pipe.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import {isBlank, isPresent, Json} from 'angular2/src/facade/lang';
2-
import {Pipe, PipeFactory} from './pipe';
2+
import {Pipe, BasePipe, PipeFactory} from './pipe';
33

44
/**
55
* Implements json transforms to any object.
@@ -26,9 +26,7 @@ import {Pipe, PipeFactory} from './pipe';
2626
*
2727
* @exportedAs angular2/pipes
2828
*/
29-
export class JsonPipe extends Pipe {
30-
supports(obj): boolean { return true; }
31-
29+
export class JsonPipe extends BasePipe {
3230
transform(value): string { return Json.stringify(value); }
3331

3432
create(cdRef): Pipe { return this }

modules/angular2/src/change_detection/pipes/keyvalue_changes.ts

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,13 @@
11
import {ListWrapper, MapWrapper, StringMapWrapper} from 'angular2/src/facade/collection';
22
import {stringify, looseIdentical, isJsObject, CONST} from 'angular2/src/facade/lang';
33

4-
import {WrappedValue, Pipe, PipeFactory} from './pipe';
4+
import {WrappedValue, BasePipe, Pipe, PipeFactory} from './pipe';
55

66
/**
77
* @exportedAs angular2/pipes
88
*/
99
@CONST()
10-
export class KeyValueChangesFactory extends PipeFactory {
11-
constructor() { super(); }
12-
10+
export class KeyValueChangesFactory implements PipeFactory {
1311
supports(obj): boolean { return KeyValueChanges.supportsObj(obj); }
1412

1513
create(cdRef): Pipe { return new KeyValueChanges(); }
@@ -18,7 +16,7 @@ export class KeyValueChangesFactory extends PipeFactory {
1816
/**
1917
* @exportedAs angular2/pipes
2018
*/
21-
export class KeyValueChanges extends Pipe {
19+
export class KeyValueChanges extends BasePipe {
2220
private _records: Map<any, any> = new Map();
2321
private _mapHead: KVChangeRecord = null;
2422
private _previousMapHead: KVChangeRecord = null;
@@ -37,7 +35,7 @@ export class KeyValueChanges extends Pipe {
3735
if (this.check(map)) {
3836
return WrappedValue.wrap(this);
3937
} else {
40-
return this;
38+
return null;
4139
}
4240
}
4341

modules/angular2/src/change_detection/pipes/lowercase_pipe.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ import {Pipe} from './pipe';
2323
*
2424
* @exportedAs angular2/pipes
2525
*/
26-
export class LowerCasePipe extends Pipe {
26+
export class LowerCasePipe implements Pipe {
2727
_latestValue: string = null;
2828

2929
supports(str): boolean { return isString(str); }

modules/angular2/src/change_detection/pipes/null_pipe.ts

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,11 @@
11
import {isBlank, CONST} from 'angular2/src/facade/lang';
2-
import {Pipe, WrappedValue, PipeFactory} from './pipe';
2+
import {Pipe, BasePipe, WrappedValue, PipeFactory} from './pipe';
33

44
/**
55
* @exportedAs angular2/pipes
66
*/
77
@CONST()
8-
export class NullPipeFactory extends PipeFactory {
9-
constructor() { super(); }
10-
8+
export class NullPipeFactory implements PipeFactory {
119
supports(obj): boolean { return NullPipe.supportsObj(obj); }
1210

1311
create(cdRef): Pipe { return new NullPipe(); }
@@ -16,7 +14,7 @@ export class NullPipeFactory extends PipeFactory {
1614
/**
1715
* @exportedAs angular2/pipes
1816
*/
19-
export class NullPipe extends Pipe {
17+
export class NullPipe extends BasePipe {
2018
called: boolean = false;
2119

2220
static supportsObj(obj): boolean { return isBlank(obj); }

modules/angular2/src/change_detection/pipes/observable_pipe.ts

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,14 +29,14 @@ import {ChangeDetectorRef} from '../change_detector_ref';
2929
*
3030
* @exportedAs angular2/pipes
3131
*/
32-
export class ObservablePipe extends Pipe {
32+
export class ObservablePipe implements Pipe {
3333
_latestValue: Object = null;
3434
_latestReturnedValue: Object = null;
3535

3636
_subscription: Object = null;
3737
_observable: Observable = null;
3838

39-
constructor(public _ref: ChangeDetectorRef) { super(); }
39+
constructor(public _ref: ChangeDetectorRef) {}
4040

4141
supports(obs): boolean { return ObservableWrapper.isObservable(obs); }
4242

@@ -91,9 +91,7 @@ export class ObservablePipe extends Pipe {
9191
* @exportedAs angular2/pipes
9292
*/
9393
@CONST()
94-
export class ObservablePipeFactory extends PipeFactory {
95-
constructor() { super(); }
96-
94+
export class ObservablePipeFactory implements PipeFactory {
9795
supports(obs): boolean { return ObservableWrapper.isObservable(obs); }
9896

9997
create(cdRef): Pipe { return new ObservablePipe(cdRef); }

0 commit comments

Comments
 (0)