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

Commit

Permalink
Merge branch 'release/v0.2.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
osahner committed Jul 25, 2018
2 parents f7a8464 + a1d65a1 commit f4020f1
Show file tree
Hide file tree
Showing 9 changed files with 5,074 additions and 2,997 deletions.
7,856 changes: 4,972 additions & 2,884 deletions package-lock.json

Large diffs are not rendered by default.

67 changes: 34 additions & 33 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "ngx-httpclient-busy",
"version": "0.1.1",
"version": "0.2.0",
"scripts": {
"build": "gulp build",
"build:watch": "gulp",
Expand Down Expand Up @@ -30,51 +30,52 @@
"url": "https://github.com/username/repo/issues"
},
"devDependencies": {
"@angular/common": "^5.1.1",
"@angular/compiler": "^5.1.1",
"@angular/compiler-cli": "^5.1.1",
"@angular/core": "^5.1.1",
"@angular/http": "^5.1.1",
"@angular/platform-browser": "^5.1.1",
"@angular/platform-browser-dynamic": "^5.1.1",
"@compodoc/compodoc": "^1.0.0-beta.10",
"@types/jasmine": "^2.8.2",
"@angular/common": "^6.0.9",
"@angular/compiler": "^6.0.9",
"@angular/compiler-cli": "^6.0.9",
"@angular/core": "^6.0.9",
"@angular/http": "^6.0.9",
"@angular/platform-browser": "^6.0.9",
"@angular/platform-browser-dynamic": "^6.0.9",
"@compodoc/compodoc": "^1.1.3",
"@types/jasmine": "^2.8.8",
"@types/jasminewd2": "^2.0.3",
"@types/node": "^6.0.94",
"angular-in-memory-web-api": "^0.5.2",
"codelyzer": "^4.0.2",
"concurrently": "^3.4.0",
"core-js": "^2.5.3",
"@types/node": "^6.0.114",
"angular-in-memory-web-api": "^0.6.0",
"codelyzer": "^4.4.2",
"concurrently": "^3.6.0",
"core-js": "^2.5.7",
"del": "^2.2.2",
"gulp": "^3.9.1",
"gulp-rename": "^1.2.2",
"gulp-rollup": "^2.15.0",
"jasmine-core": "^2.8.0",
"gulp-rename": "^1.3.0",
"gulp-rollup": "^2.16.2",
"jasmine-core": "^2.99.1",
"jasmine-spec-reporter": "^4.2.1",
"karma": "~1.7.0",
"karma": "~1.7.1",
"karma-chrome-launcher": "^2.2.0",
"karma-cli": "~1.0.1",
"karma-coverage-istanbul-reporter": "^1.2.1",
"karma-jasmine": "~1.1.0",
"karma-coverage-istanbul-reporter": "^1.4.3",
"karma-jasmine": "^1.1.2",
"karma-jasmine-html-reporter": "^0.2.2",
"karma-typescript": "^3.0.8",
"karma-typescript": "^3.0.12",
"karma-typescript-angular2-transform": "^1.0.2",
"karma-verbose-reporter": "0.0.6",
"lite-server": "^2.3.0",
"node-sass": "^4.5.2",
"node-sass-tilde-importer": "^1.0.0",
"node-watch": "^0.5.2",
"protractor": "^5.2.2",
"lite-server": "^2.4.0",
"node-sass": "^4.9.2",
"node-sass-tilde-importer": "^1.0.2",
"node-watch": "^0.5.8",
"protractor": "^5.3.2",
"rollup": "^0.49.3",
"run-sequence": "^1.2.2",
"rxjs": "^5.5.5",
"rxjs": "^6.2.0",
"rxjs-compat": "^6.2.0",
"systemjs": "^0.20.12",
"ts-node": "~3.2.0",
"tslint": "~5.7.0",
"typescript": "~2.5.3",
"zone.js": "^0.8.14"
"ts-node": "~4.1.0",
"tslint": "~5.9.1",
"typescript": "2.7.2",
"zone.js": "^0.8.26"
},
"engines": {
"node": ">=6.0.0"
"node": ">=8.0.0"
}
}
46 changes: 21 additions & 25 deletions playground/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,10 @@ import { BrowserModule } from '@angular/platform-browser';
import { Component, NgModule, OnInit } from '@angular/core';
import { HTTP_INTERCEPTORS, HttpClient, HttpClientModule, HttpHeaders } from '@angular/common/http';
import { platformBrowserDynamic } from '@angular/platform-browser-dynamic';
import { Observable } from "rxjs/Observable";
import "rxjs/add/observable/throw";
import "rxjs/add/operator/map";
import "rxjs/add/operator/delay";
import "rxjs/add/operator/catch";
import { throwError } from 'rxjs';

