-
Notifications
You must be signed in to change notification settings - Fork 40
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
Add support for ready
to return a promise.
#37
Conversation
README.md
Outdated
@@ -234,9 +234,11 @@ The callback changes basing on the parameters your are giving: | |||
3. If two parameters are given to the callback, the first will be the `error` object, the second will be the `done` callback. | |||
4. If three parameters are given to the callback, the first will be the `error` object, the second will be the top level `context` unless you have specified both server and override, in that case the `context` will be what the override returns, and the third the `done` callback. | |||
|
|||
If no callback is provided `ready` will return a Promise that is resolved or rejected once plugins and `after` calls are completed. No data is provided to the `.then` callback, if an error occurs it is provided to the `.catch` callback. |
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.
I think we should provide the context to resolve
.
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.
I've updated my working copy code to do this. I'll update the docs and push the update once it's decided what should be returned from app.ready(callbackForm)
.
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.
This has not been updated
Sorry for the intrusion I'm 👍 for moving ready for a better async support I'm 👎 for return different kind of type depending on a parameter presence |
@allevo you propose to return |
Yeah. And it could be a problem. But returning different type is very a bad thing. For example the |
If we do a semver-major, we might want to do some more work here to better support async/await overall. |
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.
I'm ok with this change, but we should add a check to verify that a user does not register other plugins after the ready
execution.
Should I make @delvedor So I make sure I understand correctly you want me to add a check to if (this.booted) {
throw new Error('plugin cannot be loaded after ready')
} Should that be done in a separate commit so it appears in |
Yes, I'd prefer undefined. @coreyfarrell the check that @delvedor wants is already part of https://github.com/mcollina/avvio/pull/38/files#diff-fe60a8aed4b3103661f9d88361346b0dR185. They will be released together anyway. Go ahead and just do the change on |
Returning undefined helped me catch the fact that I missed the const app = {}
boot(app) Right now I'm manually switching the tests in so I can find/fix the issues with |
I'm now realizing github probably didn't send any notifications when I updated the PR yesterday. I've addressed feedback and fixed issues found by testing with wrapped objects. |
README.md
Outdated
@@ -234,9 +234,11 @@ The callback changes basing on the parameters your are giving: | |||
3. If two parameters are given to the callback, the first will be the `error` object, the second will be the `done` callback. | |||
4. If three parameters are given to the callback, the first will be the `error` object, the second will be the top level `context` unless you have specified both server and override, in that case the `context` will be what the override returns, and the third the `done` callback. | |||
|
|||
If no callback is provided `ready` will return a Promise that is resolved or rejected once plugins and `after` calls are completed. No data is provided to the `.then` callback, if an error occurs it is provided to the `.catch` callback. |
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.
This has not been updated
boot.js
Outdated
@@ -229,8 +228,23 @@ Boot.prototype.close = function (func) { | |||
} | |||
|
|||
Boot.prototype.ready = function (func) { | |||
this._readyQ.push(func) | |||
return this | |||
if (func) { |
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.
I would check if this is a function and throw if it exists but it is not.
@@ -16,10 +16,8 @@ test('chainable standalone', (t) => { | |||
done() | |||
}).ready(function () { | |||
t.pass('we are ready') | |||
}).use(function (ctx, opts, done) { | |||
t.pass('3rd plugin') | |||
done() |
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.
Can you restore this?
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.
ready
no longer returns this
so the test now verifies that it is not chainable.
If you are concerned about testing that use
after ready
does the right thing I believe other tests do this, ready adds at the end of the queue
from after-and-ready.test.js
for example calls ready before calling use.
Please let me know if I'm misunderstanding your finding.
@@ -38,10 +36,8 @@ test('chainable automatically binded', (t) => { | |||
done() | |||
}).ready(function () { | |||
t.pass('we are ready') | |||
}).use(function (ctx, opts, done) { | |||
t.pass('3rd plugin') | |||
done() |
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.
can you restore this?
No description provided.