refactor(pipes): rename PipeRegistry to Pipes

BREAKING CHANGE:
    This change renames all instances of PipeRegistry to Pipes.
    As part of this change, the former "defaultPipes" export is
    now a Pipes instance, instead of a map. The map that was previously
    called "defaultPipes" no longer exists, but may be accessed via
    defaultPipes.config.
This commit is contained in:
Jeff Cross
2015-07-09 10:34:51 -07:00
parent 8b3efdf229
commit 9a70f84e60
20 changed files with 90 additions and 104 deletions

View File

@ -2,7 +2,7 @@ import {JitProtoChangeDetector} from './jit_proto_change_detector';
import {PregenProtoChangeDetector} from './pregen_proto_change_detector';
import {DynamicProtoChangeDetector} from './proto_change_detector';
import {PipeFactory, Pipe} from './pipes/pipe';
import {PipeRegistry} from './pipes/pipes';
import {Pipes} from './pipes/pipes';
import {IterableChangesFactory} from './pipes/iterable_changes';
import {KeyValueChangesFactory} from './pipes/keyvalue_changes';
import {ObservablePipeFactory} from './pipes/observable_pipe';
@ -111,7 +111,7 @@ export const date: List<PipeFactory> =
CONST_EXPR([CONST_EXPR(new DatePipe()), CONST_EXPR(new NullPipeFactory())]);
export const defaultPipes = CONST_EXPR({
export const defaultPipes: Pipes = CONST_EXPR(new Pipes({
"iterableDiff": iterableDiff,
"keyValDiff": keyValDiff,
"async": async,
@ -123,11 +123,11 @@ export const defaultPipes = CONST_EXPR({
"percent": percent,
"currency": currency,
"date": date
});
}));
/**
* Map from {@link ChangeDetectorDefinition#id} to a factory method which takes a
* {@link PipeRegistry} and a {@link ChangeDetectorDefinition} and generates a
* {@link Pipes} and a {@link ChangeDetectorDefinition} and generates a
* {@link ProtoChangeDetector} associated with the definition.
*/
// TODO(kegluneq): Use PregenProtoChangeDetectorFactory rather than Function once possible in
@ -198,5 +198,3 @@ export class JitChangeDetection extends ChangeDetection {
return new JitProtoChangeDetector(definition);
}
}
export const defaultPipeRegistry: PipeRegistry = CONST_EXPR(new PipeRegistry(defaultPipes));

View File

@ -20,7 +20,7 @@ import {ProtoRecord, RecordType} from './proto_record';
var ABSTRACT_CHANGE_DETECTOR = "AbstractChangeDetector";
var UTIL = "ChangeDetectionUtil";
var DISPATCHER_ACCESSOR = "this.dispatcher";
var PIPE_REGISTRY_ACCESSOR = "this.pipeRegistry";
var PIPES_ACCESSOR = "this.pipes";
var PROTOS_ACCESSOR = "this.protos";
var DIRECTIVES_ACCESSOR = "this.directiveRecords";
var CONTEXT_ACCESSOR = "this.context";
@ -74,7 +74,7 @@ export class ChangeDetectorJITGenerator {
${DIRECTIVES_ACCESSOR} = directiveRecords;
${LOCALS_ACCESSOR} = null;
${CURRENT_PROTO} = null;
${PIPE_REGISTRY_ACCESSOR} = null;
${PIPES_ACCESSOR} = null;
${ALREADY_CHECKED_ACCESSOR} = false;
${this._genFieldDefinitions()}
}
@ -111,13 +111,13 @@ export class ChangeDetectorJITGenerator {
${this._genCallOnAllChangesDoneBody()}
}
${typeName}.prototype.hydrate = function(context, locals, directives, pipeRegistry) {
${typeName}.prototype.hydrate = function(context, locals, directives, pipes) {
${MODE_ACCESSOR} = "${ChangeDetectionUtil.changeDetectionMode(this.changeDetectionStrategy)}";
${CONTEXT_ACCESSOR} = context;
${LOCALS_ACCESSOR} = locals;
${this._genHydrateDirectives()}
${this._genHydrateDetectors()}
${PIPE_REGISTRY_ACCESSOR} = pipeRegistry;
${PIPES_ACCESSOR} = pipes;
${ALREADY_CHECKED_ACCESSOR} = false;
}
@ -125,7 +125,7 @@ export class ChangeDetectorJITGenerator {
${this._genPipeOnDestroy()}
${this._genFieldDefinitions()}
${LOCALS_ACCESSOR} = null;
${PIPE_REGISTRY_ACCESSOR} = null;
${PIPES_ACCESSOR} = null;
}
${typeName}.prototype.hydrated = function() {
@ -267,10 +267,10 @@ export class ChangeDetectorJITGenerator {
return `
${CURRENT_PROTO} = ${PROTOS_ACCESSOR}[${protoIndex}];
if (${pipe} === ${UTIL}.uninitialized()) {
${pipe} = ${PIPE_REGISTRY_ACCESSOR}.get('${pipeType}', ${context}, ${cdRef});
${pipe} = ${PIPES_ACCESSOR}.get('${pipeType}', ${context}, ${cdRef});
} else if (!${pipe}.supports(${context})) {
${pipe}.onDestroy();
${pipe} = ${PIPE_REGISTRY_ACCESSOR}.get('${pipeType}', ${context}, ${cdRef});
${pipe} = ${PIPES_ACCESSOR}.get('${pipeType}', ${context}, ${cdRef});
}
${newValue} = ${pipe}.transform(${context}, [${argString}]);

View File

@ -4,7 +4,7 @@ import {Locals} from 'angular2/src/change_detection/parser/locals';
import {AbstractChangeDetector} from './abstract_change_detector';
import {BindingRecord} from './binding_record';
import {PipeRegistry} from './pipes/pipes';
import {Pipes} from './pipes/pipes';
import {ChangeDetectionUtil, SimpleChange, uninitialized} from './change_detection_util';
@ -14,34 +14,34 @@ export class DynamicChangeDetector extends AbstractChangeDetector {
locals: Locals = null;
values: List<any>;
changes: List<any>;
pipes: List<any>;
localPipes: List<any>;
prevContexts: List<any>;
directives: any = null;
alreadyChecked: boolean = false;
private pipeRegistry: PipeRegistry = null;
private pipes: Pipes = null;
constructor(id: string, private changeControlStrategy: string, private dispatcher: any,
private protos: List<ProtoRecord>, private directiveRecords: List<any>) {
super(id);
this.values = ListWrapper.createFixedSize(protos.length + 1);
this.pipes = ListWrapper.createFixedSize(protos.length + 1);
this.localPipes = ListWrapper.createFixedSize(protos.length + 1);
this.prevContexts = ListWrapper.createFixedSize(protos.length + 1);
this.changes = ListWrapper.createFixedSize(protos.length + 1);
this.values[0] = null;
ListWrapper.fill(this.values, uninitialized, 1);
ListWrapper.fill(this.pipes, null);
ListWrapper.fill(this.localPipes, null);
ListWrapper.fill(this.prevContexts, uninitialized);
ListWrapper.fill(this.changes, false);
}
hydrate(context: any, locals: Locals, directives: any, pipeRegistry: PipeRegistry): void {
hydrate(context: any, locals: Locals, directives: any, pipes: Pipes): void {
this.mode = ChangeDetectionUtil.changeDetectionMode(this.changeControlStrategy);
this.values[0] = context;
this.locals = locals;
this.directives = directives;
this.alreadyChecked = false;
this.pipeRegistry = pipeRegistry;
this.pipes = pipes;
}
dehydrate() {
@ -49,16 +49,16 @@ export class DynamicChangeDetector extends AbstractChangeDetector {
this.values[0] = null;
ListWrapper.fill(this.values, uninitialized, 1);
ListWrapper.fill(this.changes, false);
ListWrapper.fill(this.pipes, null);
ListWrapper.fill(this.localPipes, null);
ListWrapper.fill(this.prevContexts, uninitialized);
this.locals = null;
this.pipeRegistry = null;
this.pipes = null;
}
_destroyPipes() {
for (var i = 0; i < this.pipes.length; ++i) {
if (isPresent(this.pipes[i])) {
this.pipes[i].onDestroy();
for (var i = 0; i < this.localPipes.length; ++i) {
if (isPresent(this.localPipes[i])) {
this.localPipes[i].onDestroy();
}
}
}
@ -270,7 +270,7 @@ export class DynamicChangeDetector extends AbstractChangeDetector {
if (isPresent(storedPipe)) {
storedPipe.onDestroy();
}
var pipe = this.pipeRegistry.get(proto.name, context, this.ref);
var pipe = this.pipes.get(proto.name, context, this.ref);
this._writePipe(proto, pipe);
return pipe;
}
@ -289,9 +289,9 @@ export class DynamicChangeDetector extends AbstractChangeDetector {
_writeSelf(proto: ProtoRecord, value) { this.values[proto.selfIndex] = value; }
_readPipe(proto: ProtoRecord) { return this.pipes[proto.selfIndex]; }
_readPipe(proto: ProtoRecord) { return this.localPipes[proto.selfIndex]; }
_writePipe(proto: ProtoRecord, value) { this.pipes[proto.selfIndex] = value; }
_writePipe(proto: ProtoRecord, value) { this.localPipes[proto.selfIndex] = value; }
_setChanged(proto: ProtoRecord, value: boolean) { this.changes[proto.selfIndex] = value; }

View File

@ -51,7 +51,7 @@ export interface ChangeDetector {
removeChild(cd: ChangeDetector): void;
removeShadowDomChild(cd: ChangeDetector): void;
remove(): void;
hydrate(context: any, locals: Locals, directives: any, pipeRegistry: any): void;
hydrate(context: any, locals: Locals, directives: any, pipes: any): void;
dehydrate(): void;
markPathToRootAsCheckOnce(): void;

View File

@ -6,7 +6,7 @@ import {ChangeDetectorRef} from '../change_detector_ref';
@Injectable()
@CONST()
export class PipeRegistry {
export class Pipes {
constructor(public config) {}
get(type: string, obj, cdRef?: ChangeDetectorRef, existingPipe?: Pipe): Pipe {

View File

@ -16,7 +16,7 @@ export 'package:angular2/src/change_detection/directive_record.dart'
export 'package:angular2/src/change_detection/interfaces.dart'
show ChangeDetector, ChangeDetectorDefinition, ProtoChangeDetector;
export 'package:angular2/src/change_detection/pipes/pipes.dart'
show PipeRegistry;
show Pipes;
export 'package:angular2/src/change_detection/proto_record.dart'
show ProtoRecord;
export 'package:angular2/src/change_detection/change_detection_util.dart'