import { CounterService, HttpClientBusyInterceptor, HttpClientBusyModule } from '../dist';
import { catchError } from 'rxjs/operators';

@Component({
selector: 'app',
Expand All @@ -30,28 +27,30 @@ import { CounterService, HttpClientBusyInterceptor, HttpClientBusyModule } from
`
})
class AppComponent implements OnInit {

constructor(private http: HttpClient) {
}
constructor(private http: HttpClient) {}

public ping() {
this.http
.put<Array<any>>('https://www.mocky.io/v2/5185415ba171ea3a00704eed?mocky-delay=1s', {
headers: new HttpHeaders().set('Accept', 'application/json')
})
.catch((error: any) => {
return Observable.throw('An error occurred');
})
.pipe(
catchError((error: any) => {
return throwError('An error occurred');
})
)
.subscribe(() => {
console.log('longrunning request done');
});
this.http
.put<Array<any>>('https://www.mocky.io/v2/5185415ba171ea3a00704eed?mocky-delay=100ms', {
headers: new HttpHeaders().set('Accept', 'application/json')
})
.catch((error: any) => {
return Observable.throw('An error occurred');
})
.pipe(
catchError((error: any) => {
return throwError('An error occurred');
})
)
.subscribe(() => {
console.log('shortrunning request done');
});
Expand All @@ -60,10 +59,12 @@ class AppComponent implements OnInit {
.put<Array<any>>('http://www.mocky.io/v2/5a2fae752d00009614a83b2f', {
headers: new HttpHeaders().set('Accept', 'application/json')
})
.catch((error: any) => {
console.log('error request done');
return Observable.throw('An error occurred');
})
.pipe(
catchError((error: any) => {
console.log('error request done');
return throwError('An error occurred');
})
)
.subscribe(() => {
console.log('never happens');
});
Expand All @@ -72,19 +73,14 @@ class AppComponent implements OnInit {
ngOnInit(): void {
console.info('AppComponent init');
}

}

@NgModule({
declarations: [AppComponent],
bootstrap: [AppComponent],
imports: [BrowserModule, HttpClientModule, HttpClientBusyModule.forRoot()],
providers: [
CounterService,
{ provide: HTTP_INTERCEPTORS, useClass: HttpClientBusyInterceptor, multi: true }
]
providers: [CounterService, { provide: HTTP_INTERCEPTORS, useClass: HttpClientBusyInterceptor, multi: true }]
})
class AppModule {
}
class AppModule {}

platformBrowserDynamic().bootstrapModule(AppModule);
19 changes: 12 additions & 7 deletions playground/systemjs.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* System configuration for Angular samples
* Adjust as necessary for your application needs.
*/
(function () {
(function() {
System.config({
paths: {
// paths serve as alias
Expand All @@ -21,15 +21,17 @@
'@angular/common': 'npm:@angular/common/bundles/common.umd.js',
'@angular/compiler': 'npm:@angular/compiler/bundles/compiler.umd.js',
'@angular/platform-browser': 'npm:@angular/platform-browser/bundles/platform-browser.umd.js',
'@angular/platform-browser-dynamic': 'npm:@angular/platform-browser-dynamic/bundles/platform-browser-dynamic.umd.js',
'@angular/platform-browser-dynamic':
'npm:@angular/platform-browser-dynamic/bundles/platform-browser-dynamic.umd.js',
//'@angular/http': 'npm:@angular/http/bundles/http.umd.js',
'@angular/common/http': 'npm:@angular/common/bundles/common-http.umd.js',
'@angular/router': 'npm:@angular/router/bundles/router.umd.js',
'@angular/forms': 'npm:@angular/forms/bundles/forms.umd.js',

// other libraries
'rxjs': 'npm:rxjs',
'tslib': 'npm:tslib/tslib.js',
rxjs: 'npm:rxjs',
'rxjs-compat': 'npm:rxjs-compat',
tslib: 'npm:tslib/tslib.js',
'angular-in-memory-web-api': 'npm:angular-in-memory-web-api/bundles/in-memory-web-api.umd.js',
'ngx-httpclient-busy': '../dist'
},
Expand All @@ -43,9 +45,12 @@
}
}
},
rxjs: {
defaultExtension: 'js'
},
'rxjs/internal-compatibility': { main: 'index.js', defaultExtension: 'js' },
'rxjs/ajax': { main: 'index.js', defaultExtension: 'js' },
'rxjs/operators': { main: 'index.js', defaultExtension: 'js' },
'rxjs/testing': { main: 'index.js', defaultExtension: 'js' },
'rxjs/webSocket': { main: 'index.js', defaultExtension: 'js' },
rxjs: { main: 'index.js', defaultExtension: 'js' },
'ngx-httpclient-busy': {
main: 'ngx-httpclient-busy.umd.js',
defaultExtension: 'js'
Expand Down
15 changes: 9 additions & 6 deletions src/counter.service.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,21 @@
import { Injectable } from '@angular/core';
import { Subscriber } from 'rxjs/Subscriber';
import { Observable } from 'rxjs/Observable';
import 'rxjs/add/operator/share';
import { Subscriber, Observable } from 'rxjs';
import { share } from "rxjs/operators";

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

constructor() {
this._observable = Observable.create(subscriber => {
this._subscriber = subscriber;
}).share();
}).pipe(
share()
);
}

public get observable(): Observable<number> {
Expand Down
12 changes: 3 additions & 9 deletions src/http-client-busy.directive.ts
Original file line number Diff line number Diff line change
@@ -1,24 +1,20 @@
import { Directive, ElementRef, Input, OnDestroy, OnInit, Renderer2 } from '@angular/core';
import { Subscription } from 'rxjs/Subscription';
import { Subscription } from 'rxjs';
import { CounterService } from './counter.service';

@Directive({
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);
const busy = count > 0;
const hasIdle = this._el.nativeElement.classList.contains(this._httpClientBusyConfig.idle);
const hasBusy = this._el.nativeElement.classList.contains(this._httpClientBusyConfig.busy);

Expand All @@ -40,7 +36,6 @@ export class HttpClientBusyDirective implements OnInit, OnDestroy {
}

ngOnInit() {
// this._renderer.addClass(this._el.nativeElement, 'http-client-busy');
this._httpClientBusyConfig.idle = this.httpClientBusy.idle || 'fade';
this._httpClientBusyConfig.busy = this.httpClientBusy.busy || '';
this._updateStatus(0);
Expand All @@ -56,4 +51,3 @@ export interface HttpClientBusyConfig {
busy?: string;
idle?: string;
}

31 changes: 14 additions & 17 deletions src/http-client-busy.interceptor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,33 +7,30 @@ import {
HttpRequest,
HttpResponse
} from '@angular/common/http';
import { Observable } from 'rxjs/Observable';
import 'rxjs/add/observable/throw';
import 'rxjs/add/operator/catch';
import 'rxjs/add/operator/do';
import { Observable, throwError } from 'rxjs';
import { catchError, tap } from 'rxjs/operators';
import { CounterService } from './counter.service';

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

constructor(private _counter: CounterService) {
}

intercept(req: HttpRequest<any>,
next: HttpHandler): Observable<HttpEvent<any>> {
intercept(req: HttpRequest<any>, next: HttpHandler): Observable<HttpEvent<any>> {
this._counter.increment();
return next.handle(req)
.do(evt => {
return next.handle(req).pipe(
tap(evt => {
if (evt instanceof HttpResponse) {
this._counter.decrement();
}
})
.catch(err => {
}),
catchError(err => {
if (err instanceof HttpErrorResponse) {
this._counter.decrement();
}
return Observable.throw(err);
});
return throwError(err);
})
);
}
}

18 changes: 5 additions & 13 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,22 +10,14 @@ export * from './http-client-busy.directive';
export * from './http-client-busy.interceptor';

@NgModule({
imports: [
CommonModule,
HttpClientModule
],
declarations: [
HttpClientBusyDirective
],
exports: [
HttpClientBusyDirective
]
imports: [CommonModule, HttpClientModule],
declarations: [HttpClientBusyDirective],
exports: [HttpClientBusyDirective]
})
export class HttpClientBusyModule {
static forRoot(): ModuleWithProviders {
return {
ngModule: HttpClientBusyModule,
providers: [HttpClientBusyInterceptor, CounterService]
}
ngModule: HttpClientBusyModule
};
}
}
7 changes: 4 additions & 3 deletions src/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "ngx-httpclient-busy",
"version": "0.1.1",
"version": "0.2.0",
"repository": {
"type": "git",
"url": "https://github.com/osahner/ngx-httpclient-busy"
Expand All @@ -22,8 +22,9 @@
"jsnext:main": "ngx-httpclient-busy.js",
"typings": "ngx-httpclient-busy.d.ts",
"peerDependencies": {
"@angular/core": "^4.2.4 || ^5.0.0",
"rxjs": "^5.1.0",
"@angular/core": "^6.0.0",
"rxjs": "^6.2.0",
"rxjs-compat": "^6.2.0",
"zone.js": "^0.8.4"
}
}

0 comments on commit f4020f1

Please sign in to comment.