https://github.com/onetapinc/async-chain-proxy
Provide a method chain interface to an class instance.
https://github.com/onetapinc/async-chain-proxy
Last synced: 13 days ago
JSON representation
Provide a method chain interface to an class instance.
- Host: GitHub
- URL: https://github.com/onetapinc/async-chain-proxy
- Owner: OnetapInc
- Created: 2017-05-09T07:23:41.000Z (about 8 years ago)
- Default Branch: master
- Last Pushed: 2019-07-31T00:21:29.000Z (almost 6 years ago)
- Last Synced: 2025-05-08T02:49:26.102Z (13 days ago)
- Language: JavaScript
- Homepage:
- Size: 8.79 KB
- Stars: 4
- Watchers: 4
- Forks: 3
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
async-chain-proxy provides method chain interfaces for accessing async methods.
## How to use
### method chain
```js
class A {
async foo () {
console.log('foo')
}
async bar () {
console.log('bar')
}
}const chainProxy = require('async-chain-proxy')
const obj = chainProxy(new A())
obj.foo().bar().end()// output
>foo
>bar
```### receive a return value
```js
class A {
async foo () {
return 'foo'
}
}
const chainProxy = require('async-chain-proxy')
const obj = chainProxy(new A())
obj.foo().result((v) => console.log(v)).end()// output
>foo
```### API
#### constructor(target, options = {})
##### options
- resultFuncName(default: 'result') : If you don't prefer result function name, you can change.
- endFuncName(default: 'end') : If you don't prefer end function name, you can change.
- onChainFinished(default: null) : this is a callback function that is called after end().#### result(r)
This function is used for receiving result of previous action.
#### end()
Indicates end of chained actions. If you didn't call end(), all the actions aren't called.
#### target
Returns target object.