Skip to content
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

Basic data types documentation for nodejs/abi-stable-node#280. #165

Closed
wants to merge 6 commits into from
Closed

Basic data types documentation for nodejs/abi-stable-node#280. #165

wants to merge 6 commits into from

Conversation

jschlight
Copy link
Contributor

This is my initial hack at documentation for Basic Types. I'm open to all suggestions and criticisms to improve this document. Please let me know how it can be improved with additional content or format changes.

Initial hack at documetation for Basic Types.
Value is a the base class upon which other JavaScipt values like Number, Boolean, String, and Object are based.

```
Value();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For each of the methods I would add a heading. In this example:

Default Constructor

and we might want to add the Added in: which is used in the standard Node doc as well.

We may want to include the Returns line, if if it is just Returns void (or whatever we think is the best way to say returns nothing)

See https://nodejs.org/dist/latest-v8.x/docs/api/n-api.html#n_api_napi_create_reference in the N-API doc as the example I looked at to come up with these suggestions.

@@ -0,0 +1,373 @@
# N-API Documentation
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A general thought is that some intro at the top that introduces the basic types and how they are used might be useful before the section with the details. We can add that later though so what you have here would be good to land without that.

@mhdawson
Copy link
Member

Overall a good start just a few suggestions. I also think we can incrementally land changes so if you like my suggestions we could integrate those (and any others made in the mean time), land what you have so far and then continue to add content in follow on PRs.

@@ -0,0 +1,373 @@
# N-API Documentation
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We might want to put a big "WORK IN PROGRESS, NOT YET COMPLETE" at the top just to set peoples expectations.

@jschlight
Copy link
Contributor Author

I've split the earlier single large md file into four separate files that fit into the new documentation scaffolding structure. I've implemented Michael's suggestions with the exception of the Added in: marker which will require further research.

size_t Length() const;
```

Returns the number of arguemnts passed in the Callabckinfo object.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Callbackinfo -> CallbackInfo (capital I)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just noticed arguemnts -> arguments

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

arguemnts -> arguments

Value NewTarget() const;
```

Returns the `new.target` value of the constructor call. If the CallbackInfo is not a constructor call, a call to `IsEmpty()` on the returned value returns true.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This reads a bit strangely (to my ears). Maybe:

If the function that was invoked (and for which the CallbackInfo was passed) is not a constructor call....

There is also similar wording in a few other places.


Returns the JavaScript `this` value for the call

### Data
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would be good to provide a bit more details on what/how Data is used but that can be added in a follow on PR.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not clear how Data is used. I'm assuming that it's a place the C++ programmer can store general information with the C++ object, but I'm not sure. If so, I can add that to the documentation.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we can add the info as a follow on PR we just need to record somewhere that we should come back and do that. We should generate a test that uses it which would provide an example to base the doc on.

doc/env.md Outdated

The opaque data structure containing the environment in which the request is being run.

The Env object is usually created and passed by the calling system.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would it be better to say

"is usually created and passed by the Node.js runtime or node-addon-api infrastructure"

The same comment also applies other places were we say "calling system"

doc/external.md Outdated
```cpp
template <typename T>
static External New(napi_env env,
T* data,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The parameters don't line up here.

doc/external.md Outdated
```cpp
template <typename T>
static External New(napi_env env,
T* data,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

parameters don't line up here

doc/external.md Outdated
Returns a pointer to the arbitrary C++ data held by the External object.

### Not documented here

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this just because the doc will be added in future PR ? Or do you have some questions that need to be answered before you can add the doc for these ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wanted the reviewers to know that they're not documented. I'm pretty sure there's no need to document them. If so, I'll remove the note.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm thinking best to remove. It confused me so it might confuse others as well.

Copy link
Member

@mhdawson mhdawson left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks pretty close, just a few comments/questions.

@jschlight jschlight changed the title See nodejs/abi-stable-node#280. Basic data types documentation for nodejs/abi-stable-node#280. Nov 17, 2017
@jschlight
Copy link
Contributor Author

Michael, thank you for your comments. I've implemented your recommendations, have pushed updated files, and added a couple of comments above.

Copy link
Member

@mhdawson mhdawson left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just a few more comments/typos

@jschlight
Copy link
Contributor Author

Thanks, Michael. I've made another push to my branch.

Copy link
Member

@mhdawson mhdawson left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

mhdawson pushed a commit that referenced this pull request Nov 21, 2017
PR-URL: #165
Reviewed-By: Michael Dawson <michael_dawson@ca.ibm.com>
@mhdawson
Copy link
Member

Landed as 7ecab46

@mhdawson mhdawson closed this Nov 21, 2017
kevindavies8 added a commit to kevindavies8/node-addon-api-Develop that referenced this pull request Aug 24, 2022
PR-URL: nodejs/node-addon-api#165
Reviewed-By: Michael Dawson <michael_dawson@ca.ibm.com>
Marlyfleitas added a commit to Marlyfleitas/node-api-addon-Development that referenced this pull request Aug 26, 2022
PR-URL: nodejs/node-addon-api#165
Reviewed-By: Michael Dawson <michael_dawson@ca.ibm.com>
wroy7860 added a commit to wroy7860/addon-api-benchmark-node that referenced this pull request Sep 19, 2022
PR-URL: nodejs/node-addon-api#165
Reviewed-By: Michael Dawson <michael_dawson@ca.ibm.com>
johnfrench3 pushed a commit to johnfrench3/node-addon-api-git that referenced this pull request Aug 11, 2023
PR-URL: nodejs/node-addon-api#165
Reviewed-By: Michael Dawson <michael_dawson@ca.ibm.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants