refactor(ChangeDetector): use View/ShadowDom & Content/LightDom consistently
This commit is contained in:
parent
5d9b1e90dc
commit
c56efc0c5f
|
@ -26,8 +26,8 @@ class _Context {
|
||||||
}
|
}
|
||||||
|
|
||||||
export class AbstractChangeDetector<T> implements ChangeDetector {
|
export class AbstractChangeDetector<T> implements ChangeDetector {
|
||||||
lightDomChildren: any[] = [];
|
contentChildren: any[] = [];
|
||||||
shadowDomChildren: any[] = [];
|
viewChildren: any[] = [];
|
||||||
parent: ChangeDetector;
|
parent: ChangeDetector;
|
||||||
ref: ChangeDetectorRef;
|
ref: ChangeDetectorRef;
|
||||||
|
|
||||||
|
@ -50,21 +50,21 @@ export class AbstractChangeDetector<T> implements ChangeDetector {
|
||||||
this.ref = new ChangeDetectorRef_(this);
|
this.ref = new ChangeDetectorRef_(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
addChild(cd: ChangeDetector): void {
|
addContentChild(cd: ChangeDetector): void {
|
||||||
this.lightDomChildren.push(cd);
|
this.contentChildren.push(cd);
|
||||||
cd.parent = this;
|
cd.parent = this;
|
||||||
}
|
}
|
||||||
|
|
||||||
removeChild(cd: ChangeDetector): void { ListWrapper.remove(this.lightDomChildren, cd); }
|
removeContentChild(cd: ChangeDetector): void { ListWrapper.remove(this.contentChildren, cd); }
|
||||||
|
|
||||||
addShadowDomChild(cd: ChangeDetector): void {
|
addViewChild(cd: ChangeDetector): void {
|
||||||
this.shadowDomChildren.push(cd);
|
this.viewChildren.push(cd);
|
||||||
cd.parent = this;
|
cd.parent = this;
|
||||||
}
|
}
|
||||||
|
|
||||||
removeShadowDomChild(cd: ChangeDetector): void { ListWrapper.remove(this.shadowDomChildren, cd); }
|
removeViewChild(cd: ChangeDetector): void { ListWrapper.remove(this.viewChildren, cd); }
|
||||||
|
|
||||||
remove(): void { this.parent.removeChild(this); }
|
remove(): void { this.parent.removeContentChild(this); }
|
||||||
|
|
||||||
handleEvent(eventName: string, elIndex: number, locals: Locals): boolean {
|
handleEvent(eventName: string, elIndex: number, locals: Locals): boolean {
|
||||||
var res = this.handleEventInternal(eventName, elIndex, locals);
|
var res = this.handleEventInternal(eventName, elIndex, locals);
|
||||||
|
@ -86,10 +86,10 @@ export class AbstractChangeDetector<T> implements ChangeDetector {
|
||||||
|
|
||||||
this.detectChangesInRecords(throwOnChange);
|
this.detectChangesInRecords(throwOnChange);
|
||||||
|
|
||||||
this._detectChangesInLightDomChildren(throwOnChange);
|
this._detectChangesContentChildren(throwOnChange);
|
||||||
if (!throwOnChange) this.afterContentLifecycleCallbacks();
|
if (!throwOnChange) this.afterContentLifecycleCallbacks();
|
||||||
|
|
||||||
this._detectChangesInShadowDomChildren(throwOnChange);
|
this._detectChangesInViewChildren(throwOnChange);
|
||||||
if (!throwOnChange) this.afterViewLifecycleCallbacks();
|
if (!throwOnChange) this.afterViewLifecycleCallbacks();
|
||||||
|
|
||||||
if (this.mode === ChangeDetectionStrategy.CheckOnce)
|
if (this.mode === ChangeDetectionStrategy.CheckOnce)
|
||||||
|
@ -130,7 +130,7 @@ export class AbstractChangeDetector<T> implements ChangeDetector {
|
||||||
|
|
||||||
// This method is not intended to be overridden. Subclasses should instead provide an
|
// This method is not intended to be overridden. Subclasses should instead provide an
|
||||||
// implementation of `hydrateDirectives`.
|
// implementation of `hydrateDirectives`.
|
||||||
hydrate(context: T, locals: Locals, directives: any, pipes: any): void {
|
hydrate(context: T, locals: Locals, directives: any, pipes: Pipes): void {
|
||||||
this.mode = ChangeDetectionUtil.changeDetectionMode(this.strategy);
|
this.mode = ChangeDetectionUtil.changeDetectionMode(this.strategy);
|
||||||
this.context = context;
|
this.context = context;
|
||||||
|
|
||||||
|
@ -183,16 +183,16 @@ export class AbstractChangeDetector<T> implements ChangeDetector {
|
||||||
afterViewLifecycleCallbacksInternal(): void {}
|
afterViewLifecycleCallbacksInternal(): void {}
|
||||||
|
|
||||||
/** @internal */
|
/** @internal */
|
||||||
_detectChangesInLightDomChildren(throwOnChange: boolean): void {
|
_detectChangesContentChildren(throwOnChange: boolean): void {
|
||||||
var c = this.lightDomChildren;
|
var c = this.contentChildren;
|
||||||
for (var i = 0; i < c.length; ++i) {
|
for (var i = 0; i < c.length; ++i) {
|
||||||
c[i].runDetectChanges(throwOnChange);
|
c[i].runDetectChanges(throwOnChange);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/** @internal */
|
/** @internal */
|
||||||
_detectChangesInShadowDomChildren(throwOnChange: boolean): void {
|
_detectChangesInViewChildren(throwOnChange: boolean): void {
|
||||||
var c = this.shadowDomChildren;
|
var c = this.viewChildren;
|
||||||
for (var i = 0; i < c.length; ++i) {
|
for (var i = 0; i < c.length; ++i) {
|
||||||
c[i].runDetectChanges(throwOnChange);
|
c[i].runDetectChanges(throwOnChange);
|
||||||
}
|
}
|
||||||
|
|
|
@ -47,7 +47,6 @@ export class BindingRecord {
|
||||||
return isBlank(this.directiveRecord) || this.directiveRecord.isDefaultChangeDetection();
|
return isBlank(this.directiveRecord) || this.directiveRecord.isDefaultChangeDetection();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static createDirectiveDoCheck(directiveRecord: DirectiveRecord): BindingRecord {
|
static createDirectiveDoCheck(directiveRecord: DirectiveRecord): BindingRecord {
|
||||||
return new BindingRecord(DIRECTIVE_LIFECYCLE, null, 0, null, null, "DoCheck", directiveRecord);
|
return new BindingRecord(DIRECTIVE_LIFECYCLE, null, 0, null, null, "DoCheck", directiveRecord);
|
||||||
}
|
}
|
||||||
|
|
|
@ -23,7 +23,7 @@ export const CONTEXT_ACCESSOR = "context";
|
||||||
export const CONTEXT_INDEX = 0;
|
export const CONTEXT_INDEX = 0;
|
||||||
const _FIELD_PREFIX = 'this.';
|
const _FIELD_PREFIX = 'this.';
|
||||||
|
|
||||||
var _whiteSpaceRegExp = RegExpWrapper.create("\\W", "g");
|
var _whiteSpaceRegExp = /\W/g;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns `s` with all non-identifier characters removed.
|
* Returns `s` with all non-identifier characters removed.
|
||||||
|
|
|
@ -22,10 +22,10 @@ export interface ChangeDetector {
|
||||||
mode: ChangeDetectionStrategy;
|
mode: ChangeDetectionStrategy;
|
||||||
ref: ChangeDetectorRef;
|
ref: ChangeDetectorRef;
|
||||||
|
|
||||||
addChild(cd: ChangeDetector): void;
|
addContentChild(cd: ChangeDetector): void;
|
||||||
addShadowDomChild(cd: ChangeDetector): void;
|
addViewChild(cd: ChangeDetector): void;
|
||||||
removeChild(cd: ChangeDetector): void;
|
removeContentChild(cd: ChangeDetector): void;
|
||||||
removeShadowDomChild(cd: ChangeDetector): void;
|
removeViewChild(cd: ChangeDetector): void;
|
||||||
remove(): void;
|
remove(): void;
|
||||||
hydrate(context: any, locals: Locals, directives: any, pipes: any): void;
|
hydrate(context: any, locals: Locals, directives: any, pipes: any): void;
|
||||||
dehydrate(): void;
|
dehydrate(): void;
|
||||||
|
|
|
@ -102,7 +102,7 @@ export class AppViewManagerUtils {
|
||||||
currentView.init(protoView.changeDetectorFactory(currentView), elementInjectors,
|
currentView.init(protoView.changeDetectorFactory(currentView), elementInjectors,
|
||||||
rootElementInjectors, preBuiltObjects, views, elementRefs, viewContainers);
|
rootElementInjectors, preBuiltObjects, views, elementRefs, viewContainers);
|
||||||
if (isPresent(parentView) && protoView.type === viewModule.ViewType.COMPONENT) {
|
if (isPresent(parentView) && protoView.type === viewModule.ViewType.COMPONENT) {
|
||||||
parentView.changeDetector.addShadowDomChild(currentView.changeDetector);
|
parentView.changeDetector.addViewChild(currentView.changeDetector);
|
||||||
}
|
}
|
||||||
elementOffset += protoView.elementBinders.length;
|
elementOffset += protoView.elementBinders.length;
|
||||||
textOffset += protoView.textBindingCount;
|
textOffset += protoView.textBindingCount;
|
||||||
|
@ -122,7 +122,7 @@ export class AppViewManagerUtils {
|
||||||
contextView = parentView;
|
contextView = parentView;
|
||||||
contextBoundElementIndex = boundElementIndex;
|
contextBoundElementIndex = boundElementIndex;
|
||||||
}
|
}
|
||||||
parentView.changeDetector.addChild(view.changeDetector);
|
parentView.changeDetector.addContentChild(view.changeDetector);
|
||||||
var viewContainer = parentView.viewContainers[boundElementIndex];
|
var viewContainer = parentView.viewContainers[boundElementIndex];
|
||||||
if (isBlank(viewContainer)) {
|
if (isBlank(viewContainer)) {
|
||||||
viewContainer = new viewModule.AppViewContainer();
|
viewContainer = new viewModule.AppViewContainer();
|
||||||
|
|
|
@ -634,7 +634,7 @@ export function main() {
|
||||||
it('should be called before processing view children', () => {
|
it('should be called before processing view children', () => {
|
||||||
var parent = _createWithoutHydrate('directNoDispatcher').changeDetector;
|
var parent = _createWithoutHydrate('directNoDispatcher').changeDetector;
|
||||||
var child = _createWithoutHydrate('directNoDispatcher').changeDetector;
|
var child = _createWithoutHydrate('directNoDispatcher').changeDetector;
|
||||||
parent.addShadowDomChild(child);
|
parent.addViewChild(child);
|
||||||
|
|
||||||
var orderOfOperations = [];
|
var orderOfOperations = [];
|
||||||
|
|
||||||
|
@ -753,7 +753,7 @@ export function main() {
|
||||||
it('should be called after processing view children', () => {
|
it('should be called after processing view children', () => {
|
||||||
var parent = _createWithoutHydrate('directNoDispatcher').changeDetector;
|
var parent = _createWithoutHydrate('directNoDispatcher').changeDetector;
|
||||||
var child = _createWithoutHydrate('directNoDispatcher').changeDetector;
|
var child = _createWithoutHydrate('directNoDispatcher').changeDetector;
|
||||||
parent.addShadowDomChild(child);
|
parent.addViewChild(child);
|
||||||
|
|
||||||
var orderOfOperations = [];
|
var orderOfOperations = [];
|
||||||
|
|
||||||
|
@ -902,32 +902,32 @@ export function main() {
|
||||||
child = _createChangeDetector('"str"').changeDetector;
|
child = _createChangeDetector('"str"').changeDetector;
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should add light dom children', () => {
|
it('should add content children', () => {
|
||||||
parent.addChild(child);
|
parent.addContentChild(child);
|
||||||
|
|
||||||
expect(parent.lightDomChildren.length).toEqual(1);
|
expect(parent.contentChildren.length).toEqual(1);
|
||||||
expect(parent.lightDomChildren[0]).toBe(child);
|
expect(parent.contentChildren[0]).toBe(child);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should add shadow dom children', () => {
|
it('should add view children', () => {
|
||||||
parent.addShadowDomChild(child);
|
parent.addViewChild(child);
|
||||||
|
|
||||||
expect(parent.shadowDomChildren.length).toEqual(1);
|
expect(parent.viewChildren.length).toEqual(1);
|
||||||
expect(parent.shadowDomChildren[0]).toBe(child);
|
expect(parent.viewChildren[0]).toBe(child);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should remove light dom children', () => {
|
it('should remove content children', () => {
|
||||||
parent.addChild(child);
|
parent.addContentChild(child);
|
||||||
parent.removeChild(child);
|
parent.removeContentChild(child);
|
||||||
|
|
||||||
expect(parent.lightDomChildren).toEqual([]);
|
expect(parent.contentChildren).toEqual([]);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should remove shadow dom children', () => {
|
it('should remove view children', () => {
|
||||||
parent.addShadowDomChild(child);
|
parent.addViewChild(child);
|
||||||
parent.removeShadowDomChild(child);
|
parent.removeViewChild(child);
|
||||||
|
|
||||||
expect(parent.shadowDomChildren.length).toEqual(0);
|
expect(parent.viewChildren.length).toEqual(0);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -1142,7 +1142,7 @@ export function main() {
|
||||||
function changeDetector(mode, parent) {
|
function changeDetector(mode, parent) {
|
||||||
var val = _createChangeDetector('10');
|
var val = _createChangeDetector('10');
|
||||||
val.changeDetector.mode = mode;
|
val.changeDetector.mode = mode;
|
||||||
if (isPresent(parent)) parent.addChild(val.changeDetector);
|
if (isPresent(parent)) parent.addContentChild(val.changeDetector);
|
||||||
return val.changeDetector;
|
return val.changeDetector;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -285,7 +285,7 @@ function setUpChangeDetection(protoChangeDetectorFactory: Function, iterations,
|
||||||
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), null);
|
cd.hydrate(object, null, new FakeDirectives(targetObj), null);
|
||||||
parentCd.addChild(cd);
|
parentCd.addContentChild(cd);
|
||||||
}
|
}
|
||||||
return parentCd;
|
return parentCd;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue