Skip to content

Commit

Permalink
[ci-skip] Update README with examples
Browse files Browse the repository at this point in the history
  • Loading branch information
rtsao committed Apr 12, 2017
1 parent d2d78bd commit 59c477b
Showing 1 changed file with 45 additions and 0 deletions.
45 changes: 45 additions & 0 deletions README.md
Expand Up @@ -10,6 +10,51 @@ See: https://www.chromestatus.com/features/4805872211460096

[![sauce labs test status][sauce-badge]][sauce-href]

## Install

```bash
npm i browser-unhandled-rejection
```
or
```bash
yarn add browser-unhandled-rejection
```

## Usage
### Automatic polyfill
This automatically applies the polyfill to the global `Promise` object if it is needed.
```js
import {auto} from 'browser-unhandled-rejection';

auto(); // Applies polyfill if necessary to window.Promise
```

### Manual polyfill
The following snippet is equivalent to `auto()`:
```js
import {polyfill} from 'browser-unhandled-rejection';

if (typeof PromiseRejectionEvent !== 'undefined') {
polyfill(); // Polyfills window.Promise
}
```

### Ponyfill
This may may useful if you don't want to mutate `window.Promise`:
```js
import MyPromise from 'browser-unhandled-rejection';

window.addEventListener('unhandledrejection', () => {
console.log('unhandledrejection was triggered');
});

MyPromise.reject('will trigger unhandledrejection event');

new MyPromise((resolve, reject) => {
reject('will also trigger unhandledrejection event');
});
```

[npm-badge]: https://badge.fury.io/js/browser-unhandled-rejection.svg
[npm-href]: https://www.npmjs.com/package/browser-unhandled-rejection
[build-badge]: https://travis-ci.org/rtsao/browser-unhandled-rejection.svg?branch=master
Expand Down

0 comments on commit 59c477b

Please sign in to comment.