refactor(ivy): remove usage of Proxy for IE10/11 compatibility (#34328)
PR Close #34328
This commit is contained in:
parent
b405942b0c
commit
a781800276
|
@ -957,7 +957,7 @@ describe('AppComponent', () => {
|
||||||
triggerDocViewerEvent('docRendered');
|
triggerDocViewerEvent('docRendered');
|
||||||
fixture.detectChanges();
|
fixture.detectChanges();
|
||||||
expect(component.isTransitioning).toBe(false);
|
expect(component.isTransitioning).toBe(false);
|
||||||
expect(toolbar.classes['transitioning']).toBe(false);
|
expect(toolbar.classes['transitioning']).toBeFalsy();
|
||||||
|
|
||||||
// While a document is being rendered, `isTransitoning` is set to true.
|
// While a document is being rendered, `isTransitoning` is set to true.
|
||||||
triggerDocViewerEvent('docReady');
|
triggerDocViewerEvent('docReady');
|
||||||
|
@ -968,7 +968,7 @@ describe('AppComponent', () => {
|
||||||
triggerDocViewerEvent('docRendered');
|
triggerDocViewerEvent('docRendered');
|
||||||
fixture.detectChanges();
|
fixture.detectChanges();
|
||||||
expect(component.isTransitioning).toBe(false);
|
expect(component.isTransitioning).toBe(false);
|
||||||
expect(toolbar.classes['transitioning']).toBe(false);
|
expect(toolbar.classes['transitioning']).toBeFalsy();
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should update the sidenav state as soon as a new document is inserted (but not before)', () => {
|
it('should update the sidenav state as soon as a new document is inserted (but not before)', () => {
|
||||||
|
|
|
@ -18,9 +18,6 @@ import {getComponentLViewByIndex, getNativeByTNodeOrNull} from '../render3/util/
|
||||||
import {assertDomNode} from '../util/assert';
|
import {assertDomNode} from '../util/assert';
|
||||||
import {DebugContext} from '../view/index';
|
import {DebugContext} from '../view/index';
|
||||||
|
|
||||||
import {createProxy} from './proxy';
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @publicApi
|
* @publicApi
|
||||||
|
@ -204,6 +201,7 @@ function _queryNodeChildren(
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class DebugNode__POST_R3__ implements DebugNode {
|
class DebugNode__POST_R3__ implements DebugNode {
|
||||||
readonly nativeNode: Node;
|
readonly nativeNode: Node;
|
||||||
|
|
||||||
|
@ -348,35 +346,14 @@ class DebugElement__POST_R3__ extends DebugNode__POST_R3__ implements DebugEleme
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
private _classesProxy !: {};
|
|
||||||
get classes(): {[key: string]: boolean;} {
|
get classes(): {[key: string]: boolean;} {
|
||||||
if (!this._classesProxy) {
|
const result: {[key: string]: boolean;} = {};
|
||||||
const element = this.nativeElement;
|
const element = this.nativeElement as HTMLElement;
|
||||||
|
const classNames = element.className.split(' ');
|
||||||
|
|
||||||
// we use a proxy here because VE code expects `.classes` to keep
|
classNames.forEach((value: string) => result[value] = true);
|
||||||
// track of which classes have been added and removed. Because we
|
|
||||||
// do not make use of a debug renderer anymore, the return value
|
return result;
|
||||||
// must always be `false` in the event that a class does not exist
|
|
||||||
// on the element (even if it wasn't added and removed beforehand).
|
|
||||||
this._classesProxy = createProxy({
|
|
||||||
get(target: {}, prop: string) {
|
|
||||||
return element ? element.classList.contains(prop) : false;
|
|
||||||
},
|
|
||||||
set(target: {}, prop: string, value: any) {
|
|
||||||
return element ? element.classList.toggle(prop, !!value) : false;
|
|
||||||
},
|
|
||||||
ownKeys() { return element ? Array.from(element.classList).sort() : []; },
|
|
||||||
getOwnPropertyDescriptor(k: any) {
|
|
||||||
// we use a special property descriptor here so that enumeration operations
|
|
||||||
// such as `Object.keys` will work on this proxy.
|
|
||||||
return {
|
|
||||||
enumerable: true,
|
|
||||||
configurable: true,
|
|
||||||
};
|
|
||||||
},
|
|
||||||
});
|
|
||||||
}
|
|
||||||
return this._classesProxy;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
get childNodes(): DebugNode[] {
|
get childNodes(): DebugNode[] {
|
||||||
|
|
|
@ -2238,9 +2238,9 @@ describe('styling', () => {
|
||||||
constructor(public elementRef: ElementRef, public renderer: Renderer2) { dirInstance = this; }
|
constructor(public elementRef: ElementRef, public renderer: Renderer2) { dirInstance = this; }
|
||||||
|
|
||||||
setStyles() {
|
setStyles() {
|
||||||
this.renderer.setStyle(
|
const nativeEl = this.elementRef.nativeElement;
|
||||||
this.elementRef.nativeElement, 'transform', 'translate3d(0px, 0px, 0px)');
|
this.renderer.setStyle(nativeEl, 'transform', 'translate3d(0px, 0px, 0px)');
|
||||||
this.renderer.addClass(this.elementRef.nativeElement, 'my-class');
|
this.renderer.addClass(nativeEl, 'my-class');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2258,16 +2258,6 @@ describe('styling', () => {
|
||||||
const div = fixture.debugElement.children[0];
|
const div = fixture.debugElement.children[0];
|
||||||
expect(div.styles.transform).toMatch(/translate3d\(0px\s*,\s*0px\s*,\s*0px\)/);
|
expect(div.styles.transform).toMatch(/translate3d\(0px\s*,\s*0px\s*,\s*0px\)/);
|
||||||
expect(div.classes['my-class']).toBe(true);
|
expect(div.classes['my-class']).toBe(true);
|
||||||
|
|
||||||
div.classes['other-class'] = true;
|
|
||||||
div.styles['width'] = '200px';
|
|
||||||
expect(div.styles.width).toEqual('200px');
|
|
||||||
expect(div.classes['other-class']).toBe(true);
|
|
||||||
|
|
||||||
if (ivyEnabled) {
|
|
||||||
expect(div.nativeElement.classList.contains('other-class')).toBeTruthy();
|
|
||||||
expect(div.nativeElement.style['width']).toEqual('200px');
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should not set classes when falsy value is passed while a sanitizer is present', () => {
|
it('should not set classes when falsy value is passed while a sanitizer is present', () => {
|
||||||
|
|
|
@ -354,7 +354,7 @@ class TestCmptWithPropInterpolation {
|
||||||
const bankElem = fixture.debugElement.children[0];
|
const bankElem = fixture.debugElement.children[0];
|
||||||
|
|
||||||
expect(bankElem.classes['closed']).toBe(true);
|
expect(bankElem.classes['closed']).toBe(true);
|
||||||
expect(bankElem.classes['open']).toBe(false);
|
expect(bankElem.classes['open']).toBeFalsy();
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should get element classes from host bindings', () => {
|
it('should get element classes from host bindings', () => {
|
||||||
|
@ -365,7 +365,7 @@ class TestCmptWithPropInterpolation {
|
||||||
expect(debugElement.classes['present-class'])
|
expect(debugElement.classes['present-class'])
|
||||||
.toBe(true, 'Expected bound host CSS class "present-class" to be present');
|
.toBe(true, 'Expected bound host CSS class "present-class" to be present');
|
||||||
expect(debugElement.classes['absent-class'])
|
expect(debugElement.classes['absent-class'])
|
||||||
.toBe(false, 'Expected bound host CSS class "absent-class" to be absent');
|
.toBeFalsy('Expected bound host CSS class "absent-class" to be absent');
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should list element styles', () => {
|
it('should list element styles', () => {
|
||||||
|
|
Loading…
Reference in New Issue