From 2cfde06b25b8cd340052f28d2ebdc5caf251269c Mon Sep 17 00:00:00 2001 From: tunnckoCore Date: Tue, 1 Nov 2016 08:12:17 +0200 Subject: [PATCH] fix(deps): dependencies update related changes --- README.md | 17 +++++++---------- index.js | 14 ++++++-------- utils.js | 2 +- 3 files changed, 14 insertions(+), 19 deletions(-) diff --git a/README.md b/README.md index a3777f3..2126fa0 100644 --- a/README.md +++ b/README.md @@ -156,7 +156,7 @@ console.log(minimist.cache.baz) // => { a: 'b' } console.log(minimist.cache.qux) // => 123 ``` -### [.use](index.js#L239) +### [.use](index.js#L236) > Define a plugin `fn` function to be called immediately upon init. It is recommended `fn` to be synchronous and should not expect asynchronous plugins to work correctly - use plugins for this. Uses [try-catch-callback][] under the hood to handle errors and completion of that synchronous function. _**Never throws - emit events!™**_ See [try-catch-callback][] and/or [try-catch-core][] for more details. @@ -178,21 +178,18 @@ const app = MiniBase({ silent: true, foo: 'bar' }) app .once('error', (err) => console.error(err.stack || err)) - .on('use', function (fn, res) { - // called on each `.use` call - console.log(res) // => 555 - }) .use((app) => { console.log(app.options) // => { silent: true, foo: 'bar' } return 555 }) .use(function () { + console.log(this.options) // => { silent: true, foo: 'bar' } // intentionally foo bar }) ``` -### [#delegate](index.js#L283) +### [#delegate](index.js#L281) > Static method to delegate properties from `provider` to `receiver` and make them non-enumerable. See [delegate-properties][] for more details, it is exact mirror. @@ -217,7 +214,7 @@ console.log(obj.foo) // => 'bar' console.log(obj.qux) // => 123 ``` -### [#define](index.js#L310) +### [#define](index.js#L308) > Static method to define a non-enumerable property on an object. See [define-property][] for more details, it is exact mirror. @@ -241,7 +238,7 @@ console.log(obj.foo) // => 123 console.log(obj.bar()) // => 'qux' ``` -### [#extend](index.js#L347) +### [#extend](index.js#L345) > Static method for inheriting the prototype and static methods of the `MiniBase` class. This method greatly simplifies the process of creating inheritance-based applications. See [static-extend][] for more details. @@ -296,8 +293,8 @@ But before doing anything, please read the [CONTRIBUTING.md](./CONTRIBUTING.md) [define-property]: https://github.com/jonschlinkert/define-property [delegate-properties]: https://github.com/jonschlinkert/delegate-properties [static-extend]: https://github.com/jonschlinkert/static-extend -[try-catch-callback]: https://github.com/tunnckocore/try-catch-callback -[try-catch-core]: https://github.com/tunnckocore/try-catch-core +[try-catch-callback]: https://github.com/hybridables/try-catch-callback +[try-catch-core]: https://github.com/hybridables/try-catch-core [npmjs-url]: https://www.npmjs.com/package/minibase [npmjs-img]: https://img.shields.io/npm/v/minibase.svg?label=minibase diff --git a/index.js b/index.js index ce1f793..b174e0f 100644 --- a/index.js +++ b/index.js @@ -211,15 +211,12 @@ utils.delegate(MiniBase.prototype, { * * app * .once('error', (err) => console.error(err.stack || err)) - * .on('use', function (fn, res) { - * // called on each `.use` call - * console.log(res) // => 555 - * }) * .use((app) => { * console.log(app.options) // => { silent: true, foo: 'bar' } * return 555 * }) * .use(function () { + * console.log(this.options) // => { silent: true, foo: 'bar' } * // intentionally * foo bar * }) @@ -237,8 +234,10 @@ utils.delegate(MiniBase.prototype, { */ use: function use (fn) { - fn = fn.bind(this, this) - utils.tryCatch(fn, (err, res) => { + utils.tryCatchCallback.call(this, fn, { + passCallback: true, + args: [this] + }, (err, res) => { if (err) { var anon = 'anonymous ' + (this._anonymousPluginsCount + 1) err.fn = fn @@ -246,8 +245,7 @@ utils.delegate(MiniBase.prototype, { this.emit('error', err) return } - this.emit('use', fn, res) - }, true) + }) return this } }) diff --git a/utils.js b/utils.js index bb795e1..9142637 100644 --- a/utils.js +++ b/utils.js @@ -14,7 +14,7 @@ require('eventemitter3', 'EventEmitter') require('get-fn-name') require('isobject', 'isObject') require('static-extend') -require('try-catch-callback', 'tryCatch') +require('try-catch-callback') require = fn // eslint-disable-line no-undef, no-native-reassign, no-global-assign /**