asynchronous chain function based on Proxy
npm
npm i achain
or yarn
yarn add achain
const achain = require('achain')
let attr = await achain(promise).attr.asyncFunc().asyncFunc()().attr
Before
async function main() {
let user = await getUser(1)
let userDetail = await user.getDetail()
await userDetail.destroy()
let user = await getUser(2)
let name = user.name
}
After
async function main() {
await achain(getUser(1)).getDetail().destroy()
let name = await achain(getUser(2)).name
}
Before
async function main() {
let res = await fetch('/users.json')
let data = res.json()
}
After
var api = achain(fetch)
async function main() {
let data = await api('/users.json').json()
}
MIT