Skip to content
This repository has been archived by the owner on Dec 17, 2021. It is now read-only.

Commit

Permalink
chore: angular v11
Browse files Browse the repository at this point in the history
  • Loading branch information
osahner committed Jan 27, 2021
1 parent 4466559 commit 3167c76
Show file tree
Hide file tree
Showing 13 changed files with 2,113 additions and 1,673 deletions.
13 changes: 8 additions & 5 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,19 @@ dist: bionic
addons:
chrome: stable

language: node_js

node_js:
- "12"
- "14"

cache:
directories:
- ./node_modules
yarn: false

install:
before_install:
- yarn global add codecov
- yarn install

install:
- yarn install --frozen-lockfile

script:
- yarn test_lib --no-watch --no-progress --code-coverage --browsers=ChromeHeadlessCI
Expand Down
2 changes: 2 additions & 0 deletions README.MD
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,8 @@ export interface HttpClientBusyConfig {

## Release History

- 0.7.0
- update @angular/cli and @angular/core to v11
- 0.6.0
- update @angular/cli and @angular/core to v10
- 0.5.0
Expand Down
2 changes: 1 addition & 1 deletion angular.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"prefix": "lib",
"architect": {
"build": {
"builder": "@angular-devkit/build-ng-packagr:build",
"builder": "@angular-devkit/build-angular:ng-packagr",
"options": {
"tsConfig": "projects/ngx-httpclient-busy/tsconfig.lib.json",
"project": "projects/ngx-httpclient-busy/ng-package.json"
Expand Down
49 changes: 24 additions & 25 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "ngx-httpclient-busy",
"version": "0.6.0",
"version": "0.7.0",
"author": {
"name": "Oliver Sahner",
"email": "[email protected]",
Expand All @@ -23,40 +23,39 @@
},
"private": true,
"dependencies": {
"@angular/animations": "~10.1.1",
"@angular/common": "~10.1.1",
"@angular/compiler": "~10.1.1",
"@angular/core": "~10.1.1",
"@angular/forms": "~10.1.1",
"@angular/platform-browser": "~10.1.1",
"@angular/platform-browser-dynamic": "~10.1.1",
"@angular/router": "~10.1.1",
"core-js": "^3.6.5",
"@angular/animations": "~11.1.0",
"@angular/common": "~11.1.0",
"@angular/compiler": "~11.1.0",
"@angular/core": "~11.1.0",
"@angular/forms": "~11.1.0",
"@angular/platform-browser": "~11.1.0",
"@angular/platform-browser-dynamic": "~11.1.0",
"@angular/router": "~11.1.0",
"core-js": "^3.8.3",
"rxjs": "~6.6.3",
"tslib": "^2.0.1",
"zone.js": "~0.11.1"
"tslib": "^2.1.0",
"zone.js": "~0.11.3"
},
"devDependencies": {
"@angular-devkit/build-angular": "~0.1001.1",
"@angular-devkit/build-ng-packagr": "~0.1001.1",
"@angular/cli": "~10.1.1",
"@angular/compiler-cli": "~10.1.1",
"@angular/language-service": "~10.1.1",
"@types/node": "^14.10.1",
"@types/jasmine": "~3.5.14",
"@angular-devkit/build-angular": "~0.1101.1",
"@angular/cli": "~11.1.1",
"@angular/compiler-cli": "~11.1.0",
"@angular/language-service": "~11.1.0",
"@types/node": "^14.14.22",
"@types/jasmine": "~3.6.3",
"@types/jasminewd2": "~2.0.8",
"codelyzer": "^6.0.0",
"codelyzer": "^6.0.1",
"jasmine-core": "~3.6.0",
"jasmine-spec-reporter": "~5.0.2",
"karma": "~5.2.2",
"jasmine-spec-reporter": "~6.0.0",
"karma": "~6.0.2",
"karma-chrome-launcher": "~3.1.0",
"karma-coverage-istanbul-reporter": "~3.0.3",
"karma-jasmine": "~4.0.1",
"karma-jasmine-html-reporter": "^1.5.4",
"ng-packagr": "^10.1.0",
"ng-packagr": "^11.1.2",
"protractor": "~7.0.0",
"ts-node": "~9.0.0",
"ts-node": "~9.1.1",
"tslint": "~6.1.3",
"typescript": "~4.0.2"
"typescript": "~4.1.2"
}
}
2 changes: 1 addition & 1 deletion projects/ngx-httpclient-busy/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "ngx-httpclient-busy",
"version": "0.5.0",
"version": "0.7.0",

"repository": {
"type": "git",
Expand Down
4 changes: 2 additions & 2 deletions projects/ngx-httpclient-busy/src/lib/counter.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@ import { Subscriber, Observable } from 'rxjs';
import { share } from 'rxjs/operators';

@Injectable({
providedIn: 'root'
providedIn: 'root',
})
export class CounterService {
private readonly _observable: Observable<number>;
private _subscriber: Subscriber<number>;
private _connectionCounter = 0;

constructor() {
this._observable = Observable.create(subscriber => {
this._observable = new Observable<number>((subscriber) => {
this._subscriber = subscriber;
}).pipe(share());
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { async, ComponentFixture, fakeAsync, inject, TestBed } from '@angular/core/testing';
import { ComponentFixture, fakeAsync, inject, TestBed, waitForAsync } from '@angular/core/testing';
import { Component } from '@angular/core';
import { HttpClient, HttpClientModule, HttpHeaders } from '@angular/common/http';
import { By } from '@angular/platform-browser';
Expand All @@ -9,9 +9,7 @@ import { catchError } from 'rxjs/operators';

@Component({
selector: 'lib-test',
template: `
<div [httpClientBusy]="{ busy: 'busy', idle: 'idle' }"></div>
`
template: ` <div [httpClientBusy]="{ busy: 'busy', idle: 'idle' }"></div> `,
})
class TestComponent {
disabled;
Expand All @@ -22,14 +20,16 @@ describe('HttpClientBusyDirective', () => {
let http: HttpClient;
let fixture: ComponentFixture<TestComponent>;

beforeEach(async(() => {
TestBed.configureTestingModule({
declarations: [TestComponent],
imports: [HttpClientModule, HttpClientBusyModule.forRoot()],
providers: []
});
TestBed.compileComponents();
}));
beforeEach(
waitForAsync(() => {
TestBed.configureTestingModule({
declarations: [TestComponent],
imports: [HttpClientModule, HttpClientBusyModule.forRoot()],
providers: [],
});
TestBed.compileComponents();
})
);

beforeEach(inject([HttpClient], (s: HttpClient) => {
jasmine.DEFAULT_TIMEOUT_INTERVAL = 5000;
Expand All @@ -43,36 +43,54 @@ describe('HttpClientBusyDirective', () => {
expect(directiveEl).not.toBeNull();
}));

it('update directive class', async(() => {
const directiveEl = fixture.debugElement.query(By.directive(HttpClientBusyDirective));
it(
'update directive class',
waitForAsync(() => {
const directiveEl = fixture.debugElement.query(By.directive(HttpClientBusyDirective));

http
.put('https://www.mocky.io/v2/5185415ba171ea3a00704eed?mocky-delay=1s', {
headers: new HttpHeaders().set('Accept', 'application/json')
})
.subscribe(() => {
expect(directiveEl.nativeElement.classList.contains('idle')).toBe(true, 'should contain idle class');
});
http
.put('https://www.mocky.io/v2/5185415ba171ea3a00704eed?mocky-delay=1s', {
headers: new HttpHeaders().set('Accept', 'application/json'),
})
.subscribe(() => {
expect(directiveEl.nativeElement.classList.contains('idle')).toBe(
true,
'should contain idle class'
);
});

setTimeout(() => {
expect(directiveEl.nativeElement.classList.contains('busy')).toBe(true, 'should contain busy class');
}, 500);
}));
setTimeout(() => {
expect(directiveEl.nativeElement.classList.contains('busy')).toBe(
true,
'should contain busy class'
);
}, 500);
})
);

it('handle errors', async(() => {
const directiveEl = fixture.debugElement.query(By.directive(HttpClientBusyDirective));
it(
'handle errors',
waitForAsync(() => {
const directiveEl = fixture.debugElement.query(By.directive(HttpClientBusyDirective));

http
.put('http://www.mocky.io/v2/5a2fae752d00009614a83b2f?mocky-delay=1s', {
headers: new HttpHeaders().set('Accept', 'application/json')
})
.pipe(catchError(selector => of({})))
.subscribe(() => {
expect(directiveEl.nativeElement.classList.contains('idle')).toBe(true, 'should contain idle class');
});
http
.put('http://www.mocky.io/v2/5a2fae752d00009614a83b2f?mocky-delay=1s', {
headers: new HttpHeaders().set('Accept', 'application/json'),
})
.pipe(catchError((selector) => of({})))
.subscribe(() => {
expect(directiveEl.nativeElement.classList.contains('idle')).toBe(
true,
'should contain idle class'
);
});

setTimeout(() => {
expect(directiveEl.nativeElement.classList.contains('busy')).toBe(true, 'should contain busy class');
}, 500);
}));
setTimeout(() => {
expect(directiveEl.nativeElement.classList.contains('busy')).toBe(
true,
'should contain busy class'
);
}, 500);
})
);
});
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,19 @@ import { Subscription } from 'rxjs';
import { CounterService } from './counter.service';

@Directive({
selector: '[httpClientBusy]'
selector: '[httpClientBusy]',
})
export class HttpClientBusyDirective implements OnInit, OnDestroy {
private autoUnsubscribe: Subscription;
private httpClientBusyConfig: HttpClientBusyConfig = {};

@Input() httpClientBusy: HttpClientBusyConfig;

constructor(private el: ElementRef, private renderer: Renderer2, private counter: CounterService) {}
constructor(
private el: ElementRef,
private renderer: Renderer2,
private counter: CounterService
) {}

private _updateStatus(count: number) {
const busy = count > 0;
Expand Down Expand Up @@ -39,7 +43,7 @@ export class HttpClientBusyDirective implements OnInit, OnDestroy {
this.httpClientBusyConfig.idle = this.httpClientBusy.idle || 'fade';
this.httpClientBusyConfig.busy = this.httpClientBusy.busy || '';
this._updateStatus(0);
this.autoUnsubscribe = this.counter.observable.subscribe(next => this._updateStatus(next));
this.autoUnsubscribe = this.counter.observable.subscribe((next) => this._updateStatus(next));
}

ngOnDestroy() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,27 +5,27 @@ import {
HttpHandler,
HttpInterceptor,
HttpRequest,
HttpResponse
HttpResponse,
} from '@angular/common/http';
import { Observable, throwError } from 'rxjs';
import { catchError, tap } from 'rxjs/operators';
import { CounterService } from './counter.service';

@Injectable({
providedIn: 'root'
providedIn: 'root',
})
export class HttpClientBusyInterceptor implements HttpInterceptor {
constructor(private counter: CounterService) {}

intercept(req: HttpRequest<any>, next: HttpHandler): Observable<HttpEvent<any>> {
this.counter.increment();
return next.handle(req).pipe(
tap(evt => {
tap((evt) => {
if (evt instanceof HttpResponse) {
this.counter.decrement();
}
}),
catchError(err => {
catchError((err) => {
if (err instanceof HttpErrorResponse) {
this.counter.decrement();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@ import { HttpClientBusyDirective } from './httpclient-busy.directive';
imports: [CommonModule, HttpClientModule],
declarations: [HttpClientBusyDirective],
exports: [HttpClientBusyDirective],
providers: [{ provide: HTTP_INTERCEPTORS, useClass: HttpClientBusyInterceptor, multi: true }]
providers: [{ provide: HTTP_INTERCEPTORS, useClass: HttpClientBusyInterceptor, multi: true }],
})
export class HttpClientBusyModule {
static forRoot(): ModuleWithProviders<HttpClientBusyModule> {
return {
ngModule: HttpClientBusyModule
ngModule: HttpClientBusyModule,
};
}
}
1 change: 1 addition & 0 deletions projects/ngx-httpclient-busy/tsconfig.lib.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
"extends": "../../tsconfig.json",
"compilerOptions": {
"outDir": "../../out-tsc/lib",
"declarationMap": true,
"target": "es2015",
"declaration": true,
"inlineSources": true,
Expand Down
3 changes: 3 additions & 0 deletions projects/ngx-httpclient-busy/tsconfig.lib.prod.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
{
"extends": "./tsconfig.lib.json",
"compilerOptions": {
"declarationMap": false
},
"angularCompilerOptions": {
"enableIvy": false
}
Expand Down
Loading

0 comments on commit 3167c76

Please sign in to comment.