https://github.com/prscx/simplified-promise
Enhance Simplicity of JS Promise
https://github.com/prscx/simplified-promise
Last synced: over 1 year ago
JSON representation
Enhance Simplicity of JS Promise
- Host: GitHub
- URL: https://github.com/prscx/simplified-promise
- Owner: prscX
- License: mit
- Created: 2018-01-09T05:17:56.000Z (over 8 years ago)
- Default Branch: master
- Last Pushed: 2018-06-24T07:31:54.000Z (about 8 years ago)
- Last Synced: 2025-03-23T17:45:36.788Z (over 1 year ago)
- Language: JavaScript
- Homepage:
- Size: 40 KB
- Stars: 4
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README

Simplified Promise
If this project has helped you out, please support us with a star 🌟
It enhances the simplicity of JavaScript Promise by adding below static API's to the out of box Promise:
- `Promise.Create(): Promise`
- `Promise.All(): Promise`
## ES6 Promise Usage
`new Promise( /* executor */ function(resolve, reject) { ... } );`
**Parameters**
- __executor__: A function that is passed with the arguments resolve and reject
If we use standard Promise then it is mandatory to pass executor function:
~~~~
function myAsyncFunction(url) {
return new Promise((resolve, reject) => {
const xhr = new XMLHttpRequest();
xhr.open("GET", url);
xhr.onload = () => resolve(xhr.responseText);
xhr.onerror = () => reject(xhr.statusText);
xhr.send();
});
}
~~~~
Doing this we need to wrap our implementation in executor **Function**. In my opinion it increases source hierarchy
## Why it is useful
- It allows us to write neat & clean source
- Less source hierarchy
- Easy to use and understand
## 💻 Usage
`$ npm install --save simplified-promise`
`import * from 'simplified-promise'`
- Promise.Create
~~~~
foo() {
let promise = Promise.Create()
asyncFoo()
.then(() => promise.resolve())
.catch(err => promise.reject(err))
return promise
}
~~~~
- Promise.All
~~~~
foo() {
let promises = []
promises.push(asyncFoo1())
promises.push(asyncFoo2())
return Promise.All(promises)
}
~~~~
## ✨ Credits
## 🤔 How to contribute
Have an idea? Found a bug? Please raise to [ISSUES](https://github.com/prscX/simplified-promise/issues).
Contributions are welcome and are greatly appreciated! Every little bit helps, and credit will always be given.
## 💫 Where is this library used?
If you are using this library in one of your projects, add it in this list below. ✨
## 📜 License
This library is provided under the Apache 2 License.
Simplified Promise @ [prscX](https://github.com/prscX)
## 💖 Support my projects
I open-source almost everything I can, and I try to reply everyone needing help using these projects. Obviously, this takes time. You can integrate and use these projects in your applications for free! You can even change the source code and redistribute (even resell it).
However, if you get some profit from this or just want to encourage me to continue creating stuff, there are few ways you can do it:
* Starring and sharing the projects you like 🚀
* If you're feeling especially charitable, please follow [prscX](https://github.com/prscX) on GitHub.
Thanks! ❤️
[prscX.github.io](https://prscx.github.io)
Pranav >
