Skip to content

Commit 8d85b83

Browse files
committed
feat(change_detection): pass binding propagation config to pipe registry
1 parent dd235f3 commit 8d85b83

21 files changed

+69
-37
lines changed

modules/angular2/change_detection.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ export {ProtoChangeDetector, DynamicProtoChangeDetector, JitProtoChangeDetector,
1111
from './src/change_detection/proto_change_detector';
1212
export {DynamicChangeDetector}
1313
from './src/change_detection/dynamic_change_detector';
14+
export {BindingPropagationConfig}
15+
from './src/change_detection/binding_propagation_config';
1416
export * from './src/change_detection/pipes/pipe_registry';
1517
export {uninitialized} from './src/change_detection/change_detection_util';
1618
export * from './src/change_detection/pipes/pipe';

modules/angular2/core.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,5 @@ export * from './src/core/compiler/compiler';
99
export * from './src/core/compiler/template_loader';
1010
export * from './src/core/compiler/view';
1111
export * from './src/core/compiler/view_container';
12-
export * from './src/core/compiler/binding_propagation_config';
1312

1413
export * from './src/core/dom/element';

modules/angular2/src/change_detection/abstract_change_detector.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,18 @@
11
import {isPresent} from 'angular2/src/facade/lang';
22
import {List, ListWrapper} from 'angular2/src/facade/collection';
3+
import {BindingPropagationConfig} from './binding_propagation_config';
34
import {ChangeDetector, CHECK_ALWAYS, CHECK_ONCE, CHECKED, DETACHED} from './interfaces';
45

56
export class AbstractChangeDetector extends ChangeDetector {
67
children:List;
78
parent:ChangeDetector;
89
mode:string;
10+
bindingPropagationConfig:BindingPropagationConfig;
911

1012
constructor() {
1113
super();
1214
this.children = [];
15+
this.bindingPropagationConfig = new BindingPropagationConfig(this);
1316
this.mode = CHECK_ALWAYS;
1417
}
1518

modules/angular2/src/core/compiler/binding_propagation_config.js renamed to modules/angular2/src/change_detection/binding_propagation_config.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import {ChangeDetector, CHECK_ONCE, DETACHED, CHECK_ALWAYS} from 'angular2/change_detection';
1+
import {ChangeDetector, CHECK_ONCE, DETACHED, CHECK_ALWAYS} from './interfaces';
22

33
/**
44
* @publicModule angular2/angular2

modules/angular2/src/change_detection/change_detection_jit_generator.es6

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import {
1515
RECORD_TYPE_PRIMITIVE_OP,
1616
RECORD_TYPE_KEYED_ACCESS,
1717
RECORD_TYPE_PIPE,
18+
RECORD_TYPE_BINDING_PIPE,
1819
RECORD_TYPE_INTERPOLATE
1920
} from './proto_record';
2021

@@ -180,14 +181,14 @@ if (${CHANGES_LOCAL} && ${CHANGES_LOCAL}.length > 0) {
180181
`;
181182
}
182183

183-
function pipeCheckTemplate(context:string, pipe:string, pipeType:string,
184+
function pipeCheckTemplate(context:string, bindingPropagationConfig:string, pipe:string, pipeType:string,
184185
value:string, change:string, addRecord:string, notify:string):string{
185186
return `
186187
if (${pipe} === ${UTIL}.unitialized()) {
187-
${pipe} = ${PIPE_REGISTRY_ACCESSOR}.get('${pipeType}', ${context});
188+
${pipe} = ${PIPE_REGISTRY_ACCESSOR}.get('${pipeType}', ${context}, ${bindingPropagationConfig});
188189
} else if (!${pipe}.supports(${context})) {
189190
${pipe}.onDestroy();
190-
${pipe} = ${PIPE_REGISTRY_ACCESSOR}.get('${pipeType}', ${context});
191+
${pipe} = ${PIPE_REGISTRY_ACCESSOR}.get('${pipeType}', ${context}, ${bindingPropagationConfig});
191192
}
192193
193194
${CHANGE_LOCAL} = ${pipe}.transform(${context});
@@ -293,20 +294,20 @@ export class ChangeDetectorJITGenerator {
293294

294295
genHydrate():string {
295296
return hydrateTemplate(this.typeName, this.genFieldDefinitions(),
296-
pipeOnDestroyTemplate(this.getnonNullPipeNames()));
297+
pipeOnDestroyTemplate(this.getNonNullPipeNames()));
297298
}
298299

299300
genFieldDefinitions() {
300301
var fields = [];
301302
fields = fields.concat(this.fieldNames);
302-
fields = fields.concat(this.getnonNullPipeNames());
303+
fields = fields.concat(this.getNonNullPipeNames());
303304
return fieldDefinitionsTemplate(fields);
304305
}
305306

306-
getnonNullPipeNames():List<String> {
307+
getNonNullPipeNames():List<String> {
307308
var pipes = [];
308309
this.records.forEach((r) => {
309-
if (r.mode === RECORD_TYPE_PIPE) {
310+
if (r.mode === RECORD_TYPE_PIPE || r.mode === RECORD_TYPE_BINDING_PIPE) {
310311
pipes.push(this.pipeNames[r.selfIndex]);
311312
}
312313
});
@@ -332,7 +333,7 @@ export class ChangeDetectorJITGenerator {
332333
}
333334

334335
genRecord(r:ProtoRecord):string {
335-
if (r.mode === RECORD_TYPE_PIPE) {
336+
if (r.mode === RECORD_TYPE_PIPE || r.mode === RECORD_TYPE_BINDING_PIPE) {
336337
return this.genPipeCheck (r);
337338
} else {
338339
return this.genReferenceCheck(r);
@@ -345,11 +346,12 @@ export class ChangeDetectorJITGenerator {
345346
var newValue = this.localNames[r.selfIndex];
346347
var oldValue = this.fieldNames[r.selfIndex];
347348
var change = this.changeNames[r.selfIndex];
349+
var bpc = r.mode === RECORD_TYPE_BINDING_PIPE ? "this.bindingPropagationConfig" : "null";
348350

349351
var addRecord = addSimpleChangeRecordTemplate(r.selfIndex - 1, oldValue, newValue);
350352
var notify = this.genNotify(r);
351353

352-
return pipeCheckTemplate(context, pipe, r.name, newValue, change, addRecord, notify);
354+
return pipeCheckTemplate(context, bpc, pipe, r.name, newValue, change, addRecord, notify);
353355
}
354356

355357
genReferenceCheck(r:ProtoRecord):string {

modules/angular2/src/change_detection/dynamic_change_detector.js

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import {List, ListWrapper, MapWrapper, StringMapWrapper} from 'angular2/src/faca
33

44
import {AbstractChangeDetector} from './abstract_change_detector';
55
import {PipeRegistry} from './pipes/pipe_registry';
6-
import {ChangeDetectionUtil, SimpleChange, uninitialized} from './change_detection_util';
6+
import {ChangeDetectionUtil, uninitialized} from './change_detection_util';
77

88

99
import {
@@ -17,6 +17,7 @@ import {
1717
RECORD_TYPE_PRIMITIVE_OP,
1818
RECORD_TYPE_KEYED_ACCESS,
1919
RECORD_TYPE_PIPE,
20+
RECORD_TYPE_BINDING_PIPE,
2021
RECORD_TYPE_INTERPOLATE
2122
} from './proto_record';
2223

@@ -103,7 +104,7 @@ export class DynamicChangeDetector extends AbstractChangeDetector {
103104

104105
_check(proto:ProtoRecord) {
105106
try {
106-
if (proto.mode == RECORD_TYPE_PIPE) {
107+
if (proto.mode === RECORD_TYPE_PIPE || proto.mode === RECORD_TYPE_BINDING_PIPE) {
107108
return this._pipeCheck(proto);
108109
} else {
109110
return this._referenceCheck(proto);
@@ -202,7 +203,14 @@ export class DynamicChangeDetector extends AbstractChangeDetector {
202203
if (isPresent(storedPipe)) {
203204
storedPipe.onDestroy();
204205
}
205-
var pipe = this.pipeRegistry.get(proto.name, context);
206+
207+
// Currently, only pipes that used in bindings in the template get
208+
// the bindingPropagationConfig of the encompassing component.
209+
//
210+
// In the future, pipes declared in the bind configuration should
211+
// be able to access the bindingPropagationConfig of that component.
212+
var bpc = proto.mode === RECORD_TYPE_BINDING_PIPE ? this.bindingPropagationConfig : null;
213+
var pipe = this.pipeRegistry.get(proto.name, context, bpc);
206214
this._writePipe(proto, pipe);
207215
return pipe;
208216
}

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -168,11 +168,13 @@ export class Pipe extends AST {
168168
exp:AST;
169169
name:string;
170170
args:List<AST>;
171-
constructor(exp:AST, name:string, args:List) {
171+
inBinding:boolean;
172+
constructor(exp:AST, name:string, args:List, inBinding:boolean) {
172173
super();
173174
this.exp = exp;
174175
this.name = name;
175176
this.args = args;
177+
this.inBinding = inBinding;
176178
}
177179

178180
visit(visitor) {

modules/angular2/src/change_detection/parser/parser.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ export class Parser {
5858
if (ListWrapper.isEmpty(pipes)) return bindingAst;
5959

6060
var res = ListWrapper.reduce(pipes,
61-
(result, currentPipeName) => new Pipe(result, currentPipeName, []),
61+
(result, currentPipeName) => new Pipe(result, currentPipeName, [], false),
6262
bindingAst.ast);
6363
return new ASTWithSource(res, bindingAst.source, bindingAst.location);
6464
}
@@ -220,7 +220,7 @@ class _ParseAST {
220220
while (this.optionalCharacter($COLON)) {
221221
ListWrapper.push(args, this.parseExpression());
222222
}
223-
result = new Pipe(result, name, args);
223+
result = new Pipe(result, name, args, true);
224224
}
225225
return result;
226226
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ export class IterableChangesFactory {
2121
return IterableChanges.supportsObj(obj);
2222
}
2323

24-
create():Pipe {
24+
create(bpc):Pipe {
2525
return new IterableChanges();
2626
}
2727
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ export class KeyValueChangesFactory {
88
return KeyValueChanges.supportsObj(obj);
99
}
1010

11-
create():Pipe {
11+
create(bpc):Pipe {
1212
return new KeyValueChanges();
1313
}
1414
}

0 commit comments

Comments
 (0)