Skip to content

Commit

Permalink
fix(.use): allow passing options as second argument
Browse files Browse the repository at this point in the history
it is directly passed as 2nd argument to the plugin function. Like .use(fn, { foo: 12 }), fn
signature will be (app, opts)
  • Loading branch information
tunnckoCore committed Apr 2, 2017
1 parent 630518e commit 958ed95
Show file tree
Hide file tree
Showing 7 changed files with 47 additions and 37 deletions.
23 changes: 12 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -189,13 +189,14 @@ console.log(emitter._allEvents.foo.length) // => 2
console.log(emitter._allEvents.bar.length) // => 1
```

### [.use](src/index.js#L96)
### [.use](src/index.js#L99)
> Invokes `plugin` function immediately, which is passed with `app` instance. You can use it for adding more methods or properties to the instance. Useful if you want to make dush to work with DOM for example.
**Params**

* `plugin` **{Function}**: A function passed with `(app)` signature
* `returns` **{Object}**: The `dush` instance for chaining
* `plugin` **{Function}**: A function passed with `(app, options)` signature
* `options` **{Object}**: optional, passed as second argument to `plugin` function
* `returns` **{Object}**: self "app" for chaining

**Example**

Expand All @@ -215,7 +216,7 @@ console.log(app.foo) // => 'bar'
app.hello('World')
```

