1.0.4 • Published 8 years ago

thenction v1.0.4

Weekly downloads
2
License
MIT
Repository
github
Last release
8 years ago

thenction npm Travis SUSHI-WARE LICENSE

thenction is an abbreviation of thenable function.

Install

$ npm i -S thenction

Usage

const thenction = require('thenction')(Promise)
// or: const thenction = require('thenction')(require('your-favorite-promise-lib'))

const twiceLog = thenction(value => value * 2).then(value => (console.log(value), value))

Promise.resolve(2).then(twiceLog)
//=> 4

twiceLog(2).then(value => console.log(value))
//=> 4
//=> 4

Promise.resolve(2).then(twiceLog.then(twiceLog))
//=> 4
//=> 8

const twiceLogSleep = twiceLog
  .then(value => new Promise(resolve => setTimeout(resolve, 1000, value)))

Promise.resolve(2).then(twiceLogSleep).then(twiceLog)
//=> 4
// after 1s
//=> 8

const twiceLogError = twiceLog
  .then(value => { throw new Error('wow') })
  .catch(error => console.log(error))

Promise.resolve(2).then(twiceLogError)
//=> 4
//=> Error: wow

API

require('thenction')(Promise)

Returns a thenction(baseFn) function.

Promise

Type: Fucntion

Your favorite Promise implementation

thenction(baseFn)

Returns a thenable function.

baseFn

Type: Function

Base function to be composed by then and catch.

thenableFunction.then(onFulfilled, onRejected)

onFulfilled

Type: Function

onRejected

Type: Function

thenableFunction.catch(onRejected)

onRejected

Type: Function

License

MIT and :sushi: © TSUYUSATO "MakeNowJust" Kitsune <make.just.on@gmail.com> 2016

1.0.4

8 years ago

1.0.3

8 years ago

1.0.2

8 years ago

1.0.1

8 years ago

1.0.0

8 years ago