@ngx-loading-bar/http
Version:
Automatic page loading / progress bar for Angular
180 lines (169 loc) • 7.31 kB
JavaScript
(function (global, factory) {
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('@ngx-loading-bar/core'), require('@angular/core'), require('@angular/http'), require('rxjs/operators')) :
typeof define === 'function' && define.amd ? define('@ngx-loading-bar/http', ['exports', '@ngx-loading-bar/core', '@angular/core', '@angular/http', 'rxjs/operators'], factory) :
(factory((global['ngx-loading-bar'] = global['ngx-loading-bar'] || {}, global['ngx-loading-bar'].http = {}),global.core,global.ng.core,global.ng.http,global.rxjs.operators));
}(this, (function (exports,core,core$1,http,operators) { 'use strict';
/*! *****************************************************************************
Copyright (c) Microsoft Corporation. All rights reserved.
Licensed under the Apache License, Version 2.0 (the "License"); you may not use
this file except in compliance with the License. You may obtain a copy of the
License at http://www.apache.org/licenses/LICENSE-2.0
THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED
WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE,
MERCHANTABLITY OR NON-INFRINGEMENT.
See the Apache Version 2.0 License for specific language governing permissions
and limitations under the License.
***************************************************************************** */
/* global Reflect, Promise */
var extendStatics = Object.setPrototypeOf ||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
function (d, b) { for (var p in b)
if (b.hasOwnProperty(p))
d[p] = b[p]; };
function __extends(d, b) {
extendStatics(d, b);
function __() { this.constructor = d; }
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
}
function __read(o, n) {
var m = typeof Symbol === "function" && o[Symbol.iterator];
if (!m)
return o;
var i = m.call(o), r, ar = [], e;
try {
while ((n === void 0 || n-- > 0) && !(r = i.next()).done)
ar.push(r.value);
}
catch (error) {
e = { error: error };
}
finally {
try {
if (r && !r.done && (m = i["return"]))
m.call(i);
}
finally {
if (e)
throw e.error;
}
}
return ar;
}
function __spread() {
for (var ar = [], i = 0; i < arguments.length; i++)
ar = ar.concat(__read(arguments[i]));
return ar;
}
/**
* @fileoverview added by tsickle
* @suppress {checkTypes,extraRequire,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
*/
var LoadingBarHttp = /** @class */ (function (_super) {
__extends(LoadingBarHttp, _super);
function LoadingBarHttp(_backend, _defaultOptions, loadingBar) {
var _this = _super.call(this, _backend, _defaultOptions) || this;
_this.loadingBar = loadingBar;
return _this;
}
/**
* @param {?} url
* @param {?=} options
* @return {?}
*/
LoadingBarHttp.prototype.request = /**
* @param {?} url
* @param {?=} options
* @return {?}
*/
function (url, options) {
var _this = this;
/** @type {?} */
var headers = options && options.headers;
if (!headers && url && (( /** @type {?} */(url))).headers) {
headers = (( /** @type {?} */(url))).headers;
}
if (headers && headers.has('ignoreLoadingBar')) {
headers.delete('ignoreLoadingBar');
return _super.prototype.request.call(this, url, options);
}
/** @type {?} */
var response$ = _super.prototype.request.call(this, url, options);
if (options && options.ignoreLoadingBar === true) {
return response$;
}
/** @type {?} */
var started = false;
/** @type {?} */
var responseSubscribe = response$.subscribe.bind(response$);
response$.subscribe = function () {
var args = [];
for (var _i = 0; _i < arguments.length; _i++) {
args[_i] = arguments[_i];
}
_this.loadingBar.start();
started = true;
return responseSubscribe.apply(void 0, __spread(args));
};
return response$.pipe(operators.finalize(function () { return started && _this.loadingBar.complete(); }));
};
LoadingBarHttp.decorators = [
{ type: core$1.Injectable }
];
/** @nocollapse */
LoadingBarHttp.ctorParameters = function () {
return [
{ type: http.ConnectionBackend },
{ type: http.RequestOptions },
{ type: core.LoadingBarService }
];
};
return LoadingBarHttp;
}(http.Http));
/**
* @fileoverview added by tsickle
* @suppress {checkTypes,extraRequire,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
*/
/**
* @param {?} xhrBackend
* @param {?} requestOptions
* @param {?} loadingBarService
* @return {?}
*/
function httpFactory(xhrBackend, requestOptions, loadingBarService) {
return new LoadingBarHttp(xhrBackend, requestOptions, loadingBarService);
}
var LoadingBarHttpModule = /** @class */ (function () {
function LoadingBarHttpModule() {
}
LoadingBarHttpModule.decorators = [
{ type: core$1.NgModule, args: [{
imports: [
http.HttpModule,
core.LoadingBarModule,
],
exports: [
http.HttpModule,
core.LoadingBarModule,
],
providers: [
{ provide: http.Http, useFactory: httpFactory, deps: [http.XHRBackend, http.RequestOptions, core.LoadingBarService] },
],
},] }
];
return LoadingBarHttpModule;
}());
/**
* @fileoverview added by tsickle
* @suppress {checkTypes,extraRequire,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
*/
/**
* @fileoverview added by tsickle
* @suppress {checkTypes,extraRequire,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
*/
exports.LoadingBarHttpModule = LoadingBarHttpModule;
exports.LoadingBarHttp = LoadingBarHttp;
exports.ɵa = httpFactory;
Object.defineProperty(exports, '__esModule', { value: true });
})));
//# sourceMappingURL=ngx-loading-bar-http.umd.js.map