Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

angular-loading-overlay-http-interceptor

Package Overview
Dependencies
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

angular-loading-overlay-http-interceptor - npm Package Compare versions

Comparing version 1.0.0 to 1.1.0

source/IBsLoadingOverlayHttpInterceptorOptions.ts

19

dist/angular-loading-overlay-http-interceptor.js

@@ -77,8 +77,16 @@ /******/ (function(modules) { // webpackBootstrap

var _this = this;
if (config === void 0) { config = {}; }
this.config = config;
this.bsLoadingOverlayService = bsLoadingOverlayService;
this.requestsCount = 0;
this.request = function (config) {
_this.onRequest();
return config;
this.request = function (requestConfig) {
if (_this.config.requestsMatcher) {
if (_this.config.requestsMatcher(requestConfig)) {
_this.onRequest();
}
}
else {
_this.onRequest();
}
return requestConfig;
};

@@ -105,6 +113,7 @@ this.requestError = function (rejection) {

BsLoadingOverlayHttpInterceptorInterceptor.prototype.onResponse = function () {
this.requestsCount--;
if (this.requestsCount === 0) {
var newRequestsCount = this.requestsCount - 1;
if (newRequestsCount === 0) {
this.bsLoadingOverlayService.stop(this.config);
}
this.requestsCount = Math.max(0, newRequestsCount);
};

@@ -111,0 +120,0 @@ return BsLoadingOverlayHttpInterceptorInterceptor;

{
"name": "angular-loading-overlay-http-interceptor",
"version": "1.0.0",
"version": "1.1.0",
"description": "Angular loading overlay integration with http interceptor",

@@ -5,0 +5,0 @@ "repository": {

import BsLoadingOverlayHttpInterceptorInterceptor from './BsLoadingOverlayHttpInterceptorInterceptor';
import IBsLoadingOverlayOptions from 'angular-loading-overlay/source/IBsLoadingOverlayOptions';
import IBsLoadingOverlayHttpInterceptorOptions from './IBsLoadingOverlayHttpInterceptorOptions';
import {BsLoadingOverlayService} from 'angular-loading-overlay/source/BsLoadingOverlayService';

@@ -7,3 +7,3 @@

(bsLoadingOverlayService: BsLoadingOverlayService) =>
(config: IBsLoadingOverlayOptions) =>
(config: IBsLoadingOverlayHttpInterceptorOptions) =>
new BsLoadingOverlayHttpInterceptorInterceptor(config, bsLoadingOverlayService);

@@ -10,0 +10,0 @@

import BsLoadingOverlayHttpInterceptor from './BsLoadingOverlayHttpInterceptorInterceptor';
import {BsLoadingOverlayService} from 'angular-loading-overlay/source/BsLoadingOverlayService';
import IBsLoadingOverlayOptions from 'angular-loading-overlay/source/IBsLoadingOverlayOptions';
import IBsLoadingOverlayHttpInterceptorOptions from './IBsLoadingOverlayHttpInterceptorOptions';

@@ -8,3 +8,3 @@ describe('Interceptor', () => {

let service: any;
let options: IBsLoadingOverlayOptions;
let options: IBsLoadingOverlayHttpInterceptorOptions;
let requestConfig: ng.IRequestConfig;

@@ -28,63 +28,105 @@ let responsePromise: ng.IHttpPromiseCallbackArg<any>;

options = {
referenceId: 'some reference id'
};
interceptor = new BsLoadingOverlayHttpInterceptor(options, service);
});
it('should return provided options on request', () => {
let returnedRequest = interceptor.request(requestConfig);
expect(returnedRequest).toEqual(requestConfig);
});
describe('request', () => {
it('should return provided request config', () => {
let returnedRequestConfig = interceptor.request(requestConfig);
expect(returnedRequestConfig).toEqual(requestConfig);
});
it('should call service start with provided options on request', () => {
interceptor.request(requestConfig);
it('should call service start with provided options', () => {
interceptor.request(requestConfig);
expect(service.start.calledWith(options)).toBeTruthy();
});
expect(service.start.calledWith(options)).toBeTruthy();
});
it('should call service start once on request', () => {
interceptor.request(requestConfig);
it('should call service start once', () => {
interceptor.request(requestConfig);
expect(service.start.calledOnce).toBeTruthy();
});
expect(service.start.calledOnce).toBeTruthy();
});
it('should call service start once on request called twice', () => {
interceptor.request(requestConfig);
interceptor.request(requestConfig);
it('should call service start once on called twice', () => {
interceptor.request(requestConfig);
interceptor.request(requestConfig);
expect(service.start.calledOnce).toBeTruthy();
});
expect(service.start.calledOnce).toBeTruthy();
});
it('should call service start once on request called twice', () => {
interceptor.request(requestConfig);
interceptor.request(requestConfig);
it('should call service start once on called twice', () => {
interceptor.request(requestConfig);
interceptor.request(requestConfig);
expect(service.start.calledOnce).toBeTruthy();
});
expect(service.start.calledOnce).toBeTruthy();
});
it('should return provided rejection on request error', () => {
const rejection = {rejectionField: 123};
let returnedRejection = interceptor.requestError(rejection);
expect(returnedRejection).toEqual(rejection);
});
it('should call service start once on called after response', () => {
interceptor.response(responsePromise);
interceptor.request(requestConfig);
it('should call service stop once on request error after request', () => {
interceptor.request(requestConfig);
interceptor.requestError(requestConfig);
expect(service.start.calledOnce).toBeTruthy();
});
expect(service.stop.calledOnce).toBeTruthy();
});
describe('with matcher provided', () => {
beforeEach(() => {
options = {
requestsMatcher: (requestConfig) => requestConfig.url === 'some url'
};
interceptor = new BsLoadingOverlayHttpInterceptor(options, service);
});
it('should call service stop with provided options on request error after request', () => {
interceptor.request(requestConfig);
interceptor.requestError(requestConfig);
it('should call service start once if requestMatcher returns true matching requestConfig', () => {
interceptor.request({
url: 'some url',
method: 'GET'
});
expect(service.stop.calledWith(options)).toBeTruthy();
expect(service.start.calledOnce).toBeTruthy();
});
it('should not call service start if requestMatcher returns false matching requestConfig', () => {
interceptor.request({
url: 'another url, no match here',
method: 'GET'
});
expect(service.start.called).toBeFalsy();
});
});
});
it('should call service stop once on request error called twice after request called twice', () => {
interceptor.request(requestConfig);
interceptor.request(requestConfig);
interceptor.requestError(requestConfig);
interceptor.requestError(requestConfig);
describe('requestError', () => {
it('should return provided rejection', () => {
const rejection = {rejectionField: 123};
let returnedRejection = interceptor.requestError(rejection);
expect(returnedRejection).toEqual(rejection);
});
expect(service.stop.calledOnce).toBeTruthy();
it('should call service stop once on called after request', () => {
interceptor.request(requestConfig);
interceptor.requestError(requestConfig);
expect(service.stop.calledOnce).toBeTruthy();
});
it('should call service stop with provided options on called after request', () => {
interceptor.request(requestConfig);
interceptor.requestError(requestConfig);
expect(service.stop.calledWith(options)).toBeTruthy();
});
it('should call service stop once on called twice after request called twice', () => {
interceptor.request(requestConfig);
interceptor.request(requestConfig);
interceptor.requestError(requestConfig);
interceptor.requestError(requestConfig);
expect(service.stop.calledOnce).toBeTruthy();
});
});

@@ -105,2 +147,8 @@

it('should not call service stop on response called without request called', () => {
interceptor.response(responsePromise);
expect(service.stop.called).toBeFalsy();
});
it('should call service stop with provided options on response called after request called', () => {

@@ -107,0 +155,0 @@ interceptor.request(requestConfig);

@@ -1,2 +0,2 @@

import IBsLoadingOverlayOptions from 'angular-loading-overlay/source/IBsLoadingOverlayOptions';
import IBsLoadingOverlayHttpInterceptorOptions from './IBsLoadingOverlayHttpInterceptorOptions';
import {BsLoadingOverlayService} from 'angular-loading-overlay/source/BsLoadingOverlayService';

@@ -6,3 +6,3 @@

constructor(
private config: IBsLoadingOverlayOptions,
private config: IBsLoadingOverlayHttpInterceptorOptions = {},
private bsLoadingOverlayService: BsLoadingOverlayService

@@ -22,12 +22,21 @@ ) {}

private onResponse() {
this.requestsCount --;
const newRequestsCount = this.requestsCount - 1;
if (this.requestsCount === 0) {
if (newRequestsCount === 0) {
this.bsLoadingOverlayService.stop(this.config);
}
this.requestsCount = Math.max(0, newRequestsCount);
}
request = (config: ng.IRequestConfig) => {
this.onRequest();
return config;
request = (requestConfig: ng.IRequestConfig) => {
if (this.config.requestsMatcher) {
if (this.config.requestsMatcher(requestConfig)) {
this.onRequest();
}
} else {
this.onRequest();
}
return requestConfig;
};

@@ -34,0 +43,0 @@

@@ -22,4 +22,5 @@ {

"source/BsLoadingOverlayHttpInterceptorInterceptor.ts",
"source/BsLoadingOverlayHttpInterceptorModule.ts"
"source/BsLoadingOverlayHttpInterceptorModule.ts",
"source/IBsLoadingOverlayHttpInterceptorOptions.ts"
]
}
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc