-
Notifications
You must be signed in to change notification settings - Fork 41
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support on close without the instance object #76
Changes from 2 commits
7bd9822
9e4cec2
c1b841f
23b9e7b
6ab5470
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -283,7 +283,7 @@ Boot.prototype.ready = function (func) { | |
}) | ||
} | ||
|
||
function noop () {} | ||
function noop () { } | ||
|
||
function callWithCbOrNextTick (func, cb, context) { | ||
context = this._server | ||
|
@@ -350,9 +350,12 @@ function closeWithCbOrNextTick (func, cb, context) { | |
function encapsulateTwoParam (func, that) { | ||
return _encapsulateTwoParam.bind(that) | ||
function _encapsulateTwoParam (context, cb) { | ||
if (func.length === 0 || func.length === 1) { | ||
if (func.length === 0) { | ||
func(this) | ||
process.nextTick(cb) | ||
} else if (func.length === 1) { | ||
func(cb) | ||
cemremengu marked this conversation as resolved.
Show resolved
Hide resolved
|
||
process.nextTick(cb) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You were right. This needs to change to: func(cb) Remove the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Tests are failing with that change function encapsulateTwoParam (func, that) {
return _encapsulateTwoParam.bind(that)
function _encapsulateTwoParam (context, cb) {
if (func.length === 0) {
func()
process.nextTick(cb)
} else if (func.length === 1) {
func(cb)
} else {
func(this, cb)
}
}
} There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe tests need to be updated to call |
||
} else { | ||
func(this, cb) | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -328,6 +328,20 @@ test('close without a cb', (t) => { | |
app.close() | ||
}) | ||
|
||
test('close without an instance', (t) => { | ||
t.plan(2) | ||
|
||
const app = boot() | ||
|
||
app.onClose((done) => { | ||
t.ok('called') | ||
}) | ||
|
||
app.close(() => { | ||
t.pass('closed') | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. you might want to:
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Looks like length is always 1 as t.is(arguments[0], null)
t.is(arguments[1], undefined) Is that alright? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. then there is possibly something off with your code, as https://github.com/mcollina/avvio/pull/76/files#diff-fe60a8aed4b3103661f9d88361346b0dR353 should be triggered. |
||
}) | ||
}) | ||
|
||
test('close passing not a function', (t) => { | ||
t.plan(1) | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if it is
0
there is no point in calling it withthis
as first argument.