From 08d512a7b756c079697ef1fb169a90792bad0ee9 Mon Sep 17 00:00:00 2001 From: tunnckoCore Date: Sun, 19 Mar 2017 14:20:55 +0200 Subject: [PATCH] fix(readme): add api docs --- README.md | 65 +++++++++++++++++++++++++++++++++++++++++++++---------- index.js | 45 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 99 insertions(+), 11 deletions(-) diff --git a/README.md b/README.md index 5bfcc2a..904c656 100644 --- a/README.md +++ b/README.md @@ -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) @@ -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`.") @@ -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 @@ -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 \ No newline at end of file +[dush]: https://github.com/tunnckocore/dush \ No newline at end of file diff --git a/index.js b/index.js index 9aa38b1..2587469 100644 --- a/index.js +++ b/index.js @@ -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 = {