-
Notifications
You must be signed in to change notification settings - Fork 3
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 @promise annotation #63
Comments
@ritch should respond with his thoughts, but I assumed that for a function, this annotation would display an additional signature (in addition to the standard asyc/callback signature) to clearly indicate (a) the function does support a promise API and (b) what the promise signature is, e.g. the expected argument to While this might be obvious to someone used to promises, it will be helpful for the many folks who are not, and will also be more explicit than just saying "this function supports promise API". In any case, we need to make it really easy for someone referring to the API docs to understand how to call a given function both with callbacks and with promises. |
It should make it obvious how to use the |
Reassigning to Yappa for immediate attention. |
On it. |
@crandmck @ritch @chandadharap @bajtos any thoughts on the "syntax" and display template for this annotation? |
Everyone's out on holiday until at least 1/4, and I'm out starting later today until 1/7. Meantime, refer to #63 (comment) above. Although I'm not terribly familiar with promises, I assume we want to do something along these lines. You'll want to confirm with @ritch or @bajtos before proceeding, but this might help you get started until we hear from them. Consider
This results in https://apidocs.strongloop.com/loopback/#persistedmodel-find. For promises, I assume we'd want something like this:
It's unclear to me if the success function always takes an object arg, or if it can be anything, and if the error function gets an |
Thanks @crandmck, that should be enough for me to get started, we can settle on the details later. |
So this is the syntax I have come up with:
which yields this: Functionality implemented, but not pushed yet (need to clean up a bit). Any suggestions? |
@hacksparrow your proposal is a good start, I am wondering if we can simplify it a bit. I think Now that most functions will need only
Another aspect to consider is duplicate information. At the moment, we would end up with something like this:
Can we come up with a syntax that does not require us to describe the result twice, once for the callback and second time for the promise? The screenshot of proposed API doc looks good. I'd like to add a bit of text to explain what the
@ritch @raymondfeng @hacksparrow thoughts? |
@bajtos excellent suggestions, it is very much in sync with what I'd prefer. Will make the suggested changes. Thanks! |
@ritch why is |
Implemented on branch feature/promise. @crandmck scroll down on the README for the details on how to use it. I had to update one aspect of an existing test to make it compatible with the use of the official |
@hacksparrow I've got it working on my laptop now, but I'm seeing one problem. I added the It displays properly, however, in the console I see this:
Not sure if that is significant or not. |
@crandmck @hacksparrow seems promise doesn't read the syntax of Array from callback. |
@crandmck @jannyHou there is a formatting error at https://github.com/strongloop/loopback/blob/master/lib/persisted-model.js#L928 It should be
not
The return parameter count is more than two, therefore this method cannot be converted to a promise, hence the description for resolve object will not be found. |
thank you @hacksparrow I am triaging one issue about similar problem, and yes I think we should put return parameters in an array to make promise work, like findOrCreate |
I believe this has been implemented and landed by #67, I am closing this issue as done. Please open a new one if there is any more work left. |
To document a Promise-based API, strong-docs will need to support the
@promise
annotation.See strongloop/loopback#418.
The text was updated successfully, but these errors were encountered: