Skip to content

Commit ca9ec3e

Browse files
authored
perf(angular): proxy fast properties (#16888)
* perf(angular): proxy fast properties * update stencil
1 parent 8b14030 commit ca9ec3e

File tree

6 files changed

+400
-388
lines changed

6 files changed

+400
-388
lines changed

angular/src/directives/proxies.ts

Lines changed: 372 additions & 333 deletions
Large diffs are not rendered by default.

angular/src/directives/virtual-scroll/virtual-scroll.ts

Lines changed: 19 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ export declare interface IonVirtualScroll {
3131
export class IonVirtualScroll {
3232

3333
private differ?: IterableDiffer<any>;
34-
private nativeEl: HTMLIonVirtualScrollElement;
34+
private el: HTMLIonVirtualScrollElement;
3535
private refMap = new WeakMap<HTMLElement, EmbeddedViewRef<VirtualContext>> ();
3636

3737
@ContentChild(VirtualItem) itmTmp!: VirtualItem;
@@ -122,23 +122,8 @@ export class IonVirtualScroll {
122122
private iterableDiffers: IterableDiffers,
123123
elementRef: ElementRef,
124124
) {
125-
this.nativeEl = elementRef.nativeElement as HTMLIonVirtualScrollElement;
126-
this.nativeEl.nodeRender = this.nodeRender.bind(this);
127-
128-
proxyInputs(this, this.nativeEl, [
129-
'approxItemHeight',
130-
'approxHeaderHeight',
131-
'approxFooterHeight',
132-
'headerFn',
133-
'footerFn',
134-
'items',
135-
'itemHeight'
136-
]);
137-
proxyMethods(this, this.nativeEl, [
138-
'checkEnd',
139-
'checkRange',
140-
'positionForItem'
141-
]);
125+
this.el = elementRef.nativeElement as HTMLIonVirtualScrollElement;
126+
this.el.nodeRender = this.nodeRender.bind(this);
142127
}
143128

144129
ngOnChanges(changes: SimpleChanges): void {
@@ -208,3 +193,19 @@ function getElement(view: EmbeddedViewRef<VirtualContext>): HTMLElement {
208193
}
209194
throw new Error('virtual element was not created');
210195
}
196+
197+
proxyInputs(IonVirtualScroll, [
198+
'approxItemHeight',
199+
'approxHeaderHeight',
200+
'approxFooterHeight',
201+
'headerFn',
202+
'footerFn',
203+
'items',
204+
'itemHeight'
205+
]);
206+
207+
proxyMethods(IonVirtualScroll, [
208+
'checkEnd',
209+
'checkRange',
210+
'positionForItem'
211+
]);

angular/src/providers/platform.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@ import { Injectable } from '@angular/core';
22
import { BackButtonDetail, Platforms, getPlatforms, isPlatform } from '@ionic/core';
33
import { Subject, Subscription } from 'rxjs';
44

5-
import { proxyEvent } from '../util/util';
6-
75
export interface BackButtonEmitter extends Subject<BackButtonDetail> {
86
subscribeWithPriority(priority: number, callback: () => Promise<any> | void): Subscription;
97
}
@@ -177,3 +175,10 @@ function readQueryParam(url: string, key: string) {
177175
const results = regex.exec(url);
178176
return results ? decodeURIComponent(results[1].replace(/\+/g, ' ')) : null;
179177
}
178+
179+
function proxyEvent<T>(emitter: Subject<T>, el: EventTarget, eventName: string) {
180+
el.addEventListener(eventName, (ev: Event | undefined | null) => {
181+
// ?? cordova might emit "null" events
182+
emitter.next(ev != null ? (ev as any).detail as T : undefined);
183+
});
184+
}

angular/src/util/overlay.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { proxyMethod } from '../util/util';
1+
import { proxyMethod } from './util';
22

33
export class OverlayBaseController<Opts, Overlay> {
44
constructor(private ctrl: string) {}

angular/src/util/util.ts

Lines changed: 0 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,3 @@
1-
import { ElementRef } from '@angular/core';
2-
import { Subject } from 'rxjs';
3-
4-
export function inputs(instance: any, el: ElementRef, props: string[]) {
5-
props.forEach(propName => {
6-
Object.defineProperty(instance, propName, {
7-
get: () => el.nativeElement[propName], set: (val: any) => el.nativeElement[propName] = val
8-
});
9-
});
10-
}
11-
12-
export function proxyEvent<T>(emitter: Subject<T>, el: EventTarget, eventName: string) {
13-
el.addEventListener(eventName, (ev: Event | undefined | null) => {
14-
// ?? cordova might emit "null" events
15-
emitter.next(ev != null ? (ev as any).detail as T : undefined);
16-
});
17-
}
181

192
export function proxyMethod(ctrlName: string, methodName: string, ...args: any[]) {
203
const controller = ensureElementInBody(ctrlName);
@@ -30,19 +13,3 @@ export function ensureElementInBody(elementName: string) {
3013
}
3114
return element as HTMLStencilElement;
3215
}
33-
34-
export function deepEqual(x: any, y: any) {
35-
if (x === y) {
36-
return true;
37-
} else if (typeof x === 'object' && x != null && (typeof y === 'object' && y != null)) {
38-
if (Object.keys(x).length !== Object.keys(y).length) { return false; }
39-
40-
for (const prop in x) {
41-
if (y.hasOwnProperty(prop)) {
42-
if (!deepEqual(x[prop], y[prop])) { return false; }
43-
} else { return false; }
44-
}
45-
46-
return true;
47-
} else { return false; }
48-
}

core/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
"ionicons": "4.5.1"
3131
},
3232
"devDependencies": {
33-
"@stencil/core": "0.16.1",
33+
"@stencil/core": "0.16.2-0",
3434
"@stencil/sass": "0.1.1",
3535
"@stencil/utils": "latest",
3636
"@types/jest": "^23.3.1",

0 commit comments

Comments
 (0)