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

make-cancellable-promise

Package Overview
Dependencies
Maintainers
1
Versions
7
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

make-cancellable-promise - npm Package Compare versions

Comparing version 1.0.0 to 1.1.0

dist/esm/index.js

35

package.json
{
"name": "make-cancellable-promise",
"version": "1.0.0",
"version": "1.1.0",
"description": "Make any Promise cancellable.",
"main": "dist/index.js",
"main": "dist/umd/index.js",
"module": "dist/esm/index.js",
"source": "src/index.js",
"sideEffects": false,
"scripts": {
"build": "babel src -d dist --ignore **/__tests__,**/*.spec.js",
"build": "yarn build-esm && yarn build-umd",
"build-esm": "BABEL_ENV=production-esm babel src -d dist/esm --ignore \"**/*.spec.js\"",
"build-umd": "BABEL_ENV=production-umd babel src -d dist/umd --ignore \"**/*.spec.js\"",
"clean": "rimraf dist",

@@ -13,3 +17,3 @@ "jest": "jest",

"lint": "eslint src/ --ext .jsx,.js",
"prepublishOnly": "yarn clean && yarn build",
"prepack": "yarn clean && yarn build",
"test": "yarn lint && yarn jest"

@@ -28,11 +32,13 @@ },

"devDependencies": {
"@babel/cli": "^7.5.0",
"@babel/core": "^7.5.0",
"@babel/preset-env": "^7.5.0",
"eslint": "^5.16.0",
"eslint-config-airbnb-base": "^13.1.0",
"eslint-plugin-import": "^2.18.0",
"jest": "^24.8.0",
"rimraf": "^2.6.3"
"@babel/cli": "^7.8.0",
"@babel/core": "^7.9.0",
"@babel/preset-env": "^7.9.0",
"eslint": "~7.19.0",
"eslint-config-wojtekmaj": "^0.5.0",
"jest": "^26.6.0",
"rimraf": "^3.0.0"
},
"resolutions": {
"semver@7.0.0": "^7.0.0"
},
"files": [

@@ -47,3 +53,4 @@ "LICENSE",

"url": "https://github.com/wojtekmaj/make-cancellable-promise.git"
}
}
},
"funding": "https://github.com/wojtekmaj/make-cancellable-promise?sponsor=1"
}

43

README.md

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

[![npm](https://img.shields.io/npm/v/make-cancellable-promise.svg)](https://www.npmjs.com/package/make-cancellable-promise) ![downloads](https://img.shields.io/npm/dt/make-cancellable-promise.svg) ![build](https://img.shields.io/travis/wojtekmaj/make-cancellable-promise/master.svg) ![dependencies](https://img.shields.io/david/wojtekmaj/make-cancellable-promise.svg) ![dev dependencies](https://img.shields.io/david/dev/wojtekmaj/make-cancellable-promise.svg) [![tested with jest](https://img.shields.io/badge/tested_with-jest-99424f.svg)](https://github.com/facebook/jest)
[![npm](https://img.shields.io/npm/v/make-cancellable-promise.svg)](https://www.npmjs.com/package/make-cancellable-promise) ![downloads](https://img.shields.io/npm/dt/make-cancellable-promise.svg) [![CI](https://github.com/wojtekmaj/make-cancellable-promise/workflows/CI/badge.svg)](https://github.com/wojtekmaj/make-cancellable-promise/actions) ![dependencies](https://img.shields.io/david/wojtekmaj/make-cancellable-promise.svg) ![dev dependencies](https://img.shields.io/david/dev/wojtekmaj/make-cancellable-promise.svg) [![tested with jest](https://img.shields.io/badge/tested_with-jest-99424f.svg)](https://github.com/facebook/jest)

@@ -30,44 +30,5 @@ # Make-Cancellable-Promise

Here's how you can use `makeCancellablePromise` with React components:
Here's how you can use `makeCancellablePromise` with React:
```jsx
class MyComponent extends Component {
state = {
status: 'initial',
}
componentDidMount() {
this.cancellable = makeCancellable(fetchData());
this.cancellable.promise
.then(() => this.setState({ status: 'success' }))
.catch(() => this.setState({ status: 'error' }));
};
componentWillUnmount() {
this.cancellable.cancel();
}
render() {
const { status } = this.state;
const text = (() => {
switch (status) {
case 'pending': return 'Fetching…';
case 'success': return 'Success';
case 'error': return 'Error!';
default: return 'Click to fetch';
}
})();
return (
<p>{text}</p>
);
}
}
```
or with React Hooks:
```jsx
function MyComponent() {

@@ -74,0 +35,0 @@ const [status, setStatus] = useState('initial');

@@ -7,3 +7,3 @@ export default function makeCancellablePromise(promise) {

.then((...args) => !isCancelled && resolve(...args))
.catch(error => !isCancelled && reject(error));
.catch((error) => !isCancelled && reject(error));
});

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

@@ -0,0 +0,0 @@ import makeCancellablePromise from './index';

Sorry, the diff of this file is not supported yet

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