Skip to content

Commit 576cef1

Browse files
committed
feat(loading): add skip counter loading
1 parent 2026bfd commit 576cef1

File tree

1 file changed

+36
-3
lines changed

1 file changed

+36
-3
lines changed

src/providers/loading-ionic.ts

Lines changed: 36 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,10 @@ export class LoadingIonicPlugin implements PreRequestPlugin, PostRequestPlugin,
1111

1212
protected allowPrevious: boolean = null;
1313

14+
protected skippedCount: number = null;
15+
16+
protected countLoading: number = 0;
17+
1418
protected loadingOptions: Object = {};
1519

1620
protected originalLoadingOptions: Object;
@@ -27,20 +31,41 @@ export class LoadingIonicPlugin implements PreRequestPlugin, PostRequestPlugin,
2731

2832
preRequest() {
2933
this.originalLoadingOptions = Object.assign({}, this.loadingOptions);
34+
35+
if (this.skippedCount) {
36+
let allowPrevious = this.allow;
37+
this.allow = true;
38+
39+
if (this.countLoading !== 0) {
40+
if (this.countLoading <= this.skippedCount) {
41+
this.allow = false;
42+
} else {
43+
this.allow = this.allowPrevious;
44+
this.countLoading = 0;
45+
}
46+
} else {
47+
this.allowPrevious = allowPrevious;
48+
}
49+
50+
this.countLoading++;
51+
}
52+
3053
if (this.allow) {
3154
this.getLoading().present();
3255
}
3356
}
3457

3558
dismiss() {
36-
if (this.loading === null) {
59+
if (this.allow === false) {
3760
return;
3861
}
3962

40-
if (this.allow) {
41-
this.loading.dismiss();
63+
if (this.loading === null) {
64+
return;
4265
}
4366

67+
this.loading.dismiss();
68+
4469
// reset values
4570
this.loading = null;
4671
this.loadingOptions = this.originalLoadingOptions;
@@ -57,9 +82,17 @@ export class LoadingIonicPlugin implements PreRequestPlugin, PostRequestPlugin,
5782
}
5883

5984
postRequestError() {
85+
if (this.skippedCount) {
86+
this.allow = true; // force dismiss loading
87+
}
6088
this.dismiss();
6189
}
6290

91+
skip(count: number): this {
92+
this.skippedCount = count;
93+
return this;
94+
}
95+
6396
disableLoading(restore: boolean = false): this {
6497
if (restore === true) {
6598
this.allowPrevious = this.allow;

0 commit comments

Comments
 (0)