Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/untool/eprom
A deliberately incorrect resettable promise-like JavaScript async primitive powering untool's server-side rendering and module reloading. Mostly conforms with the Promises/A+ spec.
https://github.com/untool/eprom
deferred library promise promise-a-plus thenable
Last synced: 5 days ago
JSON representation
A deliberately incorrect resettable promise-like JavaScript async primitive powering untool's server-side rendering and module reloading. Mostly conforms with the Promises/A+ spec.
- Host: GitHub
- URL: https://github.com/untool/eprom
- Owner: untool
- License: mit
- Created: 2018-10-18T22:07:21.000Z (about 6 years ago)
- Default Branch: master
- Last Pushed: 2024-05-10T13:39:03.000Z (6 months ago)
- Last Synced: 2024-09-22T08:15:40.012Z (about 2 months ago)
- Topics: deferred, library, promise, promise-a-plus, thenable
- Language: JavaScript
- Homepage: https://www.npmjs.com/package/eprom
- Size: 840 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 15
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
# eprom
[![travis](https://img.shields.io/travis/untool/eprom/master.svg)](https://travis-ci.org/untool/eprom) [![npm](https://img.shields.io/npm/v/eprom.svg)](https://www.npmjs.com/package/eprom)
`eprom` is an **e**nhanced **prom**ise implementation. It works by wrapping a globally available [`Promise`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise) class and is as compliant with the [Promises/A+](https://promisesaplus.com) spec as the global `Promise` is.
In addition to the usual `then`, `call` and `finally` instance methods, it provides `resolve` and `reject` methods. In this regard, it resembles jQuery's [`Deferred`](https://api.jquery.com/category/deferred-object/) object. On top of that, it features a `reset` method that enables repeat fulfillment.
### Installation
Using [NPM](https://www.npmjs.com/get-npm):
```text
npm install -S eprom
```Using [Yarn](https://yarnpkg.com/en/):
```text
yarn add eprom
```### API
`eprom`'s `EnhancedPromise` mimics more usual [`Promises`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise) in every way. As such, it provides all class ([`resolve`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise/resolve), [`reject`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise/reject), [`all`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise/all), [`race`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise/race)) and instance ([`then`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise/then), [`catch`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise/catch), [`finally`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise/finally)) methods these provide.
#### `enhancedPromise.resolve(value)`
This method resolves an `EnhancedPromise`'s inner `Promise`, triggering the execution of all `onFulfilled` handlers.
```javascript
const enhancedPromise = new EnhancedPromise();
enhancedPromise.then(value => console.log(value));
enhancedPromise.resolve('foo');
// logs 'foo'
```#### `enhancedPromise.reject(reason)`
This method rejects an `EnhancedPromise`'s inner `Promise`, triggering the execution of all `onRejected` handlers.
```javascript
const enhancedPromise = new EnhancedPromise();
enhancedPromise.catch(reason => console.err(reason));
enhancedPromise.reject('bar');
// logs 'bar'
```#### `enhancedPromise.reset()`
This method creates a fresh inner `Promise` and thus allows for the re-fulfillment of an `EnhancedPromise`. A typical use case for this is handling repeat builds triggered by [Webpack](https://webpack.js.org) in [watch mode](https://webpack.js.org/configuration/watch/).
```javascript
const enhancedPromise = new EnhancedPromise();enhancedPromise.then(value => console.log(value));
enhancedPromise.resolve('foo');
// logs 'foo'enhancedPromise.reset();
enhancedPromise.then(value => console.log(value));
enhancedPromise.resolve('bar');
// logs 'bar'
```