Skip to content
This repository was archived by the owner on Jan 6, 2025. It is now read-only.

Commit bc7f77f

Browse files
authored
perf: remove duplicate function calls (#773)
* remove duplicate initialization calls in most directives * remove `getDisplayStyle` call from BaseDirective `ngOnInit` Fixes #761
1 parent 4fb0979 commit bc7f77f

File tree

7 files changed

+7
-20
lines changed

7 files changed

+7
-20
lines changed

src/lib/core/base/base.ts

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,6 @@ export abstract class BaseDirective implements OnDestroy, OnChanges {
8080
* querying such as computed Display style
8181
*/
8282
ngOnInit() {
83-
this._display = this._getDisplayStyle();
8483
this._hasInitialized = true;
8584
}
8685

@@ -227,9 +226,6 @@ export abstract class BaseDirective implements OnDestroy, OnChanges {
227226
return this._hasInitialized;
228227
}
229228

230-
/** Original dom Elements CSS display style */
231-
protected _display;
232-
233229
/** MediaQuery Activation Tracker */
234230
protected _mqActivation: ResponsiveActivation;
235231

src/lib/extended/show-hide/show-hide.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,9 @@ export class ShowHideDirective extends BaseDirective implements OnInit, OnChange
6767
*/
6868
protected _layoutWatcher: Subscription;
6969

70+
/** Original dom Elements CSS display style */
71+
protected _display: string;
72+
7073
/* tslint:disable */
7174
@Input('fxShow') set show(val) { this._cacheInput('show', val); }
7275
@Input('fxShow.xs') set showXs(val) {this._cacheInput('showXs', val);}
@@ -101,11 +104,8 @@ export class ShowHideDirective extends BaseDirective implements OnInit, OnChange
101104
@Input('fxHide.gt-sm') set hideGtSm(val) {this._cacheInput('showGtSm', negativeOf(val)); };
102105
@Input('fxHide.gt-md') set hideGtMd(val) {this._cacheInput('showGtMd', negativeOf(val)); };
103106
@Input('fxHide.gt-lg') set hideGtLg(val) {this._cacheInput('showGtLg', negativeOf(val)); };
104-
105107
/* tslint:enable */
106-
/**
107-
*
108-
*/
108+
109109
constructor(monitor: MediaMonitor,
110110
@Optional() @Self() protected layout: LayoutDirective,
111111
protected elRef: ElementRef,
@@ -155,6 +155,7 @@ export class ShowHideDirective extends BaseDirective implements OnInit, OnChange
155155
*/
156156
ngOnInit() {
157157
super.ngOnInit();
158+
this._display = this._getDisplayStyle();
158159

159160
let value = this._getDefaultVal('show', true);
160161
// Build _mqActivation controller

src/lib/flex/flex-align/flex-align.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,6 @@ export class FlexAlignDirective extends BaseDirective implements OnInit, OnChang
8181
this._listenForMediaQueryChanges('align', 'stretch', (changes: MediaChange) => {
8282
this._updateWithValue(changes.value);
8383
});
84-
this._updateWithValue();
8584
}
8685

8786
// *********************************************

src/lib/flex/flex-order/flex-order.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,6 @@ export class FlexOrderDirective extends BaseDirective implements OnInit, OnChang
7878
this._listenForMediaQueryChanges('order', '0', (changes: MediaChange) => {
7979
this._updateWithValue(changes.value);
8080
});
81-
this._updateWithValue();
8281
}
8382

8483
// *********************************************

src/lib/flex/flex/flex.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,6 @@ export class FlexDirective extends BaseDirective implements OnInit, OnChanges, O
116116
this._listenForMediaQueryChanges('flex', '', (changes: MediaChange) => {
117117
this._updateStyle(changes.value);
118118
});
119-
this._updateStyle();
120119

121120
if (this._container) {
122121
// If this flex item is inside of a flex container marked with

src/lib/flex/layout-align/layout-align.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,6 @@ export class LayoutAlignDirective extends BaseDirective implements OnInit, OnCha
9494
this._listenForMediaQueryChanges('align', 'start stretch', (changes: MediaChange) => {
9595
this._updateWithValue(changes.value);
9696
});
97-
this._updateWithValue();
9897
}
9998

10099
ngOnDestroy() {

src/lib/flex/layout/layout.ts

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -68,11 +68,8 @@ export class LayoutDirective extends BaseDirective implements OnInit, OnChanges,
6868
@Input('fxLayout.lt-md') set layoutLtMd(val) { this._cacheInput('layoutLtMd', val); };
6969
@Input('fxLayout.lt-lg') set layoutLtLg(val) { this._cacheInput('layoutLtLg', val); };
7070
@Input('fxLayout.lt-xl') set layoutLtXl(val) { this._cacheInput('layoutLtXl', val); };
71-
7271
/* tslint:enable */
73-
/**
74-
*
75-
*/
72+
7673
constructor(monitor: MediaMonitor,
7774
elRef: ElementRef,
7875
styleUtils: StyleUtils) {
@@ -106,16 +103,13 @@ export class LayoutDirective extends BaseDirective implements OnInit, OnChanges,
106103
this._listenForMediaQueryChanges('layout', 'row', (changes: MediaChange) => {
107104
this._updateWithDirection(changes.value);
108105
});
109-
this._updateWithDirection();
110106
}
111107

112108
// *********************************************
113109
// Protected methods
114110
// *********************************************
115111

116-
/**
117-
* Validate the direction value and then update the host's inline flexbox styles
118-
*/
112+
/** Validate the direction value and then update the host's inline flexbox styles */
119113
protected _updateWithDirection(value?: string) {
120114
value = value || this._queryInput('layout') || 'row';
121115
if (this._mqActivation) {

0 commit comments

Comments
 (0)