Skip to content

Commit 0e79e44

Browse files
authored
Merge pull request #27 from mpalourdio/debounce
Debounce Delay. Fixes #25 && #26
2 parents 19d0d1a + 77366fb commit 0e79e44

27 files changed

+611
-103
lines changed

CHANGELOG.MD

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,15 @@
1+
# Changelog
2+
3+
## v0.6.0
4+
5+
This release adds the ``debounceDelay`` parameter (default is 0). It allows to discard the spinner for fast and repeated http requests, which can be annoying under some conditions.
6+
7+
See [customization](https://github.com/mpalourdio/ng-http-loader#customizing-the-spinner)
8+
9+
The library footprint has been reduced by minifying templates and stylesheets before inlining them.
10+
11+
The library now takes advantage of [RxJS lettable operators](https://github.com/ReactiveX/rxjs/blob/master/doc/lettable-operators.md)
12+
113
## v0.5.1
214

315
This release fixes a bug that could cause the spinner to not show if an http request were performed **before** the spinner component was initialized.

README.MD

Lines changed: 19 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -17,27 +17,23 @@ $ npm install ng-http-loader --save
1717
## What does it do ?
1818

1919
This package provides an HTTP Interceptor, and a spinner component (All from [SpinKit](https://github.com/tobiasahlin/SpinKit) at the moment).
20-
The HTTP interceptor listens to all HTTP requests and shows a spinner during pending requests.
20+
The HTTP interceptor listens to all HTTP requests and shows a spinner / loader indicator during pending http requests.
2121

2222
## Angular 4 / Angular 5
2323

24-
The latest compatible module version with angular 4 is **``0.3.4``**.
25-
If you want to use Angular 5, use **``^0.5.0``**.
24+
The latest module version compatible with angular 4 is **``0.3.4``**.
25+
If you want to use Angular 5, use versions **``0.4.0``** and above.
2626

2727
If you experience errors like below, **please double check the version you use.**
2828

2929
``ERROR in Error: Metadata version mismatch for module [...]/angular/node_modules/ng-http-loader/ng-http-loader
30-
.module.d.ts, found version 4, expected 3, resolving symbol AppModule in [...]/angular/src/app.module.ts``
31-
30+
.module.d.ts, found version x, expected y, resolving symbol AppModule in [...]/angular/src/app.module.ts``
3231

33-
## Requirements
32+
## Requirements - HttpClientModule
3433

35-
Compatible with Angular 4.3+. Performing http requests with the new API from ``HttpClientModule`` is **mandatory**. Otherwise,
36-
the spinner will not be fired **at all**.
34+
Performing http requests with the ``HttpClientModule`` API is **mandatory**. Otherwise,the spinner will not be fired **at all**.
3735

38-
## HttpClientModule
39-
40-
All http requests **MUST** be performed with the new ``HttpClientModule`` available from ``angular 4.3``. See this [blog post](http://blog.ninja-squad.com/2017/07/17/http-client-module/) as reference.
36+
See this [blog post](http://blog.ninja-squad.com/2017/07/17/http-client-module/) for an ``HttpClientModule`` introduction.
4137

4238
## Usage
4339

@@ -93,19 +89,24 @@ import { NgHttpLoaderServicesModule } from 'ng-http-loader/services/ng-http-load
9389
export class AppModule { }
9490
```
9591

96-
In your app.component.html, add :
92+
In your app.component.html, simply add :
9793
```xml
9894
<spinner></spinner>
9995
```
10096

10197
## Customizing the spinner
10298

103-
You can customize the background-color and the spinner type:
99+
You can customize the **background-color**, the **spinner type** and the **debounce delay** (ie. after how many milliseconds the spinner will be displayed, if needed):
104100
```xml
105-
<spinner [backgroundColor]="'#ff0000'" [spinner]="spinkit.skWave"></spinner>
101+
<spinner
102+
[backgroundColor]="'#ff0000'"
103+
[spinner]="spinkit.skWave"
104+
[debounceDelay]="200"
105+
>
106+
</spinner>
106107
```
107108

108-
**_To use this syntax, you must reference the ``Spinkit`` const as a public property in you app.component.ts_**:
109+
**_To use this syntax, you must reference the ``Spinkit`` const as a public property in your app.component.ts_**:
109110

110111
```typescript
111112
import { Spinkit } from 'ng-http-loader/spinkits'; <============
@@ -131,13 +132,9 @@ The different spinners available are referenced in [this class](src/spinkits.ts)
131132

132133
## Requests filtering
133134

134-
You can filter the requests that shouldn't be caught by the interceptor by providing **an array of regex patterns**:
135+
You can also filter the http requests that shouldn't be caught by the interceptor by providing **an array of regex patterns**:
135136
```xml
136-
<spinner
137-
[backgroundColor]="'#ff0000'"
138-
[spinner]="spinkit.skWave"
139-
[filteredUrlPatterns]="['\\d', '[a-zA-Z]', 'my-api']">
140-
</spinner>
137+
<spinner [filteredUrlPatterns]="['\\d', '[a-zA-Z]', 'my-api']"></spinner>
141138
```
142139

143140
## Misc
@@ -146,4 +143,4 @@ Each Spinkit component defined in [SPINKIT_COMPONENTS](src/spinkits.ts#L30) can
146143

147144
## Credits
148145

149-
The spinners/loaders have been taken from [SpinKit](https://github.com/tobiasahlin/SpinKit).
146+
[Tobias Ahlin](https://github.com/tobiasahlin), the awesome creator of [SpinKit](https://github.com/tobiasahlin/SpinKit).

gulpfile.js

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,49 @@
11
const inlineNg2Template = require('gulp-inline-ng2-template');
2+
const htmlMinifier = require('html-minifier');
3+
const cleanCss = require('clean-css');
24
const gulp = require('gulp');
35
const clean = require('gulp-clean');
46

57
const tmpDir = './tmp';
68
const distDir = './dist';
79

10+
function minifyTemplate(path, ext, file, callback) {
11+
try {
12+
const minifiedFile = htmlMinifier.minify(file, {
13+
collapseWhitespace: true,
14+
caseSensitive: true,
15+
removeComments: true,
16+
removeRedundantAttributes: true,
17+
preserveLineBreaks: false,
18+
});
19+
20+
callback(null, minifiedFile);
21+
}
22+
catch (error) {
23+
callback(error);
24+
}
25+
}
26+
27+
function minifyCss(path, ext, file, callback) {
28+
try {
29+
new cleanCss().minify(file, function (error, output) {
30+
callback(null, output.styles);
31+
});
32+
}
33+
catch (error) {
34+
callback(error);
35+
}
36+
}
37+
838
gulp.task('inline-templates', ['clean-tmp'], function () {
939
return gulp.src('./src/**/*.ts')
1040
.pipe(inlineNg2Template({
1141
base: '/src',
1242
target: 'es6',
13-
useRelativePaths: true
43+
useRelativePaths: true,
44+
templateProcessor: minifyTemplate,
45+
styleProcessor: minifyCss,
46+
removeLineBreaks: true,
1447
}))
1548
.pipe(gulp.dest(tmpDir));
1649
});

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "ng-http-loader",
3-
"version": "0.5.1",
3+
"version": "0.6.0",
44
"scripts": {
55
"prepare-deploy": "gulp inline-templates && gulp clean-dist && ngc -p tsconfig.ngc.json && gulp clean-tmp && gulp copy-all",
66
"test": "ng test --watch false"

src/components/ng-http-loader-components.module.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,12 @@
1+
/*
2+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
3+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
4+
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
5+
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
6+
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
7+
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
8+
*/
9+
110
import { NgModule } from '@angular/core';
211
import { CommonModule } from '@angular/common';
312
import { HttpClientModule } from '@angular/common/http';

src/components/sk-chasing-dots/sk-chasing-dots.component.css

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,24 @@
1+
/*
2+
Copyright (c) 2015 Tobias Ahlin
3+
4+
Permission is hereby granted, free of charge, to any person obtaining a copy of
5+
this software and associated documentation files (the "Software"), to deal in
6+
the Software without restriction, including without limitation the rights to
7+
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
8+
the Software, and to permit persons to whom the Software is furnished to do so,
9+
subject to the following conditions:
10+
11+
The above copyright notice and this permission notice shall be included in all
12+
copies or substantial portions of the Software.
13+
14+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
16+
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
17+
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
18+
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
19+
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
20+
*/
21+
122
.sk-chasing-dots {
223
top: 50%;
324
margin: auto;

src/components/sk-chasing-dots/sk-chasing-dots.component.html

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,24 @@
1+
<!--
2+
Copyright (c) 2015 Tobias Ahlin
3+
4+
Permission is hereby granted, free of charge, to any person obtaining a copy of
5+
this software and associated documentation files (the "Software"), to deal in
6+
the Software without restriction, including without limitation the rights to
7+
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
8+
the Software, and to permit persons to whom the Software is furnished to do so,
9+
subject to the following conditions:
10+
11+
The above copyright notice and this permission notice shall be included in all
12+
copies or substantial portions of the Software.
13+
14+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
16+
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
17+
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
18+
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
19+
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
20+
-->
21+
122
<div class="sk-chasing-dots" [class.colored]="!backgroundColor">
223
<div class="sk-child sk-dot1" [style.background-color]='backgroundColor'></div>
324
<div class="sk-child sk-dot2" [style.background-color]='backgroundColor'></div>

src/components/sk-cube-grid/sk-cube-grid.component.css

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,24 @@
1+
/*
2+
Copyright (c) 2015 Tobias Ahlin
3+
4+
Permission is hereby granted, free of charge, to any person obtaining a copy of
5+
this software and associated documentation files (the "Software"), to deal in
6+
the Software without restriction, including without limitation the rights to
7+
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
8+
the Software, and to permit persons to whom the Software is furnished to do so,
9+
subject to the following conditions:
10+
11+
The above copyright notice and this permission notice shall be included in all
12+
copies or substantial portions of the Software.
13+
14+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
16+
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
17+
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
18+
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
19+
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
20+
*/
21+
122
.sk-cube-grid {
223
position: relative;
324
top: 50%;

src/components/sk-cube-grid/sk-cube-grid.component.html

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,24 @@
1+
<!--
2+
Copyright (c) 2015 Tobias Ahlin
3+
4+
Permission is hereby granted, free of charge, to any person obtaining a copy of
5+
this software and associated documentation files (the "Software"), to deal in
6+
the Software without restriction, including without limitation the rights to
7+
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
8+
the Software, and to permit persons to whom the Software is furnished to do so,
9+
subject to the following conditions:
10+
11+
The above copyright notice and this permission notice shall be included in all
12+
copies or substantial portions of the Software.
13+
14+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
16+
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
17+
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
18+
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
19+
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
20+
-->
21+
122
<div class="sk-cube-grid" [class.colored]="!backgroundColor">
223
<div class="sk-cube sk-cube1" [style.background-color]='backgroundColor'></div>
324
<div class="sk-cube sk-cube2" [style.background-color]='backgroundColor'></div>

src/components/sk-double-bounce/sk-double-bounce.component.css

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,24 @@
1+
/*
2+
Copyright (c) 2015 Tobias Ahlin
3+
4+
Permission is hereby granted, free of charge, to any person obtaining a copy of
5+
this software and associated documentation files (the "Software"), to deal in
6+
the Software without restriction, including without limitation the rights to
7+
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
8+
the Software, and to permit persons to whom the Software is furnished to do so,
9+
subject to the following conditions:
10+
11+
The above copyright notice and this permission notice shall be included in all
12+
copies or substantial portions of the Software.
13+
14+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
16+
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
17+
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
18+
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
19+
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
20+
*/
21+
122
.sk-double-bounce {
223
top: 50%;
324
width: 40px;

0 commit comments

Comments
 (0)