Skip to content

Commit 491f486

Browse files
committed
fix(core): Change DetectionStrategy to OnPush
1 parent ad75e24 commit 491f486

File tree

3 files changed

+17
-9
lines changed

3 files changed

+17
-9
lines changed

README.md

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ Available spinners:
2222
* Show foreground loader with **progress bar**
2323
* The page content can be **blurred/frosted** while showing foreground loader. See [NgxUiLoaderBlurred](https://github.com/t-ho/ngx-ui-loader/wiki/NgxUiLoaderBlurred-directive) directive for more details
2424
* Show loader with different id for different tasks
25-
* Be able to add **logo**, **loading text**
25+
* Be able to add **logo** and **loading text**
2626
* Be able to change position of spinners, logo and loading text
2727
* Be able to change color and size of logo, spinners and progress bar
2828
* Be able to change the direction of progress bar
@@ -37,10 +37,6 @@ Live demo [here](https://ngx-ui-loader.stackblitz.io).
3737

3838
Multiple loaders demo [here](https://ngx-ui-loader.stackblitz.io/multiloader).
3939

40-
Minimal setup [here](https://stackblitz.com/edit/ngx-ui-loader-minimal-setup) on Stackblitz.
41-
42-
Simple setup for multiple loaders [here](https://stackblitz.com/edit/ngx-ui-loader-multiloader-simple-setup) on Stackblitz.
43-
4440
Live demo source code [here](https://stackblitz.com/edit/ngx-ui-loader) on Stackblitz.
4541

4642
## Installation
@@ -59,6 +55,8 @@ $ npm install --save ngx-ui-loader
5955
$ yarn add ngx-ui-loader
6056
```
6157

58+
*Please read [wiki page](https://github.com/t-ho/ngx-ui-loader/wiki) for more instructions*
59+
6260
### * For Angular 4 and 5, please use ngx-ui-loader version 1.2.x
6361

6462
```shell

projects/ngx-ui-loader/src/lib/core/ngx-ui-loader.component.spec.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { async, ComponentFixture, TestBed, fakeAsync, tick } from '@angular/core
22

33
import { NgxUiLoaderComponent } from './ngx-ui-loader.component';
44
import { NgxUiLoaderService } from './ngx-ui-loader.service';
5-
import { SimpleChange } from '@angular/core';
5+
import { SimpleChange, ChangeDetectionStrategy } from '@angular/core';
66
import { SPINNER, POSITION, PB_DIRECTION } from './ngx-ui-loader.enums';
77
import { SPINNER_CONFIG } from './ngx-ui-loader.contants';
88
import { PositionType } from './ngx-ui-loader.types';
@@ -43,6 +43,9 @@ describe('NgxUiLoaderComponent', () => {
4343
NgxUiLoaderService
4444
]
4545
})
46+
.overrideComponent(NgxUiLoaderComponent, {
47+
set: { changeDetection: ChangeDetectionStrategy.Default }
48+
})
4649
.compileComponents();
4750
}));
4851

@@ -335,7 +338,7 @@ describe('NgxUiLoaderComponent', () => {
335338
});
336339
fixture.detectChanges();
337340
expect(console.error).toHaveBeenCalledWith(`[ngx-ui-loader] - bgsPosition ("invalid-position") is invalid. `
338-
+ `Default value "${component.defaultConfig.bgsPosition}" is used.`);
341+
+ `Default value "${component.defaultConfig.bgsPosition}" is used.`);
339342
expect(component.bgsPosition).toBe(component.defaultConfig.bgsPosition);
340343
});
341344

projects/ngx-ui-loader/src/lib/core/ngx-ui-loader.component.ts

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
import { Component, Input, OnInit, OnChanges, SimpleChanges, SimpleChange, OnDestroy } from '@angular/core';
1+
import { Component, Input, OnInit, OnChanges, SimpleChanges, SimpleChange,
2+
OnDestroy, ChangeDetectionStrategy, ChangeDetectorRef } from '@angular/core';
23
import { DomSanitizer, SafeResourceUrl, SafeStyle } from '@angular/platform-browser';
34
import { NgxUiLoaderService } from './ngx-ui-loader.service';
45
import { Subscription } from 'rxjs';
@@ -14,7 +15,8 @@ import { coerceNumber } from './coercion';
1415
@Component({
1516
selector: 'ngx-ui-loader',
1617
templateUrl: './ngx-ui-loader.component.html',
17-
styleUrls: ['./ngx-ui-loader.component.scss']
18+
styleUrls: ['./ngx-ui-loader.component.scss'],
19+
changeDetection: ChangeDetectionStrategy.OnPush
1820
})
1921
export class NgxUiLoaderComponent implements OnChanges, OnDestroy, OnInit {
2022

@@ -71,6 +73,7 @@ export class NgxUiLoaderComponent implements OnChanges, OnDestroy, OnInit {
7173
*/
7274
constructor(
7375
private domSanitizer: DomSanitizer,
76+
private changeDetectorRef: ChangeDetectorRef,
7477
private ngxService: NgxUiLoaderService) {
7578

7679
this.initialized = false;
@@ -119,24 +122,28 @@ export class NgxUiLoaderComponent implements OnChanges, OnDestroy, OnInit {
119122
.pipe(filter((showEvent: ShowEvent) => this.loaderId === showEvent.loaderId))
120123
.subscribe(data => {
121124
this.showForeground = data.isShow;
125+
this.changeDetectorRef.markForCheck();
122126
});
123127

124128
this.showBackgroundWatcher = this.ngxService.showBackground$
125129
.pipe(filter((showEvent: ShowEvent) => this.loaderId === showEvent.loaderId))
126130
.subscribe(data => {
127131
this.showBackground = data.isShow;
132+
this.changeDetectorRef.markForCheck();
128133
});
129134

130135
this.foregroundClosingWatcher = this.ngxService.foregroundClosing$
131136
.pipe(filter((showEvent: ShowEvent) => this.loaderId === showEvent.loaderId))
132137
.subscribe(data => {
133138
this.foregroundClosing = data.isShow;
139+
this.changeDetectorRef.markForCheck();
134140
});
135141

136142
this.backgroundClosingWatcher = this.ngxService.backgroundClosing$
137143
.pipe(filter((showEvent: ShowEvent) => this.loaderId === showEvent.loaderId))
138144
.subscribe(data => {
139145
this.backgroundClosing = data.isShow;
146+
this.changeDetectorRef.markForCheck();
140147
});
141148
this.initialized = true;
142149
}

0 commit comments

Comments
 (0)