npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

ng-http-canceller

v0.0.2

Published

This module will help you to cancel $http requests

Downloads

2

Readme

ng-http-canceller

This module will help you to cancel $http requests

Install

You can install this package either with npm or with bower.

npm

npm install ng-http-canceller

Then add a <script> to your index.html:

<script src="/node_modules/ng-http-canceller/httpCancellerModule.js"></script>

Or require('ng-http-canceller') from your code.

bower

bower install ng-http-canceller

Then add a <script> to your index.html:

<script src="/bower_components/ng-http-canceller/ngHttpCanceller.js"></script>

Dependency Injection

Import it to the angular applicaiton:

angular.module('myApp', ['ngHttpCanceller']);

Documentation:

This package helps you to prevent the same API call multiple times. It cancels all the running API calls except the latest one. For example, the user needs some data after pressing some button. That button internally calls an API which returns some data & that data reflects into the UI. If the user presses that button very frequently then same API will get called multiple times before getting its response & All called API returns same response & user face flicker issue.

To achieve this functionality please follow the bellow following steps:

  1. Register your API entry into httpCanceller factory using some unique key.
httpCanceller.pushEntry(apiKey, canceler);
  1. Unregister your entry using same unique key from the factory after getting the API response(error or success) to prevent the memory leaks.
httpCanceller.removeEntry(apiKey);

How to use it :

1. Register API entry for $http :

/**
* This is the unique key for the API registration to httpCanceller factory.
*/
var apiKey = 'key_' + uniqueKey; 
var canceler = $q.defer(),
    request = {
  		method : method type like 'get', 'post', 'delete', 'put',
  		url : '',
  		headers : {
  			'Content-Type': 'application/json'
  		},
  		params : {},
  		data : {},
  		timeout : canceler.promise
    };
/**
*	Registering the API entry to httpCanceller factory(Step 1)
*/  
httpCanceller.pushEntry(apiKey, canceler);
$http(req).then(function onSuccess(response){
  /**
	*	Unregistering the API entry from httpCanceller factory(Step 2)
	*/
	httpCanceller.removeEntry(apiKey);
	return response
}, function onError(){
  /**
	*	Unregistering the API entry from httpCanceller factory(Step 2)
	*/ 
	httpCanceller.removeEntry(apiKey);
});

2. Register API entry for restangular :

/**
* This is the unique key for the API registration to httpCanceller factory.
*/
var apiKey = 'key_' + uniqueKey;

var canceler = $q.defer(),
	httpConfig  = {
		timeout  : canceler.promise
	},
apiResponse = !newRouteName ? Restangular.one(apiPath) : Restangular.oneUrl(newRouteName, apiPath);
apiResponse = apiResponse.post('api_path', urlParameters);
apiResponse = apiResponse.withHttpConfig(httpConfig);
/**
*	Registering the API entry to httpCanceller factory(Step 1)
*/	
httpCanceller.pushEntry(apiKey, canceler);

apiResponse.then(function onSuccess(response){
	/**
	*	Unregistering the API entry from httpCanceller factory(Step 2)
	*/
	httpCanceller.removeEntry(apiKey);
	return response
}, function onError(){
  /**
	*	Unregistering the API entry from httpCanceller factory(Step 2)
	*/
	httpCanceller.removeEntry(apiKey);
});

3. To cancel all the running requests which has been registered:

httpCanceller.abortAllRunningRequest();

4. To cancel specific request:

httpCanceller.abortRequest(apiKey);

5. To delete the entry from the factory after getting response:

httpCanceller.removeEntry(apiKey);