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

@ -14,14 +14,13 @@ export {
ChangeDetectorRef, ChangeDetectorRef,
PipeRegistry, Pipes,
WrappedValue, WrappedValue,
Pipe, Pipe,
PipeFactory, PipeFactory,
NullPipe, NullPipe,
NullPipeFactory, NullPipeFactory,
defaultPipes, defaultPipes,
defaultPipeRegistry,
BasePipe, BasePipe,
Locals Locals

View File

@ -43,7 +43,7 @@ export {BindingRecord} from './src/change_detection/binding_record';
export {DirectiveIndex, DirectiveRecord} from './src/change_detection/directive_record'; export {DirectiveIndex, DirectiveRecord} from './src/change_detection/directive_record';
export {DynamicChangeDetector} from './src/change_detection/dynamic_change_detector'; export {DynamicChangeDetector} from './src/change_detection/dynamic_change_detector';
export {ChangeDetectorRef} from './src/change_detection/change_detector_ref'; export {ChangeDetectorRef} from './src/change_detection/change_detector_ref';
export {PipeRegistry} from './src/change_detection/pipes/pipes'; export {Pipes} from './src/change_detection/pipes/pipes';
export {uninitialized} from './src/change_detection/change_detection_util'; export {uninitialized} from './src/change_detection/change_detection_util';
export {WrappedValue, Pipe, PipeFactory, BasePipe} from './src/change_detection/pipes/pipe'; export {WrappedValue, Pipe, PipeFactory, BasePipe} from './src/change_detection/pipes/pipe';
export {NullPipe, NullPipeFactory} from './src/change_detection/pipes/null_pipe'; export {NullPipe, NullPipeFactory} from './src/change_detection/pipes/null_pipe';
@ -52,6 +52,5 @@ export {
DynamicChangeDetection, DynamicChangeDetection,
JitChangeDetection, JitChangeDetection,
PreGeneratedChangeDetection, PreGeneratedChangeDetection,
preGeneratedProtoDetectors, preGeneratedProtoDetectors
defaultPipeRegistry
} from './src/change_detection/change_detection'; } from './src/change_detection/change_detection';

View File

@ -2,7 +2,7 @@ import {JitProtoChangeDetector} from './jit_proto_change_detector';
import {PregenProtoChangeDetector} from './pregen_proto_change_detector'; import {PregenProtoChangeDetector} from './pregen_proto_change_detector';
import {DynamicProtoChangeDetector} from './proto_change_detector'; import {DynamicProtoChangeDetector} from './proto_change_detector';
import {PipeFactory, Pipe} from './pipes/pipe'; import {PipeFactory, Pipe} from './pipes/pipe';
import {PipeRegistry} from './pipes/pipes'; import {Pipes} from './pipes/pipes';
import {IterableChangesFactory} from './pipes/iterable_changes'; import {IterableChangesFactory} from './pipes/iterable_changes';
import {KeyValueChangesFactory} from './pipes/keyvalue_changes'; import {KeyValueChangesFactory} from './pipes/keyvalue_changes';
import {ObservablePipeFactory} from './pipes/observable_pipe'; 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())]); 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, "iterableDiff": iterableDiff,
"keyValDiff": keyValDiff, "keyValDiff": keyValDiff,
"async": async, "async": async,
@ -123,11 +123,11 @@ export const defaultPipes = CONST_EXPR({
"percent": percent, "percent": percent,
"currency": currency, "currency": currency,
"date": date "date": date
}); }));
/** /**
* Map from {@link ChangeDetectorDefinition#id} to a factory method which takes a * 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. * {@link ProtoChangeDetector} associated with the definition.
*/ */
// TODO(kegluneq): Use PregenProtoChangeDetectorFactory rather than Function once possible in // TODO(kegluneq): Use PregenProtoChangeDetectorFactory rather than Function once possible in
@ -198,5 +198,3 @@ export class JitChangeDetection extends ChangeDetection {
return new JitProtoChangeDetector(definition); 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 ABSTRACT_CHANGE_DETECTOR = "AbstractChangeDetector";
var UTIL = "ChangeDetectionUtil"; var UTIL = "ChangeDetectionUtil";
var DISPATCHER_ACCESSOR = "this.dispatcher"; var DISPATCHER_ACCESSOR = "this.dispatcher";
var PIPE_REGISTRY_ACCESSOR = "this.pipeRegistry"; var PIPES_ACCESSOR = "this.pipes";
var PROTOS_ACCESSOR = "this.protos"; var PROTOS_ACCESSOR = "this.protos";
var DIRECTIVES_ACCESSOR = "this.directiveRecords"; var DIRECTIVES_ACCESSOR = "this.directiveRecords";
var CONTEXT_ACCESSOR = "this.context"; var CONTEXT_ACCESSOR = "this.context";
@ -74,7 +74,7 @@ export class ChangeDetectorJITGenerator {
${DIRECTIVES_ACCESSOR} = directiveRecords; ${DIRECTIVES_ACCESSOR} = directiveRecords;
${LOCALS_ACCESSOR} = null; ${LOCALS_ACCESSOR} = null;
${CURRENT_PROTO} = null; ${CURRENT_PROTO} = null;
${PIPE_REGISTRY_ACCESSOR} = null; ${PIPES_ACCESSOR} = null;
${ALREADY_CHECKED_ACCESSOR} = false; ${ALREADY_CHECKED_ACCESSOR} = false;
${this._genFieldDefinitions()} ${this._genFieldDefinitions()}
} }
@ -111,13 +111,13 @@ export class ChangeDetectorJITGenerator {
${this._genCallOnAllChangesDoneBody()} ${this._genCallOnAllChangesDoneBody()}
} }
${typeName}.prototype.hydrate = function(context, locals, directives, pipeRegistry) { ${typeName}.prototype.hydrate = function(context, locals, directives, pipes) {
${MODE_ACCESSOR} = "${ChangeDetectionUtil.changeDetectionMode(this.changeDetectionStrategy)}"; ${MODE_ACCESSOR} = "${ChangeDetectionUtil.changeDetectionMode(this.changeDetectionStrategy)}";
${CONTEXT_ACCESSOR} = context; ${CONTEXT_ACCESSOR} = context;
${LOCALS_ACCESSOR} = locals; ${LOCALS_ACCESSOR} = locals;
${this._genHydrateDirectives()} ${this._genHydrateDirectives()}
${this._genHydrateDetectors()} ${this._genHydrateDetectors()}
${PIPE_REGISTRY_ACCESSOR} = pipeRegistry; ${PIPES_ACCESSOR} = pipes;
${ALREADY_CHECKED_ACCESSOR} = false; ${ALREADY_CHECKED_ACCESSOR} = false;
} }
@ -125,7 +125,7 @@ export class ChangeDetectorJITGenerator {
${this._genPipeOnDestroy()} ${this._genPipeOnDestroy()}
${this._genFieldDefinitions()} ${this._genFieldDefinitions()}
${LOCALS_ACCESSOR} = null; ${LOCALS_ACCESSOR} = null;
${PIPE_REGISTRY_ACCESSOR} = null; ${PIPES_ACCESSOR} = null;
} }
${typeName}.prototype.hydrated = function() { ${typeName}.prototype.hydrated = function() {
@ -267,10 +267,10 @@ export class ChangeDetectorJITGenerator {
return ` return `
${CURRENT_PROTO} = ${PROTOS_ACCESSOR}[${protoIndex}]; ${CURRENT_PROTO} = ${PROTOS_ACCESSOR}[${protoIndex}];
if (${pipe} === ${UTIL}.uninitialized()) { if (${pipe} === ${UTIL}.uninitialized()) {
${pipe} = ${PIPE_REGISTRY_ACCESSOR}.get('${pipeType}', ${context}, ${cdRef}); ${pipe} = ${PIPES_ACCESSOR}.get('${pipeType}', ${context}, ${cdRef});
} else if (!${pipe}.supports(${context})) { } else if (!${pipe}.supports(${context})) {
${pipe}.onDestroy(); ${pipe}.onDestroy();
${pipe} = ${PIPE_REGISTRY_ACCESSOR}.get('${pipeType}', ${context}, ${cdRef}); ${pipe} = ${PIPES_ACCESSOR}.get('${pipeType}', ${context}, ${cdRef});
} }
${newValue} = ${pipe}.transform(${context}, [${argString}]); ${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 {AbstractChangeDetector} from './abstract_change_detector';
import {BindingRecord} from './binding_record'; import {BindingRecord} from './binding_record';
import {PipeRegistry} from './pipes/pipes'; import {Pipes} from './pipes/pipes';
import {ChangeDetectionUtil, SimpleChange, uninitialized} from './change_detection_util'; import {ChangeDetectionUtil, SimpleChange, uninitialized} from './change_detection_util';
@ -14,34 +14,34 @@ export class DynamicChangeDetector extends AbstractChangeDetector {
locals: Locals = null; locals: Locals = null;
values: List<any>; values: List<any>;
changes: List<any>; changes: List<any>;
pipes: List<any>; localPipes: List<any>;
prevContexts: List<any>; prevContexts: List<any>;
directives: any = null; directives: any = null;
alreadyChecked: boolean = false; alreadyChecked: boolean = false;
private pipeRegistry: PipeRegistry = null; private pipes: Pipes = null;
constructor(id: string, private changeControlStrategy: string, private dispatcher: any, constructor(id: string, private changeControlStrategy: string, private dispatcher: any,
private protos: List<ProtoRecord>, private directiveRecords: List<any>) { private protos: List<ProtoRecord>, private directiveRecords: List<any>) {
super(id); super(id);
this.values = ListWrapper.createFixedSize(protos.length + 1); 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.prevContexts = ListWrapper.createFixedSize(protos.length + 1);
this.changes = ListWrapper.createFixedSize(protos.length + 1); this.changes = ListWrapper.createFixedSize(protos.length + 1);
this.values[0] = null; this.values[0] = null;
ListWrapper.fill(this.values, uninitialized, 1); ListWrapper.fill(this.values, uninitialized, 1);
ListWrapper.fill(this.pipes, null); ListWrapper.fill(this.localPipes, null);
ListWrapper.fill(this.prevContexts, uninitialized); ListWrapper.fill(this.prevContexts, uninitialized);
ListWrapper.fill(this.changes, false); 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.mode = ChangeDetectionUtil.changeDetectionMode(this.changeControlStrategy);
this.values[0] = context; this.values[0] = context;
this.locals = locals; this.locals = locals;
this.directives = directives; this.directives = directives;
this.alreadyChecked = false; this.alreadyChecked = false;
this.pipeRegistry = pipeRegistry; this.pipes = pipes;
} }
dehydrate() { dehydrate() {
@ -49,16 +49,16 @@ export class DynamicChangeDetector extends AbstractChangeDetector {
this.values[0] = null; this.values[0] = null;
ListWrapper.fill(this.values, uninitialized, 1); ListWrapper.fill(this.values, uninitialized, 1);
ListWrapper.fill(this.changes, false); ListWrapper.fill(this.changes, false);
ListWrapper.fill(this.pipes, null); ListWrapper.fill(this.localPipes, null);
ListWrapper.fill(this.prevContexts, uninitialized); ListWrapper.fill(this.prevContexts, uninitialized);
this.locals = null; this.locals = null;
this.pipeRegistry = null; this.pipes = null;
} }
_destroyPipes() { _destroyPipes() {
for (var i = 0; i < this.pipes.length; ++i) { for (var i = 0; i < this.localPipes.length; ++i) {
if (isPresent(this.pipes[i])) { if (isPresent(this.localPipes[i])) {
this.pipes[i].onDestroy(); this.localPipes[i].onDestroy();
} }
} }
} }
@ -270,7 +270,7 @@ export class DynamicChangeDetector extends AbstractChangeDetector {
if (isPresent(storedPipe)) { if (isPresent(storedPipe)) {
storedPipe.onDestroy(); 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); this._writePipe(proto, pipe);
return pipe; return pipe;
} }
@ -289,9 +289,9 @@ export class DynamicChangeDetector extends AbstractChangeDetector {
_writeSelf(proto: ProtoRecord, value) { this.values[proto.selfIndex] = value; } _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; } _setChanged(proto: ProtoRecord, value: boolean) { this.changes[proto.selfIndex] = value; }

View File

@ -51,7 +51,7 @@ export interface ChangeDetector {
removeChild(cd: ChangeDetector): void; removeChild(cd: ChangeDetector): void;
removeShadowDomChild(cd: ChangeDetector): void; removeShadowDomChild(cd: ChangeDetector): void;
remove(): 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; dehydrate(): void;
markPathToRootAsCheckOnce(): void; markPathToRootAsCheckOnce(): void;

View File

@ -6,7 +6,7 @@ import {ChangeDetectorRef} from '../change_detector_ref';
@Injectable() @Injectable()
@CONST() @CONST()
export class PipeRegistry { export class Pipes {
constructor(public config) {} constructor(public config) {}
get(type: string, obj, cdRef?: ChangeDetectorRef, existingPipe?: Pipe): Pipe { 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' export 'package:angular2/src/change_detection/interfaces.dart'
show ChangeDetector, ChangeDetectorDefinition, ProtoChangeDetector; show ChangeDetector, ChangeDetectorDefinition, ProtoChangeDetector;
export 'package:angular2/src/change_detection/pipes/pipes.dart' export 'package:angular2/src/change_detection/pipes/pipes.dart'
show PipeRegistry; show Pipes;
export 'package:angular2/src/change_detection/proto_record.dart' export 'package:angular2/src/change_detection/proto_record.dart'
show ProtoRecord; show ProtoRecord;
export 'package:angular2/src/change_detection/change_detection_util.dart' export 'package:angular2/src/change_detection/change_detection_util.dart'

View File

@ -20,8 +20,8 @@ import {
DynamicChangeDetection, DynamicChangeDetection,
JitChangeDetection, JitChangeDetection,
PreGeneratedChangeDetection, PreGeneratedChangeDetection,
PipeRegistry, Pipes,
defaultPipeRegistry defaultPipes
} from 'angular2/change_detection'; } from 'angular2/change_detection';
import {ExceptionHandler} from './exception_handler'; import {ExceptionHandler} from './exception_handler';
import {ViewLoader} from 'angular2/src/render/dom/compiler/view_loader'; import {ViewLoader} from 'angular2/src/render/dom/compiler/view_loader';
@ -118,7 +118,7 @@ function _injectorBindings(appComponentType): List<Type | Binding | List<any>> {
Compiler, Compiler,
CompilerCache, CompilerCache,
ViewResolver, ViewResolver,
bind(PipeRegistry).toValue(defaultPipeRegistry), bind(Pipes).toValue(defaultPipes),
bind(ChangeDetection).toClass(bestChangeDetection), bind(ChangeDetection).toClass(bestChangeDetection),
ViewLoader, ViewLoader,
DirectiveResolver, DirectiveResolver,

View File

@ -52,7 +52,7 @@ import {
onAllChangesDone onAllChangesDone
} from 'angular2/src/core/annotations_impl/annotations'; } from 'angular2/src/core/annotations_impl/annotations';
import {hasLifecycleHook} from './directive_lifecycle_reflector'; import {hasLifecycleHook} from './directive_lifecycle_reflector';
import {ChangeDetector, ChangeDetectorRef, PipeRegistry} from 'angular2/change_detection'; import {ChangeDetector, ChangeDetectorRef, Pipes} from 'angular2/change_detection';
import {QueryList} from './query_list'; import {QueryList} from './query_list';
import {reflector} from 'angular2/src/reflection/reflection'; import {reflector} from 'angular2/src/reflection/reflection';
import {DirectiveMetadata} from 'angular2/src/render/api'; import {DirectiveMetadata} from 'angular2/src/render/api';
@ -65,7 +65,7 @@ export class StaticKeys {
viewContainerId: number; viewContainerId: number;
changeDetectorRefId: number; changeDetectorRefId: number;
elementRefId: number; elementRefId: number;
pipeRegistryKey: Key; pipesKey: Key;
constructor() { constructor() {
this.viewManagerId = Key.get(avmModule.AppViewManager).id; this.viewManagerId = Key.get(avmModule.AppViewManager).id;
@ -74,7 +74,7 @@ export class StaticKeys {
this.changeDetectorRefId = Key.get(ChangeDetectorRef).id; this.changeDetectorRefId = Key.get(ChangeDetectorRef).id;
this.elementRefId = Key.get(ElementRef).id; this.elementRefId = Key.get(ElementRef).id;
// not an id because the public API of injector works only with keys and tokens // not an id because the public API of injector works only with keys and tokens
this.pipeRegistryKey = Key.get(PipeRegistry); this.pipesKey = Key.get(Pipes);
} }
static instance(): StaticKeys { static instance(): StaticKeys {
@ -550,9 +550,9 @@ export class ElementInjector extends TreeNode<ElementInjector> implements Depend
injector.internalStrategy.hydrate(); injector.internalStrategy.hydrate();
} }
getPipeRegistry(): PipeRegistry { getPipes(): Pipes {
var pipeRegistryKey = StaticKeys.instance().pipeRegistryKey; var pipesKey = StaticKeys.instance().pipesKey;
return this._injector.getOptional(pipeRegistryKey); return this._injector.getOptional(pipesKey);
} }
hasVariableBinding(name: string): boolean { hasVariableBinding(name: string): boolean {

View File

@ -162,16 +162,15 @@ export class AppViewManagerUtils {
this._setUpHostActions(view, elementInjector, i); this._setUpHostActions(view, elementInjector, i);
} }
} }
var pipeRegistry = this._getPipeRegistry(imperativelyCreatedInjector, hostElementInjector); var pipes = this._getPipes(imperativelyCreatedInjector, hostElementInjector);
view.changeDetector.hydrate(view.context, view.locals, view, pipeRegistry); view.changeDetector.hydrate(view.context, view.locals, view, pipes);
} }
_getPipeRegistry(imperativelyCreatedInjector: Injector, _getPipes(imperativelyCreatedInjector: Injector, hostElementInjector: eli.ElementInjector) {
hostElementInjector: eli.ElementInjector) { var pipesKey = eli.StaticKeys.instance().pipesKey;
var pipeRegistryKey = eli.StaticKeys.instance().pipeRegistryKey;
if (isPresent(imperativelyCreatedInjector)) if (isPresent(imperativelyCreatedInjector))
return imperativelyCreatedInjector.getOptional(pipeRegistryKey); return imperativelyCreatedInjector.getOptional(pipesKey);
if (isPresent(hostElementInjector)) return hostElementInjector.getPipeRegistry(); if (isPresent(hostElementInjector)) return hostElementInjector.getPipes();
return null; return null;
} }

View File

@ -1,6 +1,6 @@
import {Directive, onCheck} from 'angular2/annotations'; import {Directive, onCheck} from 'angular2/annotations';
import {ElementRef} from 'angular2/core'; import {ElementRef} from 'angular2/core';
import {PipeRegistry} from 'angular2/src/change_detection/pipes/pipes'; import {Pipes} from 'angular2/src/change_detection/pipes/pipes';
import {Pipe} from 'angular2/src/change_detection/pipes/pipe'; import {Pipe} from 'angular2/src/change_detection/pipes/pipe';
import {Renderer} from 'angular2/src/render/api'; import {Renderer} from 'angular2/src/render/api';
import {KeyValueChanges} from 'angular2/src/change_detection/pipes/keyvalue_changes'; import {KeyValueChanges} from 'angular2/src/change_detection/pipes/keyvalue_changes';
@ -35,8 +35,7 @@ export class CSSClass {
_pipe: Pipe; _pipe: Pipe;
_rawClass; _rawClass;
constructor(private _pipeRegistry: PipeRegistry, private _ngEl: ElementRef, constructor(private _pipes: Pipes, private _ngEl: ElementRef, private _renderer: Renderer) {}
private _renderer: Renderer) {}
set rawClass(v) { set rawClass(v) {
this._cleanupClasses(this._rawClass); this._cleanupClasses(this._rawClass);
@ -46,7 +45,7 @@ export class CSSClass {
} }
this._rawClass = v; this._rawClass = v;
this._pipe = this._pipeRegistry.get(isListLikeIterable(v) ? 'iterableDiff' : 'keyValDiff', v); this._pipe = this._pipes.get(isListLikeIterable(v) ? 'iterableDiff' : 'keyValDiff', v);
} }
onCheck(): void { onCheck(): void {

View File

@ -1,12 +1,5 @@
import {Directive} from 'angular2/annotations'; import {Directive} from 'angular2/annotations';
import { import {ViewContainerRef, ViewRef, ProtoViewRef, Pipes, onCheck, Pipe} from 'angular2/angular2';
ViewContainerRef,
ViewRef,
ProtoViewRef,
PipeRegistry,
onCheck,
Pipe
} from 'angular2/angular2';
import {isPresent, isBlank} from 'angular2/src/facade/lang'; import {isPresent, isBlank} from 'angular2/src/facade/lang';
/** /**
@ -47,7 +40,7 @@ export class NgFor {
_pipe: Pipe; _pipe: Pipe;
constructor(private viewContainer: ViewContainerRef, private protoViewRef: ProtoViewRef, constructor(private viewContainer: ViewContainerRef, private protoViewRef: ProtoViewRef,
private pipes: PipeRegistry) {} private pipes: Pipes) {}
set ngForOf(value: any) { set ngForOf(value: any) {
this._ngForOf = value; this._ngForOf = value;

View File

@ -1,7 +1,7 @@
import {Directive, onCheck} from 'angular2/annotations'; import {Directive, onCheck} from 'angular2/annotations';
import {ElementRef} from 'angular2/core'; import {ElementRef} from 'angular2/core';
import {Pipe} from 'angular2/src/change_detection/pipes/pipe'; import {Pipe} from 'angular2/src/change_detection/pipes/pipe';
import {PipeRegistry} from 'angular2/src/change_detection/pipes/pipes'; import {Pipes} from 'angular2/src/change_detection/pipes/pipes';
import {KeyValueChanges} from 'angular2/src/change_detection/pipes/keyvalue_changes'; import {KeyValueChanges} from 'angular2/src/change_detection/pipes/keyvalue_changes';
import {isPresent, print} from 'angular2/src/facade/lang'; import {isPresent, print} from 'angular2/src/facade/lang';
import {Renderer} from 'angular2/src/render/api'; import {Renderer} from 'angular2/src/render/api';
@ -34,12 +34,11 @@ export class NgStyle {
_pipe: Pipe; _pipe: Pipe;
_rawStyle; _rawStyle;
constructor(private _pipeRegistry: PipeRegistry, private _ngEl: ElementRef, constructor(private _pipes: Pipes, private _ngEl: ElementRef, private _renderer: Renderer) {}
private _renderer: Renderer) {}
set rawStyle(v) { set rawStyle(v) {
this._rawStyle = v; this._rawStyle = v;
this._pipe = this._pipeRegistry.get('keyValDiff', this._rawStyle); this._pipe = this._pipes.get('keyValDiff', this._rawStyle);
} }
onCheck() { onCheck() {

View File

@ -7,8 +7,8 @@ import {
Lexer, Lexer,
ChangeDetection, ChangeDetection,
DynamicChangeDetection, DynamicChangeDetection,
PipeRegistry, Pipes,
defaultPipeRegistry defaultPipes
} from 'angular2/change_detection'; } from 'angular2/change_detection';
import {ExceptionHandler} from 'angular2/src/core/exception_handler'; import {ExceptionHandler} from 'angular2/src/core/exception_handler';
import {ViewLoader} from 'angular2/src/render/dom/compiler/view_loader'; import {ViewLoader} from 'angular2/src/render/dom/compiler/view_loader';
@ -101,7 +101,7 @@ function _getAppBindings() {
Compiler, Compiler,
CompilerCache, CompilerCache,
bind(ViewResolver).toClass(MockViewResolver), bind(ViewResolver).toClass(MockViewResolver),
bind(PipeRegistry).toValue(defaultPipeRegistry), bind(Pipes).toValue(defaultPipes),
bind(ChangeDetection).toClass(DynamicChangeDetection), bind(ChangeDetection).toClass(DynamicChangeDetection),
ViewLoader, ViewLoader,
DynamicComponentLoader, DynamicComponentLoader,

View File

@ -125,7 +125,7 @@ class _CodegenState {
buf.write('''\n buf.write('''\n
class $_changeDetectorTypeName extends $_BASE_CLASS { class $_changeDetectorTypeName extends $_BASE_CLASS {
final dynamic $_DISPATCHER_ACCESSOR; final dynamic $_DISPATCHER_ACCESSOR;
$_GEN_PREFIX.PipeRegistry $_PIPE_REGISTRY_ACCESSOR; $_GEN_PREFIX.Pipes $_PIPES_ACCESSOR;
final $_GEN_PREFIX.List<$_GEN_PREFIX.ProtoRecord> $_PROTOS_ACCESSOR; final $_GEN_PREFIX.List<$_GEN_PREFIX.ProtoRecord> $_PROTOS_ACCESSOR;
final $_GEN_PREFIX.List<$_GEN_PREFIX.DirectiveRecord> final $_GEN_PREFIX.List<$_GEN_PREFIX.DirectiveRecord>
$_DIRECTIVES_ACCESSOR; $_DIRECTIVES_ACCESSOR;
@ -172,14 +172,14 @@ class _CodegenState {
${_getCallOnAllChangesDoneBody()} ${_getCallOnAllChangesDoneBody()}
} }
void hydrate($_contextTypeName context, locals, directives, pipeRegistry) { void hydrate($_contextTypeName context, locals, directives, pipes) {
$_MODE_ACCESSOR = '$_changeDetectionMode'; $_MODE_ACCESSOR = '$_changeDetectionMode';
$_CONTEXT_ACCESSOR = context; $_CONTEXT_ACCESSOR = context;
$_LOCALS_ACCESSOR = locals; $_LOCALS_ACCESSOR = locals;
${_genHydrateDirectives()} ${_genHydrateDirectives()}
${_genHydrateDetectors()} ${_genHydrateDetectors()}
$_ALREADY_CHECKED_ACCESSOR = false; $_ALREADY_CHECKED_ACCESSOR = false;
$_PIPE_REGISTRY_ACCESSOR = pipeRegistry; $_PIPES_ACCESSOR = pipes;
} }
void dehydrate() { void dehydrate() {
@ -190,7 +190,7 @@ class _CodegenState {
: '$f = $_UTIL.uninitialized();'; : '$f = $_UTIL.uninitialized();';
}).join('')} }).join('')}
$_LOCALS_ACCESSOR = null; $_LOCALS_ACCESSOR = null;
$_PIPE_REGISTRY_ACCESSOR = null; $_PIPES_ACCESSOR = null;
} }
hydrated() => $_CONTEXT_ACCESSOR != null; hydrated() => $_CONTEXT_ACCESSOR != null;
@ -327,10 +327,10 @@ class _CodegenState {
return ''' return '''
$_CURRENT_PROTO = $_PROTOS_ACCESSOR[$protoIndex]; $_CURRENT_PROTO = $_PROTOS_ACCESSOR[$protoIndex];
if ($_IDENTICAL_CHECK_FN($pipe, $_UTIL.uninitialized())) { if ($_IDENTICAL_CHECK_FN($pipe, $_UTIL.uninitialized())) {
$pipe = $_PIPE_REGISTRY_ACCESSOR.get('$pipeType', $context, $cdRef); $pipe = $_PIPES_ACCESSOR.get('$pipeType', $context, $cdRef);
} else if (!$pipe.supports($context)) { } else if (!$pipe.supports($context)) {
$pipe.onDestroy(); $pipe.onDestroy();
$pipe = $_PIPE_REGISTRY_ACCESSOR.get('$pipeType', $context, $cdRef); $pipe = $_PIPES_ACCESSOR.get('$pipeType', $context, $cdRef);
} }
$newValue = $pipe.transform($context, [$argString]); $newValue = $pipe.transform($context, [$argString]);
@ -542,6 +542,6 @@ const _LOCALS_ACCESSOR = '_locals';
const _MODE_ACCESSOR = 'mode'; const _MODE_ACCESSOR = 'mode';
const _PREGEN_PROTO_CHANGE_DETECTOR_IMPORT = const _PREGEN_PROTO_CHANGE_DETECTOR_IMPORT =
'package:angular2/src/change_detection/pregen_proto_change_detector.dart'; 'package:angular2/src/change_detection/pregen_proto_change_detector.dart';
const _PIPE_REGISTRY_ACCESSOR = '_pipeRegistry'; const _PIPES_ACCESSOR = '_pipes';
const _PROTOS_ACCESSOR = '_protos'; const _PROTOS_ACCESSOR = '_protos';
const _UTIL = '$_GEN_PREFIX.ChangeDetectionUtil'; const _UTIL = '$_GEN_PREFIX.ChangeDetectionUtil';

View File

@ -29,7 +29,7 @@ import {
BindingRecord, BindingRecord,
DirectiveRecord, DirectiveRecord,
DirectiveIndex, DirectiveIndex,
PipeRegistry, Pipes,
Pipe, Pipe,
CHECK_ALWAYS, CHECK_ALWAYS,
CHECK_ONCE, CHECK_ONCE,
@ -324,7 +324,7 @@ export function main() {
describe('pipes', () => { describe('pipes', () => {
it('should pass a change record to the dispatcher', () => { it('should pass a change record to the dispatcher', () => {
var registry = new FakePipeRegistry('pipe', () => new CountingPipe()); var registry = new FakePipes('pipe', () => new CountingPipe());
var person = new Person('bob'); var person = new Person('bob');
var val = _createChangeDetector('name | pipe', person, registry); var val = _createChangeDetector('name | pipe', person, registry);
val.changeDetector.detectChanges(); val.changeDetector.detectChanges();
@ -332,7 +332,7 @@ export function main() {
}); });
it('should support arguments in pipes', () => { it('should support arguments in pipes', () => {
var registry = new FakePipeRegistry('pipe', () => new MultiArgPipe()); var registry = new FakePipes('pipe', () => new MultiArgPipe());
var address = new Address('two'); var address = new Address('two');
var person = new Person('value', address); var person = new Person('value', address);
var val = _createChangeDetector("name | pipe:'one':address.city", person, registry); var val = _createChangeDetector("name | pipe:'one':address.city", person, registry);
@ -749,7 +749,7 @@ export function main() {
it('should destroy all active pipes during dehyration', () => { it('should destroy all active pipes during dehyration', () => {
var pipe = new OncePipe(); var pipe = new OncePipe();
var registry = new FakePipeRegistry('pipe', () => pipe); var registry = new FakePipes('pipe', () => pipe);
var cd = _createChangeDetector('name | pipe', new Person('bob'), registry).changeDetector; var cd = _createChangeDetector('name | pipe', new Person('bob'), registry).changeDetector;
cd.detectChanges(); cd.detectChanges();
@ -775,7 +775,7 @@ export function main() {
describe('pipes', () => { describe('pipes', () => {
it('should support pipes', () => { it('should support pipes', () => {
var registry = new FakePipeRegistry('pipe', () => new CountingPipe()); var registry = new FakePipes('pipe', () => new CountingPipe());
var ctx = new Person('Megatron'); var ctx = new Person('Megatron');
var val = _createChangeDetector('name | pipe', ctx, registry); var val = _createChangeDetector('name | pipe', ctx, registry);
@ -791,7 +791,7 @@ export function main() {
}); });
it('should lookup pipes in the registry when the context is not supported', () => { it('should lookup pipes in the registry when the context is not supported', () => {
var registry = new FakePipeRegistry('pipe', () => new OncePipe()); var registry = new FakePipes('pipe', () => new OncePipe());
var ctx = new Person('Megatron'); var ctx = new Person('Megatron');
var cd = _createChangeDetector('name | pipe', ctx, registry).changeDetector; var cd = _createChangeDetector('name | pipe', ctx, registry).changeDetector;
@ -808,7 +808,7 @@ export function main() {
it('should invoke onDestroy on a pipe before switching to another one', () => { it('should invoke onDestroy on a pipe before switching to another one', () => {
var pipe = new OncePipe(); var pipe = new OncePipe();
var registry = new FakePipeRegistry('pipe', () => pipe); var registry = new FakePipes('pipe', () => pipe);
var ctx = new Person('Megatron'); var ctx = new Person('Megatron');
var cd = _createChangeDetector('name | pipe', ctx, registry).changeDetector; var cd = _createChangeDetector('name | pipe', ctx, registry).changeDetector;
@ -824,7 +824,7 @@ export function main() {
'of the encompassing component into a pipe', 'of the encompassing component into a pipe',
() => { () => {
var registry = new FakePipeRegistry('pipe', () => new IdentityPipe()); var registry = new FakePipes('pipe', () => new IdentityPipe());
var cd = var cd =
_createChangeDetector('name | pipe', new Person('bob'), registry).changeDetector; _createChangeDetector('name | pipe', new Person('bob'), registry).changeDetector;
@ -835,7 +835,7 @@ export function main() {
}); });
it('should do nothing when no change', () => { it('should do nothing when no change', () => {
var registry = new FakePipeRegistry('pipe', () => new IdentityPipe()); var registry = new FakePipes('pipe', () => new IdentityPipe());
var ctx = new Person('Megatron'); var ctx = new Person('Megatron');
var val = _createChangeDetector('name | pipe', ctx, registry); var val = _createChangeDetector('name | pipe', ctx, registry);
@ -851,7 +851,7 @@ export function main() {
}); });
it('should unwrap the wrapped value', () => { it('should unwrap the wrapped value', () => {
var registry = new FakePipeRegistry('pipe', () => new WrappedPipe()); var registry = new FakePipes('pipe', () => new WrappedPipe());
var ctx = new Person('Megatron'); var ctx = new Person('Megatron');
var val = _createChangeDetector('name | pipe', ctx, registry); var val = _createChangeDetector('name | pipe', ctx, registry);
@ -915,7 +915,7 @@ class MultiArgPipe implements Pipe {
onDestroy(): void {} onDestroy(): void {}
} }
class FakePipeRegistry extends PipeRegistry { class FakePipes extends Pipes {
numberOfLookups: number; numberOfLookups: number;
pipeType: string; pipeType: string;
factory: Function; factory: Function;

View File

@ -11,7 +11,7 @@ import {
SpyPipeFactory SpyPipeFactory
} from 'angular2/test_lib'; } from 'angular2/test_lib';
import {PipeRegistry} from 'angular2/src/change_detection/pipes/pipes'; import {Pipes} from 'angular2/src/change_detection/pipes/pipes';
export function main() { export function main() {
describe("pipe registry", () => { describe("pipe registry", () => {
@ -30,7 +30,7 @@ export function main() {
}); });
it("should return an existing pipe if it can support the passed in object", () => { it("should return an existing pipe if it can support the passed in object", () => {
var r = new PipeRegistry({"type": []}); var r = new Pipes({"type": []});
firstPipe.spy("supports").andReturn(true); firstPipe.spy("supports").andReturn(true);
@ -43,7 +43,7 @@ export function main() {
firstPipeFactory.spy("supports").andReturn(true); firstPipeFactory.spy("supports").andReturn(true);
firstPipeFactory.spy("create").andReturn(secondPipe); firstPipeFactory.spy("create").andReturn(secondPipe);
var r = new PipeRegistry({"type": [firstPipeFactory]}); var r = new Pipes({"type": [firstPipeFactory]});
expect(r.get("type", "some object", null, firstPipe)).toEqual(secondPipe); expect(r.get("type", "some object", null, firstPipe)).toEqual(secondPipe);
expect(firstPipe.spy("onDestroy")).toHaveBeenCalled(); expect(firstPipe.spy("onDestroy")).toHaveBeenCalled();
@ -56,19 +56,19 @@ export function main() {
secondPipeFactory.spy("supports").andReturn(true); secondPipeFactory.spy("supports").andReturn(true);
secondPipeFactory.spy("create").andReturn(secondPipe); secondPipeFactory.spy("create").andReturn(secondPipe);
var r = new PipeRegistry({"type": [firstPipeFactory, secondPipeFactory]}); var r = new Pipes({"type": [firstPipeFactory, secondPipeFactory]});
expect(r.get("type", "some object")).toBe(secondPipe); expect(r.get("type", "some object")).toBe(secondPipe);
}); });
it("should throw when no matching type", () => { it("should throw when no matching type", () => {
var r = new PipeRegistry({}); var r = new Pipes({});
expect(() => r.get("unknown", "some object")) expect(() => r.get("unknown", "some object"))
.toThrowError(`Cannot find 'unknown' pipe supporting object 'some object'`); .toThrowError(`Cannot find 'unknown' pipe supporting object 'some object'`);
}); });
it("should throw when no matching pipe", () => { it("should throw when no matching pipe", () => {
var r = new PipeRegistry({"type": []}); var r = new Pipes({"type": []});
expect(() => r.get("type", "some object")) expect(() => r.get("type", "some object"))
.toThrowError(`Cannot find 'type' pipe supporting object 'some object'`); .toThrowError(`Cannot find 'type' pipe supporting object 'some object'`);

View File

@ -48,8 +48,8 @@ import {
} from 'angular2/di'; } from 'angular2/di';
import { import {
PipeFactory, PipeFactory,
PipeRegistry, Pipes,
defaultPipeRegistry, defaultPipes,
ChangeDetection, ChangeDetection,
DynamicChangeDetection, DynamicChangeDetection,
Pipe, Pipe,
@ -1402,13 +1402,13 @@ class PushCmpWithRef {
} }
@Injectable() @Injectable()
class PipeRegistryWithDouble extends PipeRegistry { class PipesWithDouble extends Pipes {
constructor() { super({"double": [new DoublePipeFactory()]}); } constructor() { super({"double": [new DoublePipeFactory()]}); }
} }
@Component({ @Component({
selector: 'my-comp-with-pipes', selector: 'my-comp-with-pipes',
viewInjector: [new Binding(PipeRegistry, {toClass: PipeRegistryWithDouble})] viewInjector: [new Binding(Pipes, {toClass: PipesWithDouble})]
}) })
@View({directives: []}) @View({directives: []})
@Injectable() @Injectable()

View File

@ -27,7 +27,7 @@ void initReflector(reflector) {
} }
class _MyComponent_ChangeDetector0 extends _gen.AbstractChangeDetector { class _MyComponent_ChangeDetector0 extends _gen.AbstractChangeDetector {
final dynamic _dispatcher; final dynamic _dispatcher;
_gen.PipeRegistry _pipeRegistry; _gen.Pipes _pipes;
final _gen.List<_gen.ProtoRecord> _protos; final _gen.List<_gen.ProtoRecord> _protos;
final _gen.List<_gen.DirectiveRecord> _directiveRecords; final _gen.List<_gen.DirectiveRecord> _directiveRecords;
dynamic _locals = null; dynamic _locals = null;
@ -100,13 +100,13 @@ class _MyComponent_ChangeDetector0 extends _gen.AbstractChangeDetector {
_dispatcher.notifyOnAllChangesDone(); _dispatcher.notifyOnAllChangesDone();
} }
void hydrate(MyComponent context, locals, directives, pipeRegistry) { void hydrate(MyComponent context, locals, directives, pipes) {
mode = 'ALWAYS_CHECK'; mode = 'ALWAYS_CHECK';
_context = context; _context = context;
_locals = locals; _locals = locals;
_alreadyChecked = false; _alreadyChecked = false;
_pipeRegistry = pipeRegistry; _pipes = pipes;
} }
void dehydrate() { void dehydrate() {
@ -114,7 +114,7 @@ class _MyComponent_ChangeDetector0 extends _gen.AbstractChangeDetector {
_myNum0 = _gen.ChangeDetectionUtil.uninitialized(); _myNum0 = _gen.ChangeDetectionUtil.uninitialized();
_interpolate1 = _gen.ChangeDetectionUtil.uninitialized(); _interpolate1 = _gen.ChangeDetectionUtil.uninitialized();
_locals = null; _locals = null;
_pipeRegistry = null; _pipes = null;
} }
hydrated() => _context != null; hydrated() => _context != null;