Skip to content

Commit

Permalink
refactor(Pipes): rename PipeRegistry to Pipes
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
jeffbcross committed Jul 9, 2015
1 parent 245560e commit 669b0e4
Show file tree
Hide file tree
Showing 20 changed files with 90 additions and 104 deletions.
3 changes: 1 addition & 2 deletions modules/angular2/angular2.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export {
ON_PUSH,
DEFAULT,
ChangeDetectorRef,
PipeRegistry,
Pipes,
WrappedValue,
Pipe,
PipeFactory,
Expand All @@ -24,7 +24,6 @@ export {
JitChangeDetection,
PreGeneratedChangeDetection,
preGeneratedProtoDetectors,
defaultPipeRegistry,
DirectiveIndex,
BindingRecord,
ProtoChangeDetector,
Expand Down
5 changes: 2 additions & 3 deletions modules/angular2/change_detection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ export {BindingRecord} from './src/change_detection/binding_record';
export {DirectiveIndex, DirectiveRecord} from './src/change_detection/directive_record';
export {DynamicChangeDetector} from './src/change_detection/dynamic_change_detector';
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 {WrappedValue, Pipe, PipeFactory, BasePipe} from './src/change_detection/pipes/pipe';
export {NullPipe, NullPipeFactory} from './src/change_detection/pipes/null_pipe';
Expand All @@ -52,6 +52,5 @@ export {
DynamicChangeDetection,
JitChangeDetection,
PreGeneratedChangeDetection,
preGeneratedProtoDetectors,
defaultPipeRegistry
preGeneratedProtoDetectors
} from './src/change_detection/change_detection';
10 changes: 4 additions & 6 deletions modules/angular2/src/change_detection/change_detection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -76,19 +76,19 @@ export const json: List<PipeFactory> =
export const limitTo: List<PipeFactory> =
CONST_EXPR([CONST_EXPR(new LimitToPipeFactory()), CONST_EXPR(new NullPipeFactory())]);

export const defaultPipes = CONST_EXPR({
export const defaultPipes: Pipes = CONST_EXPR(new Pipes({
"iterableDiff": iterableDiff,
"keyValDiff": keyValDiff,
"async": async,
"uppercase": uppercase,
"lowercase": lowercase,
"json": json,
"limitTo": limitTo
});
}));

/**
* 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
Expand Down Expand Up @@ -159,5 +159,3 @@ export class JitChangeDetection extends ChangeDetection {
return new JitProtoChangeDetector(definition);
}
}

export const defaultPipeRegistry: PipeRegistry = CONST_EXPR(new PipeRegistry(defaultPipes));
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -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()}
}
Expand Down Expand Up @@ -111,21 +111,21 @@ 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;
}
${typeName}.prototype.dehydrate = function() {
${this._genPipeOnDestroy()}
${this._genFieldDefinitions()}
${LOCALS_ACCESSOR} = null;
${PIPE_REGISTRY_ACCESSOR} = null;
${PIPES_ACCESSOR} = null;
}
${typeName}.prototype.hydrated = function() {
Expand Down Expand Up @@ -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}]);
Expand Down
30 changes: 15 additions & 15 deletions modules/angular2/src/change_detection/dynamic_change_detector.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';


Expand All @@ -14,51 +14,51 @@ 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() {
this._destroyPipes();
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();
}
}
}
Expand Down Expand Up @@ -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;
}
Expand All @@ -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; }

Expand Down
2 changes: 1 addition & 1 deletion modules/angular2/src/change_detection/interfaces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
2 changes: 1 addition & 1 deletion modules/angular2/src/change_detection/pipes/pipes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
6 changes: 3 additions & 3 deletions modules/angular2/src/core/application.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ import {
DynamicChangeDetection,
JitChangeDetection,
PreGeneratedChangeDetection,
PipeRegistry,
defaultPipeRegistry
Pipes,
defaultPipes
} from 'angular2/change_detection';
import {ExceptionHandler} from './exception_handler';
import {ViewLoader} from 'angular2/src/render/dom/compiler/view_loader';
Expand Down Expand Up @@ -118,7 +118,7 @@ function _injectorBindings(appComponentType): List<Type | Binding | List<any>> {
Compiler,
CompilerCache,
ViewResolver,
bind(PipeRegistry).toValue(defaultPipeRegistry),
bind(Pipes).toValue(defaultPipes),
bind(ChangeDetection).toClass(bestChangeDetection),
ViewLoader,
DirectiveResolver,
Expand Down
12 changes: 6 additions & 6 deletions modules/angular2/src/core/compiler/element_injector.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ import {
onAllChangesDone
} from 'angular2/src/core/annotations_impl/annotations';
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 {reflector} from 'angular2/src/reflection/reflection';
import {DirectiveMetadata} from 'angular2/src/render/api';
Expand All @@ -67,7 +67,7 @@ export class StaticKeys {
viewContainerId: number;
changeDetectorRefId: number;
elementRefId: number;
pipeRegistryKey: Key;
pipesKey: Key;

constructor() {
this.viewManagerId = Key.get(avmModule.AppViewManager).id;
Expand All @@ -76,7 +76,7 @@ export class StaticKeys {
this.changeDetectorRefId = Key.get(ChangeDetectorRef).id;
this.elementRefId = Key.get(ElementRef).id;
// 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 {
Expand Down Expand Up @@ -552,9 +552,9 @@ export class ElementInjector extends TreeNode<ElementInjector> implements Depend
injector.internalStrategy.hydrate();
}

getPipeRegistry(): PipeRegistry {
var pipeRegistryKey = StaticKeys.instance().pipeRegistryKey;
return this._injector.getOptional(pipeRegistryKey);
getPipes(): Pipes {
var pipesKey = StaticKeys.instance().pipesKey;
return this._injector.getOptional(pipesKey);
}

hasVariableBinding(name: string): boolean {
Expand Down
13 changes: 6 additions & 7 deletions modules/angular2/src/core/compiler/view_manager_utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -162,16 +162,15 @@ export class AppViewManagerUtils {
this._setUpHostActions(view, elementInjector, i);
}
}
var pipeRegistry = this._getPipeRegistry(imperativelyCreatedInjector, hostElementInjector);
view.changeDetector.hydrate(view.context, view.locals, view, pipeRegistry);
var pipes = this._getPipes(imperativelyCreatedInjector, hostElementInjector);
view.changeDetector.hydrate(view.context, view.locals, view, pipes);
}

_getPipeRegistry(imperativelyCreatedInjector: Injector,
hostElementInjector: eli.ElementInjector) {
var pipeRegistryKey = eli.StaticKeys.instance().pipeRegistryKey;
_getPipes(imperativelyCreatedInjector: Injector, hostElementInjector: eli.ElementInjector) {
var pipesKey = eli.StaticKeys.instance().pipesKey;
if (isPresent(imperativelyCreatedInjector))
return imperativelyCreatedInjector.getOptional(pipeRegistryKey);
if (isPresent(hostElementInjector)) return hostElementInjector.getPipeRegistry();
return imperativelyCreatedInjector.getOptional(pipesKey);
if (isPresent(hostElementInjector)) return hostElementInjector.getPipes();
return null;
}

Expand Down
7 changes: 3 additions & 4 deletions modules/angular2/src/directives/class.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import {Directive, onCheck} from 'angular2/annotations';
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 {Renderer} from 'angular2/src/render/api';
import {KeyValueChanges} from 'angular2/src/change_detection/pipes/keyvalue_changes';
Expand Down Expand Up @@ -35,8 +35,7 @@ export class CSSClass {
_pipe: Pipe;
_rawClass;

constructor(private _pipeRegistry: PipeRegistry, private _ngEl: ElementRef,
private _renderer: Renderer) {}
constructor(private _pipes: Pipes, private _ngEl: ElementRef, private _renderer: Renderer) {}

set rawClass(v) {
this._cleanupClasses(this._rawClass);
Expand All @@ -46,7 +45,7 @@ export class CSSClass {
}

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 {
Expand Down
11 changes: 2 additions & 9 deletions modules/angular2/src/directives/ng_for.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,5 @@
import {Directive} from 'angular2/annotations';
import {
ViewContainerRef,
ViewRef,
ProtoViewRef,
PipeRegistry,
onCheck,
Pipe
} from 'angular2/angular2';
import {ViewContainerRef, ViewRef, ProtoViewRef, Pipes, onCheck, Pipe} from 'angular2/angular2';
import {isPresent, isBlank} from 'angular2/src/facade/lang';

/**
Expand Down Expand Up @@ -47,7 +40,7 @@ export class NgFor {
_pipe: Pipe;

constructor(private viewContainer: ViewContainerRef, private protoViewRef: ProtoViewRef,
private pipes: PipeRegistry) {}
private pipes: Pipes) {}

set ngForOf(value: any) {
this._ngForOf = value;
Expand Down
Loading

0 comments on commit 669b0e4

Please sign in to comment.