### [.on](src/index.js#L131)
### [.on](src/index.js#L134)
> Add `handler` for `name` event.
See [JSBin Example](http://jsbin.com/xeketuruto/edit?js,console).
Expand All @@ -225,7 +226,7 @@ See [JSBin Example](http://jsbin.com/xeketuruto/edit?js,console).
* `name` **{String}**: Type of event to listen for, or `'*'` for all events
* `handler` **{Function}**: Function to call in response to given event
* `once` **{Boolean}**: Make `handler` be called only once, the `.once` method use this internally
* `returns` **{Object}**: The `dush` instance for chaining
* `returns` **{Object}**: self "app" for chaining

**Example**

Expand All @@ -243,7 +244,7 @@ emitter
emitter.emit('hi', 'world')
```

### [.once](src/index.js#L181)
### [.once](src/index.js#L184)
> Add `handler` for `name` event that will be called only one time.
See [JSBin Example](http://jsbin.com/teculorima/edit?js,console).
Expand All @@ -252,7 +253,7 @@ See [JSBin Example](http://jsbin.com/teculorima/edit?js,console).

* `name` **{String}**: Type of event to listen for, or `'*'` for all events
* `handler` **{Function}**: Function to call in response to given event
* `returns` **{Object}**: The `dush` instance for chaining
* `returns` **{Object}**: self "app" for chaining

**Example**

Expand All @@ -273,7 +274,7 @@ emitter
console.log(called) // => 1
```

### [.off](src/index.js#L221)
### [.off](src/index.js#L224)
> Remove `handler` for `name` event. If `handler` not passed will remove **all** listeners for that `name` event.
See [JSBin Example](http://jsbin.com/nujucoquvi/3/edit?js,console).
Expand All @@ -282,7 +283,7 @@ See [JSBin Example](http://jsbin.com/nujucoquvi/3/edit?js,console).

* `name` **{String}**: Type of event to listen for, or `'*'` for all events
* `handler` **{Function}**: Function to call in response to given event
* `returns` **{Object}**: The `dush` instance for chaining
* `returns` **{Object}**: self "app" for chaining

**Example**

Expand All @@ -306,7 +307,7 @@ emitter.off('foo')
emitter.emit('foo')
```

### [.emit](src/index.js#L267)
### [.emit](src/index.js#L270)
> Invoke all handlers for given `name` event. If present, `'*'` listeners are invoked too with `(type, ...rest)` signature, where the `type` argument is a string representing the name of the called event; and all of the rest arguments.
See [JSBin Example](http://jsbin.com/muqujavolu/edit?js,console).
Expand All @@ -315,7 +316,7 @@ See [JSBin Example](http://jsbin.com/muqujavolu/edit?js,console).

* `name` **{String}**: The name of the event to invoke
* `args` **{any}**: Any number of arguments of any type of value, passed to each listener
* `returns` **{Object}**: The `dush` instance for chaining
* `returns` **{Object}**: self "app" for chaining

**Example**

Expand Down
19 changes: 11 additions & 8 deletions dist/dush.common.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,8 @@ function dush () {
* or properties to the instance. Useful if you want to make
* dush to work with DOM for example.
*
* **Example**
*
* ```js
* const app = dush()
*
Expand All @@ -88,13 +90,14 @@ function dush () {
* ```
*
* @name .use
* @param {Function} `plugin` A function passed with `(app)` signature
* @return {Object} The `dush` instance for chaining
* @param {Function} `plugin` A function passed with `(app, options)` signature
* @param {Object} `options` optional, passed as second argument to `plugin` function
* @return {Object} self "app" for chaining
* @api public
*/

use: function use (plugin) {
var ret = plugin(app);
use: function use (plugin, options) {
var ret = plugin(app, options);
return ret || app
},

Expand Down Expand Up @@ -124,7 +127,7 @@ function dush () {
* @param {Function} `handler` Function to call in response to given event
* @param {Boolean} `once` Make `handler` be called only once,
* the `.once` method use this internally
* @return {Object} The `dush` instance for chaining
* @return {Object} self "app" for chaining
* @api public
*/

Expand Down Expand Up @@ -174,7 +177,7 @@ function dush () {
* @name .once
* @param {String} `name` Type of event to listen for, or `'*'` for all events
* @param {Function} `handler` Function to call in response to given event
* @return {Object} The `dush` instance for chaining
* @return {Object} self "app" for chaining
* @api public
*/

Expand Down Expand Up @@ -214,7 +217,7 @@ function dush () {
* @name .off
* @param {String} `name` Type of event to listen for, or `'*'` for all events
* @param {Function} `handler` Function to call in response to given event
* @return {Object} The `dush` instance for chaining
* @return {Object} self "app" for chaining
* @api public
*/

Expand Down Expand Up @@ -260,7 +263,7 @@ function dush () {
* @name .emit
* @param {String} `name` The name of the event to invoke
* @param {any} `args` Any number of arguments of any type of value, passed to each listener
* @return {Object} The `dush` instance for chaining
* @return {Object} self "app" for chaining
* @api public
*/

Expand Down
19 changes: 11 additions & 8 deletions dist/dush.es.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,8 @@ function dush () {
* or properties to the instance. Useful if you want to make
* dush to work with DOM for example.
*
* **Example**
*
* ```js
* const app = dush()
*
Expand All @@ -86,13 +88,14 @@ function dush () {
* ```
*
* @name .use
* @param {Function} `plugin` A function passed with `(app)` signature
* @return {Object} The `dush` instance for chaining
* @param {Function} `plugin` A function passed with `(app, options)` signature
* @param {Object} `options` optional, passed as second argument to `plugin` function
* @return {Object} self "app" for chaining
* @api public
*/

use: function use (plugin) {
var ret = plugin(app);
use: function use (plugin, options) {
var ret = plugin(app, options);
return ret || app
},

Expand Down Expand Up @@ -122,7 +125,7 @@ function dush () {
* @param {Function} `handler` Function to call in response to given event
* @param {Boolean} `once` Make `handler` be called only once,
* the `.once` method use this internally
* @return {Object} The `dush` instance for chaining
* @return {Object} self "app" for chaining
* @api public
*/

Expand Down Expand Up @@ -172,7 +175,7 @@ function dush () {
* @name .once
* @param {String} `name` Type of event to listen for, or `'*'` for all events
* @param {Function} `handler` Function to call in response to given event
* @return {Object} The `dush` instance for chaining
* @return {Object} self "app" for chaining
* @api public
*/

Expand Down Expand Up @@ -212,7 +215,7 @@ function dush () {
* @name .off
* @param {String} `name` Type of event to listen for, or `'*'` for all events
* @param {Function} `handler` Function to call in response to given event
* @return {Object} The `dush` instance for chaining
* @return {Object} self "app" for chaining
* @api public
*/

Expand Down Expand Up @@ -258,7 +261,7 @@ function dush () {
* @name .emit
* @param {String} `name` The name of the event to invoke
* @param {any} `args` Any number of arguments of any type of value, passed to each listener
* @return {Object} The `dush` instance for chaining
* @return {Object} self "app" for chaining
* @api public
*/

Expand Down
2 changes: 1 addition & 1 deletion dist/dush.umd.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Binary file modified dist/dush.umd.js.gz
Binary file not shown.
2 changes: 1 addition & 1 deletion dist/dush.umd.js.map

Large diffs are not rendered by default.

19 changes: 11 additions & 8 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,8 @@ export default function dush () {
* or properties to the instance. Useful if you want to make
* dush to work with DOM for example.
*
* **Example**
*
* ```js
* const app = dush()
*
Expand All @@ -88,13 +90,14 @@ export default function dush () {
* ```
*
* @name .use
* @param {Function} `plugin` A function passed with `(app)` signature
* @return {Object} The `dush` instance for chaining
* @param {Function} `plugin` A function passed with `(app, options)` signature
* @param {Object} `options` optional, passed as second argument to `plugin` function
* @return {Object} self "app" for chaining
* @api public
*/

use (plugin) {
const ret = plugin(app)
use (plugin, options) {
const ret = plugin(app, options)
return ret || app
},

Expand Down Expand Up @@ -124,7 +127,7 @@ export default function dush () {
* @param {Function} `handler` Function to call in response to given event
* @param {Boolean} `once` Make `handler` be called only once,
* the `.once` method use this internally
* @return {Object} The `dush` instance for chaining
* @return {Object} self "app" for chaining
* @api public
*/

Expand Down Expand Up @@ -174,7 +177,7 @@ export default function dush () {
* @name .once
* @param {String} `name` Type of event to listen for, or `'*'` for all events
* @param {Function} `handler` Function to call in response to given event
* @return {Object} The `dush` instance for chaining
* @return {Object} self "app" for chaining
* @api public
*/

Expand Down Expand Up @@ -214,7 +217,7 @@ export default function dush () {
* @name .off
* @param {String} `name` Type of event to listen for, or `'*'` for all events
* @param {Function} `handler` Function to call in response to given event
* @return {Object} The `dush` instance for chaining
* @return {Object} self "app" for chaining
* @api public
*/

Expand Down Expand Up @@ -260,7 +263,7 @@ export default function dush () {
* @name .emit
* @param {String} `name` The name of the event to invoke
* @param {any} `args` Any number of arguments of any type of value, passed to each listener
* @return {Object} The `dush` instance for chaining
* @return {Object} self "app" for chaining
* @api public
*/

Expand Down

0 comments on commit 958ed95

Please sign in to comment.