Skip to content
This repository was archived by the owner on Oct 7, 2020. It is now read-only.

Commit cdf889c

Browse files
authored
fix(linear-progress): Throws exception using Ivy (#2112)
closes #2108
1 parent ec8183e commit cdf889c

File tree

2 files changed

+59
-27
lines changed

2 files changed

+59
-27
lines changed

packages/linear-progress/linear-progress.ts

Lines changed: 48 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,9 @@ import {
44
Component,
55
ElementRef,
66
Input,
7+
OnChanges,
78
OnInit,
9+
SimpleChanges,
810
ViewEncapsulation
911
} from '@angular/core';
1012
import {Platform} from '@angular/cdk/platform';
@@ -38,9 +40,11 @@ import {strings, MDCLinearProgressFoundation, MDCLinearProgressAdapter} from '@m
3840
changeDetection: ChangeDetectionStrategy.OnPush
3941
})
4042
export class MdcLinearProgress extends MDCComponent<MDCLinearProgressFoundation>
41-
implements MDCProgressIndicator, OnInit {
43+
implements MDCProgressIndicator, OnChanges, OnInit {
4244
_root!: Element;
4345

46+
private _initialized: boolean = false;
47+
4448
/* Label indicating how the progress bar should be announced to the user. */
4549
@Input() label?: string = undefined;
4650

@@ -50,8 +54,6 @@ export class MdcLinearProgress extends MDCComponent<MDCLinearProgressFoundation>
5054
}
5155
set progress(value: number) {
5256
this._progress = coerceNumberProperty(value);
53-
this._foundation.setProgress(this._progress);
54-
this._changeDetectorRef.markForCheck();
5557
}
5658
private _progress = 0;
5759

@@ -61,8 +63,6 @@ export class MdcLinearProgress extends MDCComponent<MDCLinearProgressFoundation>
6163
}
6264
set determinate(value: boolean) {
6365
this._determinate = coerceBooleanProperty(value);
64-
this._foundation.setDeterminate(this._determinate);
65-
this._changeDetectorRef.markForCheck();
6666
}
6767
private _determinate = false;
6868

@@ -72,8 +72,6 @@ export class MdcLinearProgress extends MDCComponent<MDCLinearProgressFoundation>
7272
}
7373
set buffer(value: number) {
7474
this._buffer = coerceNumberProperty(value);
75-
this._foundation.setBuffer(this._buffer);
76-
this._changeDetectorRef.markForCheck();
7775
}
7876
private _buffer = 0;
7977

@@ -83,8 +81,7 @@ export class MdcLinearProgress extends MDCComponent<MDCLinearProgressFoundation>
8381
}
8482
set reversed(value: boolean) {
8583
this._reversed = coerceBooleanProperty(value);
86-
this._foundation.setReverse(this._reversed);
87-
this._changeDetectorRef.markForCheck();
84+
this._syncReversedWithFoundation();
8885
}
8986
private _reversed = false;
9087

@@ -113,13 +110,34 @@ export class MdcLinearProgress extends MDCComponent<MDCLinearProgressFoundation>
113110

114111
ngOnInit(): void {
115112
if (this._platform.isBrowser) {
116-
this._asyncInitializeFoundation()
117-
.then(() => {
118-
this.progress = this._progress;
119-
this.buffer = this._buffer;
120-
this.determinate = this._determinate;
121-
this._changeDetectorRef.markForCheck();
122-
});
113+
this._initialized = true;
114+
115+
this._foundation.init();
116+
this._syncProgressWithFoundation();
117+
this._syncBufferWithFoundation();
118+
this._syncDeterminateWithFoundation();
119+
this._syncReversedWithFoundation();
120+
121+
this._changeDetectorRef.markForCheck();
122+
}
123+
}
124+
125+
ngOnChanges(changes: SimpleChanges) {
126+
if (!this._initialized) {
127+
return;
128+
}
129+
130+
if (changes['progress']) {
131+
this._syncProgressWithFoundation();
132+
}
133+
if (changes['buffer']) {
134+
this._syncBufferWithFoundation();
135+
}
136+
if (changes['determinate']) {
137+
this._syncDeterminateWithFoundation();
138+
}
139+
if (changes['reversed']) {
140+
this._syncReversedWithFoundation();
123141
}
124142
}
125143

@@ -131,7 +149,19 @@ export class MdcLinearProgress extends MDCComponent<MDCLinearProgressFoundation>
131149
this._foundation.close();
132150
}
133151

134-
async _asyncInitializeFoundation(): Promise<void> {
135-
this._foundation.init();
152+
private _syncProgressWithFoundation(): void {
153+
this._foundation.setProgress(this.progress);
154+
}
155+
156+
private _syncBufferWithFoundation(): void {
157+
this._foundation.setBuffer(this.buffer);
158+
}
159+
160+
private _syncDeterminateWithFoundation(): void {
161+
this._foundation.setDeterminate(this.determinate);
162+
}
163+
164+
private _syncReversedWithFoundation(): void {
165+
this._foundation.setReverse(this.reversed);
136166
}
137167
}

test/linear-progress/linear-progress.test.ts

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -65,25 +65,25 @@ describe('MdcLinearProgress', () => {
6565
});
6666

6767
it('#should set buffer to value', () => {
68-
testInstance.buffer = 50;
68+
testComponent.buffer = 50;
6969
fixture.detectChanges();
7070
expect(testInstance.buffer).toBe(50);
7171
});
7272

7373
it('#should set progress to value', () => {
74-
testInstance.progress = 20;
74+
testComponent.progress = 20;
7575
fixture.detectChanges();
7676
expect(testInstance.progress).toBe(20);
7777
});
7878

7979
it('#should not apply indeterminate class', () => {
80-
testInstance.determinate = true;
80+
testComponent.determinate = true;
8181
fixture.detectChanges();
8282
expect(testDebugElement.nativeElement.classList.contains('mdc-linear-progress--indeterminate')).toBe(false);
8383
});
8484

85-
it('#should not apply reverse class', () => {
86-
testInstance.reversed = true;
85+
it('#should apply reverse class', () => {
86+
testComponent.reversed = true;
8787
fixture.detectChanges();
8888
expect(testDebugElement.nativeElement.classList.contains('mdc-linear-progress--reversed')).toBe(true);
8989
expect(testInstance.reversed).toBe(true);
@@ -102,14 +102,16 @@ describe('MdcLinearProgress', () => {
102102
<mdc-linear-progress
103103
[reversed]="reversed"
104104
[label]="label"
105-
[progress]="0.5"
106-
[buffer]="0.75"
105+
[progress]="progress"
106+
[buffer]="buffer"
107107
[determinate]="determinate">
108108
</mdc-linear-progress>
109109
`,
110110
})
111111
class SimpleTest {
112-
reversed: boolean = false;
113-
determinate: boolean = false;
112+
reversed: boolean;
113+
determinate: boolean;
114+
buffer = 0.75;
115+
progress = 0.5;
114116
label: string;
115117
}

0 commit comments

Comments
 (0)