Skip to content

Commit

Permalink
fix(readme): add api docs
Browse files Browse the repository at this point in the history
  • Loading branch information
tunnckoCore committed Mar 19, 2017
1 parent 3b319eb commit 08d512a
Show file tree
Hide file tree
Showing 2 changed files with 99 additions and 11 deletions.
65 changes: 54 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ You might also be interested in [dush](https://github.com/tunnckocore/dush#readm
- [Install](#install)
- [Usage](#usage)
- [API](#api)
* [noChaining](#nochaining)
- [Related](#related)
- [Contributing](#contributing)
- [Building docs](#building-docs)
Expand Down Expand Up @@ -47,6 +48,46 @@ const dushNoChaining = require('dush-no-chaining')

## API

### [noChaining](index.js#L55)
> A plugin that removes support for emitter methods to be chainable. Basically, by default [dush][]'s methods (and most of other eventemitters) are chainable and some user don't like that feature that I need.
* `returns` **{Function}**: A plugin function that can be passed to [dush][], [minibase][] or [base][]

**Example**

```js
const dush = require('dush')
const noChaining = require('dush-no-chaining')

const app = dush()

// by default they are chainable
app
.on('foo', () => {})
.once('bar', () => {})
.emit('bar', 123)
.off('foo')
.emit('bar', 333)
.emit('foo', 1)

// but when add this plugin
// they are not chainable
const emitter = dush().use(noChaining())

const noop = () => {}
const on = emitter.on('foo', noop)
console.log(on) // => undefined

const off = emitter.off('foo', noop)
console.log(off) // => undefined

const once = emitter.once('bar', noop)
console.log(once) // => undefined

const emit = emitter.emit('bar', 123)
console.log(emit) // => undefined
```

## Related
- [always-done](https://www.npmjs.com/package/always-done): Handle completion and errors with elegance! Support for streams, callbacks, promises, child processes, async/await and sync functions. A drop-in replacement… [more](https://github.com/hybridables/always-done#readme) | [homepage](https://github.com/hybridables/always-done#readme "Handle completion and errors with elegance! Support for streams, callbacks, promises, child processes, async/await and sync functions. A drop-in replacement for [async-done][] - pass 100% of its tests plus more")
- [base](https://www.npmjs.com/package/base): base is the foundation for creating modular, unit testable and highly pluggable node.js applications, starting with a handful of common… [more](https://github.com/node-base/base) | [homepage](https://github.com/node-base/base "base is the foundation for creating modular, unit testable and highly pluggable node.js applications, starting with a handful of common methods, like `set`, `get`, `del` and `use`.")
Expand Down Expand Up @@ -103,6 +144,18 @@ Copyright © 2016-2017, [Charlike Mike Reagent](https://i.am.charlike.online). R
_This file was generated by [verb-generate-readme](https://github.com/verbose/verb-generate-readme), v0.4.3, on March 19, 2017._
_Project scaffolded using [charlike][] cli._

[always-done]: https://github.com/hybridables/always-done
[async-done]: https://github.com/gulpjs/async-done
[base]: https://github.com/node-base/base
[charlike]: https://github.com/tunnckocore/charlike
[commitizen]: https://github.com/commitizen/cz-cli
[dezalgo]: https://github.com/npm/dezalgo
[minibase]: https://github.com/node-minibase/minibase
[once]: https://github.com/isaacs/once
[standard-version]: https://github.com/conventional-changelog/standard-version
[verb-generate-readme]: https://github.com/verbose/verb-generate-readme
[verb]: https://github.com/verbose/verb

[license-url]: https://www.npmjs.com/package/dush-no-chaining
[license-img]: https://img.shields.io/npm/l/dush-no-chaining.svg

Expand Down Expand Up @@ -130,14 +183,4 @@ _Project scaffolded using [charlike][] cli._
[paypalme-url]: https://www.paypal.me/tunnckoCore
[paypalme-img]: https://img.shields.io/badge/paypal-donate-brightgreen.svg

[always-done]: https://github.com/hybridables/always-done
[async-done]: https://github.com/gulpjs/async-done
[base]: https://github.com/node-base/base
[charlike]: https://github.com/tunnckocore/charlike
[commitizen]: https://github.com/commitizen/cz-cli
[dezalgo]: https://github.com/npm/dezalgo
[minibase]: https://github.com/node-minibase/minibase
[once]: https://github.com/isaacs/once
[standard-version]: https://github.com/conventional-changelog/standard-version
[verb-generate-readme]: https://github.com/verbose/verb-generate-readme
[verb]: https://github.com/verbose/verb
[dush]: https://github.com/tunnckocore/dush
45 changes: 45 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,51 @@

'use strict'

/**
* > A plugin that removes support for emitter methods to be chainable. Basically, by
* default [dush][]'s methods (and most of other eventemitters) are chainable
* and some user don't like that feature that I need.
*
* **Example**
*
* ```js
* const dush = require('dush')
* const noChaining = require('dush-no-chaining')
*
* const app = dush()
*
* // by default they are chainable
* app
* .on('foo', () => {})
* .once('bar', () => {})
* .emit('bar', 123)
* .off('foo')
* .emit('bar', 333)
* .emit('foo', 1)
*
* // but when add this plugin
* // they are not chainable
* const emitter = dush().use(noChaining())
*
* const noop = () => {}
* const on = emitter.on('foo', noop)
* console.log(on) // => undefined
*
* const off = emitter.off('foo', noop)
* console.log(off) // => undefined
*
* const once = emitter.once('bar', noop)
* console.log(once) // => undefined
*
* const emit = emitter.emit('bar', 123)
* console.log(emit) // => undefined
* ```
*
* @name noChaining
* @return {Function} A plugin function that can be passed to [dush][], [minibase][] or [base][]
* @api public
*/

module.exports = function dushNoChaining () {
return function noChaining (app) {
var map = {
Expand Down

0 comments on commit 08d512a

Please sign in to comment.