tools: added experimentalDecorators flag to tsconfig
This commit is contained in:
parent
e0fb50cc3c
commit
4656c6f5cf
@ -52,7 +52,7 @@ export class AbstractChangeDetector implements ChangeDetector {
|
|||||||
|
|
||||||
detectChangesInRecords(throwOnChange: boolean): void {}
|
detectChangesInRecords(throwOnChange: boolean): void {}
|
||||||
|
|
||||||
hydrate(context: any, locals: Locals, directives: any): void {}
|
hydrate(context: any, locals: Locals, directives: any, pipes: any): void {}
|
||||||
|
|
||||||
dehydrate(): void {}
|
dehydrate(): void {}
|
||||||
|
|
||||||
|
@ -107,11 +107,10 @@ export class PreGeneratedChangeDetection extends ChangeDetection {
|
|||||||
_dynamicChangeDetection: ChangeDetection;
|
_dynamicChangeDetection: ChangeDetection;
|
||||||
_protoChangeDetectorFactories: StringMap<string, Function>;
|
_protoChangeDetectorFactories: StringMap<string, Function>;
|
||||||
|
|
||||||
constructor(private registry: PipeRegistry,
|
constructor(@Inject(PROTO_CHANGE_DETECTOR_KEY) @Optional()
|
||||||
@Inject(PROTO_CHANGE_DETECTOR_KEY) @Optional()
|
|
||||||
protoChangeDetectorsForTest?: StringMap<string, Function>) {
|
protoChangeDetectorsForTest?: StringMap<string, Function>) {
|
||||||
super();
|
super();
|
||||||
this._dynamicChangeDetection = new DynamicChangeDetection(registry);
|
this._dynamicChangeDetection = new DynamicChangeDetection();
|
||||||
this._protoChangeDetectorFactories = isPresent(protoChangeDetectorsForTest) ?
|
this._protoChangeDetectorFactories = isPresent(protoChangeDetectorsForTest) ?
|
||||||
protoChangeDetectorsForTest :
|
protoChangeDetectorsForTest :
|
||||||
preGeneratedProtoDetectors;
|
preGeneratedProtoDetectors;
|
||||||
@ -122,8 +121,7 @@ export class PreGeneratedChangeDetection extends ChangeDetection {
|
|||||||
createProtoChangeDetector(definition: ChangeDetectorDefinition): ProtoChangeDetector {
|
createProtoChangeDetector(definition: ChangeDetectorDefinition): ProtoChangeDetector {
|
||||||
var id = definition.id;
|
var id = definition.id;
|
||||||
if (StringMapWrapper.contains(this._protoChangeDetectorFactories, id)) {
|
if (StringMapWrapper.contains(this._protoChangeDetectorFactories, id)) {
|
||||||
return StringMapWrapper.get(this._protoChangeDetectorFactories, id)(this.registry,
|
return StringMapWrapper.get(this._protoChangeDetectorFactories, id)(definition);
|
||||||
definition);
|
|
||||||
}
|
}
|
||||||
return this._dynamicChangeDetection.createProtoChangeDetector(definition);
|
return this._dynamicChangeDetection.createProtoChangeDetector(definition);
|
||||||
}
|
}
|
||||||
@ -139,10 +137,8 @@ export class PreGeneratedChangeDetection extends ChangeDetection {
|
|||||||
*/
|
*/
|
||||||
@Injectable()
|
@Injectable()
|
||||||
export class DynamicChangeDetection extends ChangeDetection {
|
export class DynamicChangeDetection extends ChangeDetection {
|
||||||
constructor(private registry: PipeRegistry) { super(); }
|
|
||||||
|
|
||||||
createProtoChangeDetector(definition: ChangeDetectorDefinition): ProtoChangeDetector {
|
createProtoChangeDetector(definition: ChangeDetectorDefinition): ProtoChangeDetector {
|
||||||
return new DynamicProtoChangeDetector(this.registry, definition);
|
return new DynamicProtoChangeDetector(definition);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -157,12 +153,10 @@ export class DynamicChangeDetection extends ChangeDetection {
|
|||||||
@Injectable()
|
@Injectable()
|
||||||
@CONST()
|
@CONST()
|
||||||
export class JitChangeDetection extends ChangeDetection {
|
export class JitChangeDetection extends ChangeDetection {
|
||||||
constructor(public registry: PipeRegistry) { super(); }
|
|
||||||
|
|
||||||
static isSupported(): boolean { return JitProtoChangeDetector.isSupported(); }
|
static isSupported(): boolean { return JitProtoChangeDetector.isSupported(); }
|
||||||
|
|
||||||
createProtoChangeDetector(definition: ChangeDetectorDefinition): ProtoChangeDetector {
|
createProtoChangeDetector(definition: ChangeDetectorDefinition): ProtoChangeDetector {
|
||||||
return new JitProtoChangeDetector(this.registry, definition);
|
return new JitProtoChangeDetector(definition);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -67,14 +67,14 @@ export class ChangeDetectorJITGenerator {
|
|||||||
generate(): Function {
|
generate(): Function {
|
||||||
var typeName = _sanitizeName(`ChangeDetector_${this.id}`);
|
var typeName = _sanitizeName(`ChangeDetector_${this.id}`);
|
||||||
var classDefinition = `
|
var classDefinition = `
|
||||||
var ${typeName} = function ${typeName}(dispatcher, pipeRegistry, protos, directiveRecords) {
|
var ${typeName} = function ${typeName}(dispatcher, protos, directiveRecords) {
|
||||||
${ABSTRACT_CHANGE_DETECTOR}.call(this, ${JSON.stringify(this.id)});
|
${ABSTRACT_CHANGE_DETECTOR}.call(this, ${JSON.stringify(this.id)});
|
||||||
${DISPATCHER_ACCESSOR} = dispatcher;
|
${DISPATCHER_ACCESSOR} = dispatcher;
|
||||||
${PIPE_REGISTRY_ACCESSOR} = pipeRegistry;
|
|
||||||
${PROTOS_ACCESSOR} = protos;
|
${PROTOS_ACCESSOR} = protos;
|
||||||
${DIRECTIVES_ACCESSOR} = directiveRecords;
|
${DIRECTIVES_ACCESSOR} = directiveRecords;
|
||||||
${LOCALS_ACCESSOR} = null;
|
${LOCALS_ACCESSOR} = null;
|
||||||
${CURRENT_PROTO} = null;
|
${CURRENT_PROTO} = null;
|
||||||
|
${PIPE_REGISTRY_ACCESSOR} = null;
|
||||||
${ALREADY_CHECKED_ACCESSOR} = false;
|
${ALREADY_CHECKED_ACCESSOR} = false;
|
||||||
${this._genFieldDefinitions()}
|
${this._genFieldDefinitions()}
|
||||||
}
|
}
|
||||||
@ -111,12 +111,13 @@ export class ChangeDetectorJITGenerator {
|
|||||||
${this._genCallOnAllChangesDoneBody()}
|
${this._genCallOnAllChangesDoneBody()}
|
||||||
}
|
}
|
||||||
|
|
||||||
${typeName}.prototype.hydrate = function(context, locals, directives) {
|
${typeName}.prototype.hydrate = function(context, locals, directives, pipeRegistry) {
|
||||||
${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;
|
||||||
${ALREADY_CHECKED_ACCESSOR} = false;
|
${ALREADY_CHECKED_ACCESSOR} = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -124,14 +125,15 @@ export class ChangeDetectorJITGenerator {
|
|||||||
${this._genPipeOnDestroy()}
|
${this._genPipeOnDestroy()}
|
||||||
${this._genFieldDefinitions()}
|
${this._genFieldDefinitions()}
|
||||||
${LOCALS_ACCESSOR} = null;
|
${LOCALS_ACCESSOR} = null;
|
||||||
|
${PIPE_REGISTRY_ACCESSOR} = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
${typeName}.prototype.hydrated = function() {
|
${typeName}.prototype.hydrated = function() {
|
||||||
return ${CONTEXT_ACCESSOR} !== null;
|
return ${CONTEXT_ACCESSOR} !== null;
|
||||||
}
|
}
|
||||||
|
|
||||||
return function(dispatcher, pipeRegistry) {
|
return function(dispatcher) {
|
||||||
return new ${typeName}(dispatcher, pipeRegistry, protos, directiveRecords);
|
return new ${typeName}(dispatcher, protos, directiveRecords);
|
||||||
}
|
}
|
||||||
`;
|
`;
|
||||||
return new Function('AbstractChangeDetector', 'ChangeDetectionUtil', 'protos',
|
return new Function('AbstractChangeDetector', 'ChangeDetectionUtil', 'protos',
|
||||||
|
@ -18,10 +18,10 @@ export class DynamicChangeDetector extends AbstractChangeDetector {
|
|||||||
prevContexts: List<any>;
|
prevContexts: List<any>;
|
||||||
directives: any = null;
|
directives: any = null;
|
||||||
alreadyChecked: boolean = false;
|
alreadyChecked: boolean = false;
|
||||||
|
private pipeRegistry: PipeRegistry = null;
|
||||||
|
|
||||||
constructor(id: string, private changeControlStrategy: string, private dispatcher: any,
|
constructor(id: string, private changeControlStrategy: string, private dispatcher: any,
|
||||||
private pipeRegistry: PipeRegistry, private protos: List<ProtoRecord>,
|
private protos: List<ProtoRecord>, private directiveRecords: List<any>) {
|
||||||
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.pipes = ListWrapper.createFixedSize(protos.length + 1);
|
||||||
@ -35,12 +35,13 @@ export class DynamicChangeDetector extends AbstractChangeDetector {
|
|||||||
ListWrapper.fill(this.changes, false);
|
ListWrapper.fill(this.changes, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
hydrate(context: any, locals: Locals, directives: any) {
|
hydrate(context: any, locals: Locals, directives: any, pipeRegistry: PipeRegistry): 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;
|
||||||
}
|
}
|
||||||
|
|
||||||
dehydrate() {
|
dehydrate() {
|
||||||
@ -51,6 +52,7 @@ export class DynamicChangeDetector extends AbstractChangeDetector {
|
|||||||
ListWrapper.fill(this.pipes, null);
|
ListWrapper.fill(this.pipes, null);
|
||||||
ListWrapper.fill(this.prevContexts, uninitialized);
|
ListWrapper.fill(this.prevContexts, uninitialized);
|
||||||
this.locals = null;
|
this.locals = null;
|
||||||
|
this.pipeRegistry = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
_destroyPipes() {
|
_destroyPipes() {
|
||||||
|
@ -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): void;
|
hydrate(context: any, locals: Locals, directives: any, pipeRegistry: any): void;
|
||||||
dehydrate(): void;
|
dehydrate(): void;
|
||||||
markPathToRootAsCheckOnce(): void;
|
markPathToRootAsCheckOnce(): void;
|
||||||
|
|
||||||
|
@ -3,7 +3,7 @@ library change_detection.jit_proto_change_detector;
|
|||||||
import 'interfaces.dart' show ChangeDetector, ProtoChangeDetector;
|
import 'interfaces.dart' show ChangeDetector, ProtoChangeDetector;
|
||||||
|
|
||||||
class JitProtoChangeDetector implements ProtoChangeDetector {
|
class JitProtoChangeDetector implements ProtoChangeDetector {
|
||||||
JitProtoChangeDetector(registry, definition) : super();
|
JitProtoChangeDetector(definition) : super();
|
||||||
|
|
||||||
static bool isSupported() => false;
|
static bool isSupported() => false;
|
||||||
|
|
||||||
|
@ -9,15 +9,13 @@ import {ProtoRecordBuilder} from './proto_change_detector';
|
|||||||
export class JitProtoChangeDetector implements ProtoChangeDetector {
|
export class JitProtoChangeDetector implements ProtoChangeDetector {
|
||||||
_factory: Function;
|
_factory: Function;
|
||||||
|
|
||||||
constructor(private _pipeRegistry, private definition: ChangeDetectorDefinition) {
|
constructor(private definition: ChangeDetectorDefinition) {
|
||||||
this._factory = this._createFactory(definition);
|
this._factory = this._createFactory(definition);
|
||||||
}
|
}
|
||||||
|
|
||||||
static isSupported(): boolean { return true; }
|
static isSupported(): boolean { return true; }
|
||||||
|
|
||||||
instantiate(dispatcher: any): ChangeDetector {
|
instantiate(dispatcher: any): ChangeDetector { return this._factory(dispatcher); }
|
||||||
return this._factory(dispatcher, this._pipeRegistry);
|
|
||||||
}
|
|
||||||
|
|
||||||
_createFactory(definition: ChangeDetectorDefinition) {
|
_createFactory(definition: ChangeDetectorDefinition) {
|
||||||
var recordBuilder = new ProtoRecordBuilder();
|
var recordBuilder = new ProtoRecordBuilder();
|
||||||
|
@ -3,7 +3,6 @@ library angular2.src.change_detection.pregen_proto_change_detector;
|
|||||||
import 'package:angular2/src/change_detection/coalesce.dart';
|
import 'package:angular2/src/change_detection/coalesce.dart';
|
||||||
import 'package:angular2/src/change_detection/directive_record.dart';
|
import 'package:angular2/src/change_detection/directive_record.dart';
|
||||||
import 'package:angular2/src/change_detection/interfaces.dart';
|
import 'package:angular2/src/change_detection/interfaces.dart';
|
||||||
import 'package:angular2/src/change_detection/pipes/pipe_registry.dart';
|
|
||||||
import 'package:angular2/src/change_detection/proto_change_detector.dart';
|
import 'package:angular2/src/change_detection/proto_change_detector.dart';
|
||||||
import 'package:angular2/src/change_detection/proto_record.dart';
|
import 'package:angular2/src/change_detection/proto_record.dart';
|
||||||
|
|
||||||
@ -25,10 +24,10 @@ export 'package:angular2/src/change_detection/change_detection_util.dart'
|
|||||||
export 'package:angular2/src/facade/lang.dart' show looseIdentical;
|
export 'package:angular2/src/facade/lang.dart' show looseIdentical;
|
||||||
|
|
||||||
typedef ProtoChangeDetector PregenProtoChangeDetectorFactory(
|
typedef ProtoChangeDetector PregenProtoChangeDetectorFactory(
|
||||||
PipeRegistry registry, ChangeDetectorDefinition definition);
|
ChangeDetectorDefinition definition);
|
||||||
|
|
||||||
typedef ChangeDetector InstantiateMethod(dynamic dispatcher,
|
typedef ChangeDetector InstantiateMethod(dynamic dispatcher,
|
||||||
PipeRegistry registry, List<ProtoRecord> protoRecords,
|
List<ProtoRecord> protoRecords,
|
||||||
List<DirectiveRecord> directiveRecords);
|
List<DirectiveRecord> directiveRecords);
|
||||||
|
|
||||||
/// Implementation of [ProtoChangeDetector] for use by pre-generated change
|
/// Implementation of [ProtoChangeDetector] for use by pre-generated change
|
||||||
@ -44,29 +43,28 @@ class PregenProtoChangeDetector extends ProtoChangeDetector {
|
|||||||
final InstantiateMethod _instantiateMethod;
|
final InstantiateMethod _instantiateMethod;
|
||||||
|
|
||||||
// [ChangeDetector] dependencies.
|
// [ChangeDetector] dependencies.
|
||||||
final PipeRegistry _pipeRegistry;
|
|
||||||
final List<ProtoRecord> _protoRecords;
|
final List<ProtoRecord> _protoRecords;
|
||||||
final List<DirectiveRecord> _directiveRecords;
|
final List<DirectiveRecord> _directiveRecords;
|
||||||
|
|
||||||
/// Internal ctor.
|
/// Internal ctor.
|
||||||
PregenProtoChangeDetector._(this.id, this._instantiateMethod,
|
PregenProtoChangeDetector._(this.id, this._instantiateMethod,
|
||||||
this._pipeRegistry, this._protoRecords, this._directiveRecords);
|
this._protoRecords, this._directiveRecords);
|
||||||
|
|
||||||
static bool isSupported() => true;
|
static bool isSupported() => true;
|
||||||
|
|
||||||
factory PregenProtoChangeDetector(InstantiateMethod instantiateMethod,
|
factory PregenProtoChangeDetector(InstantiateMethod instantiateMethod,
|
||||||
PipeRegistry registry, ChangeDetectorDefinition def) {
|
ChangeDetectorDefinition def) {
|
||||||
// TODO(kegluneq): Pre-generate these (#2067).
|
// TODO(kegluneq): Pre-generate these (#2067).
|
||||||
var recordBuilder = new ProtoRecordBuilder();
|
var recordBuilder = new ProtoRecordBuilder();
|
||||||
def.bindingRecords.forEach((b) {
|
def.bindingRecords.forEach((b) {
|
||||||
recordBuilder.add(b, def.variableNames);
|
recordBuilder.add(b, def.variableNames);
|
||||||
});
|
});
|
||||||
var protoRecords = coalesce(recordBuilder.records);
|
var protoRecords = coalesce(recordBuilder.records);
|
||||||
return new PregenProtoChangeDetector._(def.id, instantiateMethod, registry,
|
return new PregenProtoChangeDetector._(def.id, instantiateMethod,
|
||||||
protoRecords, def.directiveRecords);
|
protoRecords, def.directiveRecords);
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
instantiate(dynamic dispatcher) => _instantiateMethod(
|
instantiate(dynamic dispatcher) => _instantiateMethod(
|
||||||
dispatcher, _pipeRegistry, _protoRecords, _directiveRecords);
|
dispatcher, _protoRecords, _directiveRecords);
|
||||||
}
|
}
|
||||||
|
@ -28,7 +28,6 @@ import {
|
|||||||
import {ChangeDetector, ProtoChangeDetector, ChangeDetectorDefinition} from './interfaces';
|
import {ChangeDetector, ProtoChangeDetector, ChangeDetectorDefinition} from './interfaces';
|
||||||
import {ChangeDetectionUtil} from './change_detection_util';
|
import {ChangeDetectionUtil} from './change_detection_util';
|
||||||
import {DynamicChangeDetector} from './dynamic_change_detector';
|
import {DynamicChangeDetector} from './dynamic_change_detector';
|
||||||
import {PipeRegistry} from './pipes/pipe_registry';
|
|
||||||
import {BindingRecord} from './binding_record';
|
import {BindingRecord} from './binding_record';
|
||||||
import {DirectiveRecord, DirectiveIndex} from './directive_record';
|
import {DirectiveRecord, DirectiveIndex} from './directive_record';
|
||||||
|
|
||||||
@ -39,14 +38,13 @@ import {ProtoRecord, RecordType} from './proto_record';
|
|||||||
export class DynamicProtoChangeDetector implements ProtoChangeDetector {
|
export class DynamicProtoChangeDetector implements ProtoChangeDetector {
|
||||||
_records: List<ProtoRecord>;
|
_records: List<ProtoRecord>;
|
||||||
|
|
||||||
constructor(private _pipeRegistry: PipeRegistry, private definition: ChangeDetectorDefinition) {
|
constructor(private definition: ChangeDetectorDefinition) {
|
||||||
this._records = this._createRecords(definition);
|
this._records = this._createRecords(definition);
|
||||||
}
|
}
|
||||||
|
|
||||||
instantiate(dispatcher: any): ChangeDetector {
|
instantiate(dispatcher: any): ChangeDetector {
|
||||||
return new DynamicChangeDetector(this.definition.id, this.definition.strategy, dispatcher,
|
return new DynamicChangeDetector(this.definition.id, this.definition.strategy, dispatcher,
|
||||||
this._pipeRegistry, this._records,
|
this._records, this.definition.directiveRecords);
|
||||||
this.definition.directiveRecords);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
_createRecords(definition: ChangeDetectorDefinition) {
|
_createRecords(definition: ChangeDetectorDefinition) {
|
||||||
|
@ -54,27 +54,29 @@ 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} from 'angular2/change_detection';
|
import {ChangeDetector, ChangeDetectorRef, PipeRegistry} 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';
|
||||||
|
|
||||||
var _staticKeys;
|
var _staticKeys;
|
||||||
|
|
||||||
class StaticKeys {
|
export class StaticKeys {
|
||||||
viewManagerId: number;
|
viewManagerId: number;
|
||||||
protoViewId: number;
|
protoViewId: number;
|
||||||
viewContainerId: number;
|
viewContainerId: number;
|
||||||
changeDetectorRefId: number;
|
changeDetectorRefId: number;
|
||||||
elementRefId: number;
|
elementRefId: number;
|
||||||
|
pipeRegistryKey: Key;
|
||||||
|
|
||||||
constructor() {
|
constructor() {
|
||||||
// TODO: vsavkin Key.annotate(Key.get(AppView), 'static')
|
|
||||||
this.viewManagerId = Key.get(avmModule.AppViewManager).id;
|
this.viewManagerId = Key.get(avmModule.AppViewManager).id;
|
||||||
this.protoViewId = Key.get(ProtoViewRef).id;
|
this.protoViewId = Key.get(ProtoViewRef).id;
|
||||||
this.viewContainerId = Key.get(ViewContainerRef).id;
|
this.viewContainerId = Key.get(ViewContainerRef).id;
|
||||||
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
|
||||||
|
this.pipeRegistryKey = Key.get(PipeRegistry);
|
||||||
}
|
}
|
||||||
|
|
||||||
static instance(): StaticKeys {
|
static instance(): StaticKeys {
|
||||||
@ -529,14 +531,15 @@ export class ElementInjector extends TreeNode<ElementInjector> implements Depend
|
|||||||
// |boundary
|
// |boundary
|
||||||
// |
|
// |
|
||||||
// this._injector
|
// this._injector
|
||||||
var parent = this._getParentInjector(imperativelyCreatedInjector, host);
|
var parent = this._closestBoundaryInjector(imperativelyCreatedInjector, host);
|
||||||
this._reattachInjector(this._injector, parent, true);
|
this._reattachInjector(this._injector, parent, true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private _getParentInjector(injector: Injector, host: ElementInjector): Injector {
|
private _closestBoundaryInjector(imperativelyCreatedInjector: Injector,
|
||||||
if (isPresent(injector)) {
|
host: ElementInjector): Injector {
|
||||||
return injector;
|
if (isPresent(imperativelyCreatedInjector)) {
|
||||||
|
return imperativelyCreatedInjector;
|
||||||
} else if (isPresent(host)) {
|
} else if (isPresent(host)) {
|
||||||
return host._injector;
|
return host._injector;
|
||||||
} else {
|
} else {
|
||||||
@ -549,6 +552,11 @@ export class ElementInjector extends TreeNode<ElementInjector> implements Depend
|
|||||||
injector.internalStrategy.hydrate();
|
injector.internalStrategy.hydrate();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
getPipeRegistry(): PipeRegistry {
|
||||||
|
var pipeRegistryKey = StaticKeys.instance().pipeRegistryKey;
|
||||||
|
return this._injector.getOptional(pipeRegistryKey);
|
||||||
|
}
|
||||||
|
|
||||||
hasVariableBinding(name: string): boolean {
|
hasVariableBinding(name: string): boolean {
|
||||||
var vb = this._proto.directiveVariableBindings;
|
var vb = this._proto.directiveVariableBindings;
|
||||||
return isPresent(vb) && vb.has(name);
|
return isPresent(vb) && vb.has(name);
|
||||||
|
@ -141,12 +141,11 @@ export class AppViewManagerUtils {
|
|||||||
var elementInjector = contextView.elementInjectors[contextBoundElementIndex];
|
var elementInjector = contextView.elementInjectors[contextBoundElementIndex];
|
||||||
|
|
||||||
var injector = isPresent(bindings) ? Injector.fromResolvedBindings(bindings) : null;
|
var injector = isPresent(bindings) ? Injector.fromResolvedBindings(bindings) : null;
|
||||||
|
|
||||||
this._hydrateView(view, injector, elementInjector.getHost(), contextView.context,
|
this._hydrateView(view, injector, elementInjector.getHost(), contextView.context,
|
||||||
contextView.locals);
|
contextView.locals);
|
||||||
}
|
}
|
||||||
|
|
||||||
_hydrateView(view: viewModule.AppView, injector: Injector,
|
_hydrateView(view: viewModule.AppView, imperativelyCreatedInjector: Injector,
|
||||||
hostElementInjector: eli.ElementInjector, context: Object, parentLocals: Locals) {
|
hostElementInjector: eli.ElementInjector, context: Object, parentLocals: Locals) {
|
||||||
view.context = context;
|
view.context = context;
|
||||||
view.locals.parent = parentLocals;
|
view.locals.parent = parentLocals;
|
||||||
@ -156,13 +155,24 @@ export class AppViewManagerUtils {
|
|||||||
var elementInjector = view.elementInjectors[i];
|
var elementInjector = view.elementInjectors[i];
|
||||||
|
|
||||||
if (isPresent(elementInjector)) {
|
if (isPresent(elementInjector)) {
|
||||||
elementInjector.hydrate(injector, hostElementInjector, view.preBuiltObjects[i]);
|
elementInjector.hydrate(imperativelyCreatedInjector, hostElementInjector,
|
||||||
|
view.preBuiltObjects[i]);
|
||||||
this._populateViewLocals(view, elementInjector);
|
this._populateViewLocals(view, elementInjector);
|
||||||
this._setUpEventEmitters(view, elementInjector, i);
|
this._setUpEventEmitters(view, elementInjector, i);
|
||||||
this._setUpHostActions(view, elementInjector, i);
|
this._setUpHostActions(view, elementInjector, i);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
view.changeDetector.hydrate(view.context, view.locals, view);
|
var pipeRegistry = this._getPipeRegistry(imperativelyCreatedInjector, hostElementInjector);
|
||||||
|
view.changeDetector.hydrate(view.context, view.locals, view, pipeRegistry);
|
||||||
|
}
|
||||||
|
|
||||||
|
_getPipeRegistry(imperativelyCreatedInjector: Injector,
|
||||||
|
hostElementInjector: eli.ElementInjector) {
|
||||||
|
var pipeRegistryKey = eli.StaticKeys.instance().pipeRegistryKey;
|
||||||
|
if (isPresent(imperativelyCreatedInjector))
|
||||||
|
return imperativelyCreatedInjector.getOptional(pipeRegistryKey);
|
||||||
|
if (isPresent(hostElementInjector)) return hostElementInjector.getPipeRegistry();
|
||||||
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
_populateViewLocals(view: viewModule.AppView, elementInjector: eli.ElementInjector): void {
|
_populateViewLocals(view: viewModule.AppView, elementInjector: eli.ElementInjector): void {
|
||||||
|
@ -125,7 +125,7 @@ class _CodegenState {
|
|||||||
buf.write('''
|
buf.write('''
|
||||||
class $_changeDetectorTypeName extends $_BASE_CLASS {
|
class $_changeDetectorTypeName extends $_BASE_CLASS {
|
||||||
final dynamic $_DISPATCHER_ACCESSOR;
|
final dynamic $_DISPATCHER_ACCESSOR;
|
||||||
final $_GEN_PREFIX.PipeRegistry $_PIPE_REGISTRY_ACCESSOR;
|
$_GEN_PREFIX.PipeRegistry $_PIPE_REGISTRY_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;
|
||||||
@ -141,7 +141,6 @@ class _CodegenState {
|
|||||||
|
|
||||||
$_changeDetectorTypeName(
|
$_changeDetectorTypeName(
|
||||||
this.$_DISPATCHER_ACCESSOR,
|
this.$_DISPATCHER_ACCESSOR,
|
||||||
this.$_PIPE_REGISTRY_ACCESSOR,
|
|
||||||
this.$_PROTOS_ACCESSOR,
|
this.$_PROTOS_ACCESSOR,
|
||||||
this.$_DIRECTIVES_ACCESSOR) : super(${JSON.encode(_changeDetectorDefId)});
|
this.$_DIRECTIVES_ACCESSOR) : super(${JSON.encode(_changeDetectorDefId)});
|
||||||
|
|
||||||
@ -173,13 +172,14 @@ class _CodegenState {
|
|||||||
${_getCallOnAllChangesDoneBody()}
|
${_getCallOnAllChangesDoneBody()}
|
||||||
}
|
}
|
||||||
|
|
||||||
void hydrate($_contextTypeName context, locals, directives) {
|
void hydrate($_contextTypeName context, locals, directives, pipeRegistry) {
|
||||||
$_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;
|
||||||
}
|
}
|
||||||
|
|
||||||
void dehydrate() {
|
void dehydrate() {
|
||||||
@ -190,17 +190,17 @@ class _CodegenState {
|
|||||||
: '$f = $_UTIL.uninitialized();';
|
: '$f = $_UTIL.uninitialized();';
|
||||||
}).join('')}
|
}).join('')}
|
||||||
$_LOCALS_ACCESSOR = null;
|
$_LOCALS_ACCESSOR = null;
|
||||||
|
$_PIPE_REGISTRY_ACCESSOR = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
hydrated() => $_CONTEXT_ACCESSOR != null;
|
hydrated() => $_CONTEXT_ACCESSOR != null;
|
||||||
|
|
||||||
static $_GEN_PREFIX.ProtoChangeDetector
|
static $_GEN_PREFIX.ProtoChangeDetector
|
||||||
$PROTO_CHANGE_DETECTOR_FACTORY_METHOD(
|
$PROTO_CHANGE_DETECTOR_FACTORY_METHOD(
|
||||||
$_GEN_PREFIX.PipeRegistry registry,
|
|
||||||
$_GEN_PREFIX.ChangeDetectorDefinition def) {
|
$_GEN_PREFIX.ChangeDetectorDefinition def) {
|
||||||
return new $_GEN_PREFIX.PregenProtoChangeDetector(
|
return new $_GEN_PREFIX.PregenProtoChangeDetector(
|
||||||
(a, b, c, d) => new $_changeDetectorTypeName(a, b, c, d),
|
(a, b, c) => new $_changeDetectorTypeName(a, b, c),
|
||||||
registry, def);
|
def);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
''');
|
''');
|
||||||
|
@ -27,14 +27,14 @@ export function main() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it("should return a proto change detector when one is available", () => {
|
it("should return a proto change detector when one is available", () => {
|
||||||
var map = {'id': (registry, def) => proto};
|
var map = {'id': (def) => proto};
|
||||||
var cd = new PreGeneratedChangeDetection(null, map);
|
var cd = new PreGeneratedChangeDetection(map);
|
||||||
|
|
||||||
expect(cd.createProtoChangeDetector(def)).toBe(proto)
|
expect(cd.createProtoChangeDetector(def)).toBe(proto)
|
||||||
});
|
});
|
||||||
|
|
||||||
it("should delegate to dynamic change detection otherwise", () => {
|
it("should delegate to dynamic change detection otherwise", () => {
|
||||||
var cd = new PreGeneratedChangeDetection(null, {});
|
var cd = new PreGeneratedChangeDetection({});
|
||||||
expect(cd.createProtoChangeDetector(def)).toBeAnInstanceOf(DynamicProtoChangeDetector);
|
expect(cd.createProtoChangeDetector(def)).toBeAnInstanceOf(DynamicProtoChangeDetector);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
@ -66,20 +66,19 @@ const _DEFAULT_CONTEXT = CONST_EXPR(new Object());
|
|||||||
*/
|
*/
|
||||||
export function main() {
|
export function main() {
|
||||||
ListWrapper.forEach(['dynamic', 'JIT', 'Pregen'], (cdType) => {
|
ListWrapper.forEach(['dynamic', 'JIT', 'Pregen'], (cdType) => {
|
||||||
|
|
||||||
if (cdType == "JIT" && IS_DARTIUM) return;
|
if (cdType == "JIT" && IS_DARTIUM) return;
|
||||||
if (cdType == "Pregen" && !IS_DARTIUM) return;
|
if (cdType == "Pregen" && !IS_DARTIUM) return;
|
||||||
|
|
||||||
describe(`${cdType} Change Detector`, () => {
|
describe(`${cdType} Change Detector`, () => {
|
||||||
|
|
||||||
function _getProtoChangeDetector(def: ChangeDetectorDefinition, registry = null) {
|
function _getProtoChangeDetector(def: ChangeDetectorDefinition) {
|
||||||
switch (cdType) {
|
switch (cdType) {
|
||||||
case 'dynamic':
|
case 'dynamic':
|
||||||
return new DynamicProtoChangeDetector(registry, def);
|
return new DynamicProtoChangeDetector(def);
|
||||||
case 'JIT':
|
case 'JIT':
|
||||||
return new JitProtoChangeDetector(registry, def);
|
return new JitProtoChangeDetector(def);
|
||||||
case 'Pregen':
|
case 'Pregen':
|
||||||
return getFactoryById(def.id)(registry, def);
|
return getFactoryById(def.id)(def);
|
||||||
default:
|
default:
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
@ -87,9 +86,7 @@ export function main() {
|
|||||||
|
|
||||||
function _createWithoutHydrate(expression: string) {
|
function _createWithoutHydrate(expression: string) {
|
||||||
var dispatcher = new TestDispatcher();
|
var dispatcher = new TestDispatcher();
|
||||||
var registry = null;
|
var cd = _getProtoChangeDetector(getDefinition(expression).cdDef).instantiate(dispatcher);
|
||||||
var cd = _getProtoChangeDetector(getDefinition(expression).cdDef, registry)
|
|
||||||
.instantiate(dispatcher);
|
|
||||||
return new _ChangeDetectorAndDispatcher(cd, dispatcher);
|
return new _ChangeDetectorAndDispatcher(cd, dispatcher);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -98,9 +95,9 @@ export function main() {
|
|||||||
registry = null) {
|
registry = null) {
|
||||||
var dispatcher = new TestDispatcher();
|
var dispatcher = new TestDispatcher();
|
||||||
var testDef = getDefinition(expression);
|
var testDef = getDefinition(expression);
|
||||||
var protoCd = _getProtoChangeDetector(testDef.cdDef, registry);
|
var protoCd = _getProtoChangeDetector(testDef.cdDef);
|
||||||
var cd = protoCd.instantiate(dispatcher);
|
var cd = protoCd.instantiate(dispatcher);
|
||||||
cd.hydrate(context, testDef.locals, null);
|
cd.hydrate(context, testDef.locals, null, registry);
|
||||||
return new _ChangeDetectorAndDispatcher(cd, dispatcher);
|
return new _ChangeDetectorAndDispatcher(cd, dispatcher);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -298,7 +295,7 @@ export function main() {
|
|||||||
|
|
||||||
it('should support interpolation', () => {
|
it('should support interpolation', () => {
|
||||||
var val = _createChangeDetector('interpolation', new TestData('value'));
|
var val = _createChangeDetector('interpolation', new TestData('value'));
|
||||||
val.changeDetector.hydrate(new TestData('value'), null, null);
|
val.changeDetector.hydrate(new TestData('value'), null, null, null);
|
||||||
|
|
||||||
val.changeDetector.detectChanges();
|
val.changeDetector.detectChanges();
|
||||||
|
|
||||||
@ -361,8 +358,8 @@ export function main() {
|
|||||||
|
|
||||||
it('should happen directly, without invoking the dispatcher', () => {
|
it('should happen directly, without invoking the dispatcher', () => {
|
||||||
var val = _createWithoutHydrate('directNoDispatcher');
|
var val = _createWithoutHydrate('directNoDispatcher');
|
||||||
val.changeDetector.hydrate(_DEFAULT_CONTEXT, null,
|
val.changeDetector.hydrate(_DEFAULT_CONTEXT, null, new FakeDirectives([directive1], []),
|
||||||
new FakeDirectives([directive1], []));
|
null);
|
||||||
val.changeDetector.detectChanges();
|
val.changeDetector.detectChanges();
|
||||||
expect(val.dispatcher.loggedValues).toEqual([]);
|
expect(val.dispatcher.loggedValues).toEqual([]);
|
||||||
expect(directive1.a).toEqual(42);
|
expect(directive1.a).toEqual(42);
|
||||||
@ -371,7 +368,8 @@ export function main() {
|
|||||||
describe('onChange', () => {
|
describe('onChange', () => {
|
||||||
it('should notify the directive when a group of records changes', () => {
|
it('should notify the directive when a group of records changes', () => {
|
||||||
var cd = _createWithoutHydrate('groupChanges').changeDetector;
|
var cd = _createWithoutHydrate('groupChanges').changeDetector;
|
||||||
cd.hydrate(_DEFAULT_CONTEXT, null, new FakeDirectives([directive1, directive2], []));
|
cd.hydrate(_DEFAULT_CONTEXT, null, new FakeDirectives([directive1, directive2], []),
|
||||||
|
null);
|
||||||
cd.detectChanges();
|
cd.detectChanges();
|
||||||
expect(directive1.changes).toEqual({'a': 1, 'b': 2});
|
expect(directive1.changes).toEqual({'a': 1, 'b': 2});
|
||||||
expect(directive2.changes).toEqual({'a': 3});
|
expect(directive2.changes).toEqual({'a': 3});
|
||||||
@ -382,7 +380,7 @@ export function main() {
|
|||||||
it('should notify the directive when it is checked', () => {
|
it('should notify the directive when it is checked', () => {
|
||||||
var cd = _createWithoutHydrate('directiveOnCheck').changeDetector;
|
var cd = _createWithoutHydrate('directiveOnCheck').changeDetector;
|
||||||
|
|
||||||
cd.hydrate(_DEFAULT_CONTEXT, null, new FakeDirectives([directive1], []));
|
cd.hydrate(_DEFAULT_CONTEXT, null, new FakeDirectives([directive1], []), null);
|
||||||
cd.detectChanges();
|
cd.detectChanges();
|
||||||
|
|
||||||
expect(directive1.onCheckCalled).toBe(true);
|
expect(directive1.onCheckCalled).toBe(true);
|
||||||
@ -395,7 +393,7 @@ export function main() {
|
|||||||
it('should not call onCheck in detectNoChanges', () => {
|
it('should not call onCheck in detectNoChanges', () => {
|
||||||
var cd = _createWithoutHydrate('directiveOnCheck').changeDetector;
|
var cd = _createWithoutHydrate('directiveOnCheck').changeDetector;
|
||||||
|
|
||||||
cd.hydrate(_DEFAULT_CONTEXT, null, new FakeDirectives([directive1], []));
|
cd.hydrate(_DEFAULT_CONTEXT, null, new FakeDirectives([directive1], []), null);
|
||||||
|
|
||||||
cd.checkNoChanges();
|
cd.checkNoChanges();
|
||||||
|
|
||||||
@ -407,7 +405,7 @@ export function main() {
|
|||||||
it('should notify the directive after it has been checked the first time', () => {
|
it('should notify the directive after it has been checked the first time', () => {
|
||||||
var cd = _createWithoutHydrate('directiveOnInit').changeDetector;
|
var cd = _createWithoutHydrate('directiveOnInit').changeDetector;
|
||||||
|
|
||||||
cd.hydrate(_DEFAULT_CONTEXT, null, new FakeDirectives([directive1], []));
|
cd.hydrate(_DEFAULT_CONTEXT, null, new FakeDirectives([directive1], []), null);
|
||||||
|
|
||||||
cd.detectChanges();
|
cd.detectChanges();
|
||||||
|
|
||||||
@ -423,7 +421,7 @@ export function main() {
|
|||||||
it('should not call onInit in detectNoChanges', () => {
|
it('should not call onInit in detectNoChanges', () => {
|
||||||
var cd = _createWithoutHydrate('directiveOnInit').changeDetector;
|
var cd = _createWithoutHydrate('directiveOnInit').changeDetector;
|
||||||
|
|
||||||
cd.hydrate(_DEFAULT_CONTEXT, null, new FakeDirectives([directive1], []));
|
cd.hydrate(_DEFAULT_CONTEXT, null, new FakeDirectives([directive1], []), null);
|
||||||
|
|
||||||
cd.checkNoChanges();
|
cd.checkNoChanges();
|
||||||
|
|
||||||
@ -434,7 +432,8 @@ export function main() {
|
|||||||
describe('onAllChangesDone', () => {
|
describe('onAllChangesDone', () => {
|
||||||
it('should be called after processing all the children', () => {
|
it('should be called after processing all the children', () => {
|
||||||
var cd = _createWithoutHydrate('emptyWithDirectiveRecords').changeDetector;
|
var cd = _createWithoutHydrate('emptyWithDirectiveRecords').changeDetector;
|
||||||
cd.hydrate(_DEFAULT_CONTEXT, null, new FakeDirectives([directive1, directive2], []));
|
cd.hydrate(_DEFAULT_CONTEXT, null, new FakeDirectives([directive1, directive2], []),
|
||||||
|
null);
|
||||||
|
|
||||||
cd.detectChanges();
|
cd.detectChanges();
|
||||||
|
|
||||||
@ -462,7 +461,7 @@ export function main() {
|
|||||||
it('should not be called when onAllChangesDone is false', () => {
|
it('should not be called when onAllChangesDone is false', () => {
|
||||||
var cd = _createWithoutHydrate('noCallbacks').changeDetector;
|
var cd = _createWithoutHydrate('noCallbacks').changeDetector;
|
||||||
|
|
||||||
cd.hydrate(_DEFAULT_CONTEXT, null, new FakeDirectives([directive1], []));
|
cd.hydrate(_DEFAULT_CONTEXT, null, new FakeDirectives([directive1], []), null);
|
||||||
|
|
||||||
cd.detectChanges();
|
cd.detectChanges();
|
||||||
|
|
||||||
@ -478,7 +477,7 @@ export function main() {
|
|||||||
td1 = new TestDirective(() => onChangesDoneCalls.push(td1));
|
td1 = new TestDirective(() => onChangesDoneCalls.push(td1));
|
||||||
var td2;
|
var td2;
|
||||||
td2 = new TestDirective(() => onChangesDoneCalls.push(td2));
|
td2 = new TestDirective(() => onChangesDoneCalls.push(td2));
|
||||||
cd.hydrate(_DEFAULT_CONTEXT, null, new FakeDirectives([td1, td2], []));
|
cd.hydrate(_DEFAULT_CONTEXT, null, new FakeDirectives([td1, td2], []), null);
|
||||||
|
|
||||||
cd.detectChanges();
|
cd.detectChanges();
|
||||||
|
|
||||||
@ -499,8 +498,10 @@ export function main() {
|
|||||||
parentDirective =
|
parentDirective =
|
||||||
new TestDirective(() => { orderOfOperations.push(parentDirective); });
|
new TestDirective(() => { orderOfOperations.push(parentDirective); });
|
||||||
|
|
||||||
parent.hydrate(_DEFAULT_CONTEXT, null, new FakeDirectives([parentDirective], []));
|
parent.hydrate(_DEFAULT_CONTEXT, null, new FakeDirectives([parentDirective], []),
|
||||||
child.hydrate(_DEFAULT_CONTEXT, null, new FakeDirectives([directiveInShadowDom], []));
|
null);
|
||||||
|
child.hydrate(_DEFAULT_CONTEXT, null, new FakeDirectives([directiveInShadowDom], []),
|
||||||
|
null);
|
||||||
|
|
||||||
parent.detectChanges();
|
parent.detectChanges();
|
||||||
expect(orderOfOperations).toEqual([parentDirective, directiveInShadowDom]);
|
expect(orderOfOperations).toEqual([parentDirective, directiveInShadowDom]);
|
||||||
@ -515,7 +516,8 @@ export function main() {
|
|||||||
directive.a = 'aaa';
|
directive.a = 'aaa';
|
||||||
|
|
||||||
var val = _createWithoutHydrate('readingDirectives');
|
var val = _createWithoutHydrate('readingDirectives');
|
||||||
val.changeDetector.hydrate(_DEFAULT_CONTEXT, null, new FakeDirectives([directive], []));
|
val.changeDetector.hydrate(_DEFAULT_CONTEXT, null, new FakeDirectives([directive], []),
|
||||||
|
null);
|
||||||
|
|
||||||
val.changeDetector.detectChanges();
|
val.changeDetector.detectChanges();
|
||||||
|
|
||||||
@ -625,13 +627,13 @@ export function main() {
|
|||||||
var cd = _createWithoutHydrate('emptyUsingDefaultStrategy').changeDetector;
|
var cd = _createWithoutHydrate('emptyUsingDefaultStrategy').changeDetector;
|
||||||
expect(cd.mode).toEqual(null);
|
expect(cd.mode).toEqual(null);
|
||||||
|
|
||||||
cd.hydrate(_DEFAULT_CONTEXT, null, null);
|
cd.hydrate(_DEFAULT_CONTEXT, null, null, null);
|
||||||
expect(cd.mode).toEqual(CHECK_ALWAYS);
|
expect(cd.mode).toEqual(CHECK_ALWAYS);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should set the mode to CHECK_ONCE when the push change detection is used', () => {
|
it('should set the mode to CHECK_ONCE when the push change detection is used', () => {
|
||||||
var cd = _createWithoutHydrate('emptyUsingOnPushStrategy').changeDetector;
|
var cd = _createWithoutHydrate('emptyUsingOnPushStrategy').changeDetector;
|
||||||
cd.hydrate(_DEFAULT_CONTEXT, null, null);
|
cd.hydrate(_DEFAULT_CONTEXT, null, null, null);
|
||||||
|
|
||||||
expect(cd.mode).toEqual(CHECK_ONCE);
|
expect(cd.mode).toEqual(CHECK_ONCE);
|
||||||
});
|
});
|
||||||
@ -639,7 +641,7 @@ export function main() {
|
|||||||
it('should not check a detached change detector', () => {
|
it('should not check a detached change detector', () => {
|
||||||
var val = _createChangeDetector('a', new TestData('value'));
|
var val = _createChangeDetector('a', new TestData('value'));
|
||||||
|
|
||||||
val.changeDetector.hydrate(_DEFAULT_CONTEXT, null, null);
|
val.changeDetector.hydrate(_DEFAULT_CONTEXT, null, null, null);
|
||||||
val.changeDetector.mode = DETACHED;
|
val.changeDetector.mode = DETACHED;
|
||||||
val.changeDetector.detectChanges();
|
val.changeDetector.detectChanges();
|
||||||
|
|
||||||
@ -649,7 +651,7 @@ export function main() {
|
|||||||
it('should not check a checked change detector', () => {
|
it('should not check a checked change detector', () => {
|
||||||
var val = _createChangeDetector('a', new TestData('value'));
|
var val = _createChangeDetector('a', new TestData('value'));
|
||||||
|
|
||||||
val.changeDetector.hydrate(_DEFAULT_CONTEXT, null, null);
|
val.changeDetector.hydrate(_DEFAULT_CONTEXT, null, null, null);
|
||||||
val.changeDetector.mode = CHECKED;
|
val.changeDetector.mode = CHECKED;
|
||||||
val.changeDetector.detectChanges();
|
val.changeDetector.detectChanges();
|
||||||
|
|
||||||
@ -658,7 +660,7 @@ export function main() {
|
|||||||
|
|
||||||
it('should change CHECK_ONCE to CHECKED', () => {
|
it('should change CHECK_ONCE to CHECKED', () => {
|
||||||
var cd = _createChangeDetector('10').changeDetector;
|
var cd = _createChangeDetector('10').changeDetector;
|
||||||
cd.hydrate(_DEFAULT_CONTEXT, null, null);
|
cd.hydrate(_DEFAULT_CONTEXT, null, null, null);
|
||||||
cd.mode = CHECK_ONCE;
|
cd.mode = CHECK_ONCE;
|
||||||
|
|
||||||
cd.detectChanges();
|
cd.detectChanges();
|
||||||
@ -668,7 +670,7 @@ export function main() {
|
|||||||
|
|
||||||
it('should not change the CHECK_ALWAYS', () => {
|
it('should not change the CHECK_ALWAYS', () => {
|
||||||
var cd = _createChangeDetector('10').changeDetector;
|
var cd = _createChangeDetector('10').changeDetector;
|
||||||
cd.hydrate(_DEFAULT_CONTEXT, null, null);
|
cd.hydrate(_DEFAULT_CONTEXT, null, null, null);
|
||||||
cd.mode = CHECK_ALWAYS;
|
cd.mode = CHECK_ALWAYS;
|
||||||
|
|
||||||
cd.detectChanges();
|
cd.detectChanges();
|
||||||
@ -682,7 +684,7 @@ export function main() {
|
|||||||
|
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
checkedDetector = _createWithoutHydrate('emptyUsingOnPushStrategy').changeDetector;
|
checkedDetector = _createWithoutHydrate('emptyUsingOnPushStrategy').changeDetector;
|
||||||
checkedDetector.hydrate(_DEFAULT_CONTEXT, null, null);
|
checkedDetector.hydrate(_DEFAULT_CONTEXT, null, null, null);
|
||||||
checkedDetector.mode = CHECKED;
|
checkedDetector.mode = CHECKED;
|
||||||
|
|
||||||
var targetDirective = new TestData(null);
|
var targetDirective = new TestData(null);
|
||||||
@ -691,7 +693,7 @@ export function main() {
|
|||||||
|
|
||||||
it('should set the mode to CHECK_ONCE when a binding is updated', () => {
|
it('should set the mode to CHECK_ONCE when a binding is updated', () => {
|
||||||
var cd = _createWithoutHydrate('onPushRecordsUsingDefaultStrategy').changeDetector;
|
var cd = _createWithoutHydrate('onPushRecordsUsingDefaultStrategy').changeDetector;
|
||||||
cd.hydrate(_DEFAULT_CONTEXT, null, directives);
|
cd.hydrate(_DEFAULT_CONTEXT, null, directives, null);
|
||||||
|
|
||||||
expect(checkedDetector.mode).toEqual(CHECKED);
|
expect(checkedDetector.mode).toEqual(CHECKED);
|
||||||
|
|
||||||
@ -735,13 +737,13 @@ export function main() {
|
|||||||
it('should be able to rehydrate a change detector', () => {
|
it('should be able to rehydrate a change detector', () => {
|
||||||
var cd = _createChangeDetector('name').changeDetector;
|
var cd = _createChangeDetector('name').changeDetector;
|
||||||
|
|
||||||
cd.hydrate('some context', null, null);
|
cd.hydrate('some context', null, null, null);
|
||||||
expect(cd.hydrated()).toBe(true);
|
expect(cd.hydrated()).toBe(true);
|
||||||
|
|
||||||
cd.dehydrate();
|
cd.dehydrate();
|
||||||
expect(cd.hydrated()).toBe(false);
|
expect(cd.hydrated()).toBe(false);
|
||||||
|
|
||||||
cd.hydrate('other context', null, null);
|
cd.hydrate('other context', null, null, null);
|
||||||
expect(cd.hydrated()).toBe(true);
|
expect(cd.hydrated()).toBe(true);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -899,7 +899,7 @@ export function main() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('should inject ChangeDetectorRef', () => {
|
it('should inject ChangeDetectorRef', () => {
|
||||||
var cd = new DynamicChangeDetector(null, null, null, null, [], []);
|
var cd = new DynamicChangeDetector(null, null, null, [], []);
|
||||||
var view = <any>new DummyView();
|
var view = <any>new DummyView();
|
||||||
var childView = new DummyView();
|
var childView = new DummyView();
|
||||||
childView.changeDetector = cd;
|
childView.changeDetector = cd;
|
||||||
|
@ -219,24 +219,15 @@ export function main() {
|
|||||||
}));
|
}));
|
||||||
|
|
||||||
describe('pipes', () => {
|
describe('pipes', () => {
|
||||||
beforeEachBindings(() => {
|
|
||||||
return [
|
|
||||||
bind(ChangeDetection)
|
|
||||||
.toFactory(() => new DynamicChangeDetection(
|
|
||||||
new PipeRegistry({"double": [new DoublePipeFactory()]})),
|
|
||||||
[])
|
|
||||||
];
|
|
||||||
});
|
|
||||||
|
|
||||||
it("should support pipes in bindings",
|
it("should support pipes in bindings",
|
||||||
inject([TestComponentBuilder, AsyncTestCompleter],
|
inject([TestComponentBuilder, AsyncTestCompleter],
|
||||||
(tcb: TestComponentBuilder, async) => {
|
(tcb: TestComponentBuilder, async) => {
|
||||||
tcb.overrideView(MyComp, new viewAnn.View({
|
tcb.overrideView(MyCompWithPipes, new viewAnn.View({
|
||||||
template: '<div my-dir #dir="mydir" [elprop]="ctxProp | double"></div>',
|
template: '<div my-dir #dir="mydir" [elprop]="ctxProp | double"></div>',
|
||||||
directives: [MyDir]
|
directives: [MyDir]
|
||||||
}))
|
}))
|
||||||
|
|
||||||
.createAsync(MyComp)
|
.createAsync(MyCompWithPipes)
|
||||||
.then((rootTC) => {
|
.then((rootTC) => {
|
||||||
rootTC.componentInstance.ctxProp = 'a';
|
rootTC.componentInstance.ctxProp = 'a';
|
||||||
rootTC.detectChanges();
|
rootTC.detectChanges();
|
||||||
@ -1410,6 +1401,21 @@ class PushCmpWithRef {
|
|||||||
propagate() { this.ref.requestCheck(); }
|
propagate() { this.ref.requestCheck(); }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Injectable()
|
||||||
|
class PipeRegistryWithDouble extends PipeRegistry {
|
||||||
|
constructor() { super({"double": [new DoublePipeFactory()]}); }
|
||||||
|
}
|
||||||
|
|
||||||
|
@Component({
|
||||||
|
selector: 'my-comp-with-pipes',
|
||||||
|
viewInjector: [new Binding(PipeRegistry, {toClass: PipeRegistryWithDouble})]
|
||||||
|
})
|
||||||
|
@View({directives: []})
|
||||||
|
@Injectable()
|
||||||
|
class MyCompWithPipes {
|
||||||
|
ctxProp: string = "initial value";
|
||||||
|
}
|
||||||
|
|
||||||
@Component({selector: 'my-comp'})
|
@Component({selector: 'my-comp'})
|
||||||
@View({directives: []})
|
@View({directives: []})
|
||||||
@Injectable()
|
@Injectable()
|
||||||
@ -1424,13 +1430,6 @@ class MyComp {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Component({selector: 'component-with-pipes', properties: ["prop"]})
|
|
||||||
@View({template: ''})
|
|
||||||
@Injectable()
|
|
||||||
class ComponentWithPipes {
|
|
||||||
prop: string;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Component({selector: 'child-cmp', properties: ['dirProp'], viewInjector: [MyService]})
|
@Component({selector: 'child-cmp', properties: ['dirProp'], viewInjector: [MyService]})
|
||||||
@View({directives: [MyDir], template: '{{ctxProp}}'})
|
@View({directives: [MyDir], template: '{{ctxProp}}'})
|
||||||
@Injectable()
|
@Injectable()
|
||||||
|
@ -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;
|
||||||
final _gen.PipeRegistry _pipeRegistry;
|
_gen.PipeRegistry _pipeRegistry;
|
||||||
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;
|
||||||
@ -37,8 +37,8 @@ class _MyComponent_ChangeDetector0 extends _gen.AbstractChangeDetector {
|
|||||||
dynamic _myNum0 = _gen.ChangeDetectionUtil.uninitialized();
|
dynamic _myNum0 = _gen.ChangeDetectionUtil.uninitialized();
|
||||||
dynamic _interpolate1 = _gen.ChangeDetectionUtil.uninitialized();
|
dynamic _interpolate1 = _gen.ChangeDetectionUtil.uninitialized();
|
||||||
|
|
||||||
_MyComponent_ChangeDetector0(this._dispatcher, this._pipeRegistry,
|
_MyComponent_ChangeDetector0(
|
||||||
this._protos, this._directiveRecords)
|
this._dispatcher, this._protos, this._directiveRecords)
|
||||||
: super("MyComponent_comp_0");
|
: super("MyComponent_comp_0");
|
||||||
|
|
||||||
void detectChangesInRecords(throwOnChange) {
|
void detectChangesInRecords(throwOnChange) {
|
||||||
@ -100,12 +100,13 @@ class _MyComponent_ChangeDetector0 extends _gen.AbstractChangeDetector {
|
|||||||
_dispatcher.notifyOnAllChangesDone();
|
_dispatcher.notifyOnAllChangesDone();
|
||||||
}
|
}
|
||||||
|
|
||||||
void hydrate(MyComponent context, locals, directives) {
|
void hydrate(MyComponent context, locals, directives, pipeRegistry) {
|
||||||
mode = 'ALWAYS_CHECK';
|
mode = 'ALWAYS_CHECK';
|
||||||
_context = context;
|
_context = context;
|
||||||
_locals = locals;
|
_locals = locals;
|
||||||
|
|
||||||
_alreadyChecked = false;
|
_alreadyChecked = false;
|
||||||
|
_pipeRegistry = pipeRegistry;
|
||||||
}
|
}
|
||||||
|
|
||||||
void dehydrate() {
|
void dehydrate() {
|
||||||
@ -113,14 +114,14 @@ 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;
|
||||||
}
|
}
|
||||||
|
|
||||||
hydrated() => _context != null;
|
hydrated() => _context != null;
|
||||||
|
|
||||||
static _gen.ProtoChangeDetector newProtoChangeDetector(
|
static _gen.ProtoChangeDetector newProtoChangeDetector(
|
||||||
_gen.PipeRegistry registry, _gen.ChangeDetectorDefinition def) {
|
_gen.ChangeDetectorDefinition def) {
|
||||||
return new _gen.PregenProtoChangeDetector(
|
return new _gen.PregenProtoChangeDetector(
|
||||||
(a, b, c, d) => new _MyComponent_ChangeDetector0(a, b, c, d), registry,
|
(a, b, c) => new _MyComponent_ChangeDetector0(a, b, c), def);
|
||||||
def);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
{
|
{
|
||||||
"compilerOptions": {
|
"compilerOptions": {
|
||||||
"emitDecoratorMetadata": true,
|
"emitDecoratorMetadata": true,
|
||||||
|
"experimentalDecorators": true,
|
||||||
"declaration": true,
|
"declaration": true,
|
||||||
"module": "commonjs",
|
"module": "commonjs",
|
||||||
"rootDir": ".",
|
"rootDir": ".",
|
||||||
|
@ -280,10 +280,10 @@ function setUpChangeDetection(changeDetection: ChangeDetection, iterations, obje
|
|||||||
new ChangeDetectorDefinition("proto", null, [], bindings, [directiveRecord]));
|
new ChangeDetectorDefinition("proto", null, [], bindings, [directiveRecord]));
|
||||||
|
|
||||||
var targetObj = new Obj();
|
var targetObj = new Obj();
|
||||||
parentCd.hydrate(object, null, new FakeDirectives(targetObj));
|
parentCd.hydrate(object, null, new FakeDirectives(targetObj), null);
|
||||||
for (var i = 0; i < iterations; ++i) {
|
for (var i = 0; i < iterations; ++i) {
|
||||||
var cd = proto.instantiate(dispatcher);
|
var cd = proto.instantiate(dispatcher);
|
||||||
cd.hydrate(object, null, new FakeDirectives(targetObj));
|
cd.hydrate(object, null, new FakeDirectives(targetObj), null);
|
||||||
parentCd.addChild(cd);
|
parentCd.addChild(cd);
|
||||||
}
|
}
|
||||||
return parentCd;
|
return parentCd;
|
||||||
@ -332,7 +332,7 @@ export function main() {
|
|||||||
|
|
||||||
// -- DYNAMIC
|
// -- DYNAMIC
|
||||||
var ng2DynamicChangeDetector =
|
var ng2DynamicChangeDetector =
|
||||||
setUpChangeDetection(new DynamicChangeDetection(null), numberOfDetectors, object);
|
setUpChangeDetection(new DynamicChangeDetection(), numberOfDetectors, object);
|
||||||
|
|
||||||
runChangeDetectionReads(ng2DynamicChangeDetector, 1); // warmup
|
runChangeDetectionReads(ng2DynamicChangeDetector, 1); // warmup
|
||||||
|
|
||||||
@ -352,7 +352,7 @@ export function main() {
|
|||||||
// Reenable when we have transformers for Dart
|
// Reenable when we have transformers for Dart
|
||||||
if (isJsObject({})) {
|
if (isJsObject({})) {
|
||||||
var ng2JitChangeDetector =
|
var ng2JitChangeDetector =
|
||||||
setUpChangeDetection(new JitChangeDetection(null), numberOfDetectors, object);
|
setUpChangeDetection(new JitChangeDetection(), numberOfDetectors, object);
|
||||||
|
|
||||||
runChangeDetectionReads(ng2JitChangeDetector, 1); // warmup
|
runChangeDetectionReads(ng2JitChangeDetector, 1); // warmup
|
||||||
|
|
||||||
|
@ -39,9 +39,9 @@ export function main() {
|
|||||||
var shadowDomStrategy = new NativeShadowDomStrategy();
|
var shadowDomStrategy = new NativeShadowDomStrategy();
|
||||||
var renderCompiler = new rc.DefaultDomCompiler(new Parser(new Lexer()), shadowDomStrategy,
|
var renderCompiler = new rc.DefaultDomCompiler(new Parser(new Lexer()), shadowDomStrategy,
|
||||||
new ViewLoader(null, null, null));
|
new ViewLoader(null, null, null));
|
||||||
var compiler = new Compiler(
|
var compiler = new Compiler(reader, cache, viewResolver, new ComponentUrlMapper(), urlResolver,
|
||||||
reader, cache, viewResolver, new ComponentUrlMapper(), urlResolver, renderCompiler,
|
renderCompiler, new ProtoViewFactory(new DynamicChangeDetection()),
|
||||||
new ProtoViewFactory(new DynamicChangeDetection(null)), new FakeAppRootUrl());
|
new FakeAppRootUrl());
|
||||||
|
|
||||||
function measureWrapper(func, desc) {
|
function measureWrapper(func, desc) {
|
||||||
return function() {
|
return function() {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user