-
Notifications
You must be signed in to change notification settings - Fork 459
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
First pass at basic Node Addon API docs #268
Conversation
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 tried to give you some suggestions.
doc/basic_types.md
Outdated
It represents a JavaScript value of an unknown type. It is a thin wrapper around | ||
the N-API datatype `napi_value`. Methods on this class can be used to check | ||
the JavaScript type of the underlying `napi_value` and also convert to C++ |
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.
to convert
doc/basic_types.md
Outdated
- `[in] value` - The underlying JavaScript value that the `Value` instance represents | ||
|
||
Used to create a Node addon API `Value` that represents the `napi_value` passed |
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.
Maybe here we need to use: Returns a Node addon API Value
that represents the napi_value
passed in.
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.
Agreed we to follow the standard format we should have a Returns after the parameters.
doc/basic_types.md
Outdated
- `[in] other` - The value to compare against | ||
|
||
Tests if this value strictly equals another value. |
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.
Maybe it's better move Tests if this value strictly equals another value.
on top and here something like this: Returns true
if the value isn strictly equals another value, or false
otherwise.
doc/basic_types.md
Outdated
return type may return an empty value to indicate a pending exception. So when | ||
not using C++ exceptions, callers should check whether the value is empty | ||
before attempting to use it. |
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.
Maybe it's better to move this part on top and here: Returns true
if the Value
is an empty value.
About the error if the function that you are calling doesn't return value it' more appropriate use Env::IsExceptionPending()
to retrieve if there is an active error.
doc/basic_types.md
Outdated
``` | ||
|
||
Gets the underlying `napi_valuetype` of the value. |
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.
Maybe it's more appropriate use: Returns
doc/basic_types.md
Outdated
`napi_coerce_to_object`. This will throw a JavaScript exception if the | ||
coercion fails. | ||
|
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.
Move this part on top and here something like this: Returns a JavaScript Object.
doc/basic_types.md
Outdated
|
||
Names are JavaScript values that can be used as a property name. There are two | ||
specialized types of names supported in Node Addon API- `String` and `Symbol`. |
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.
doc/basic_types.md
Outdated
created from the JavaScript primitive. Note that the value is not coerced to a | ||
string. | ||
|
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.
Maybe it could be better to split this two cases
doc/basic_types.md
Outdated
|
||
Returns an empy array. If an error occurs, a `Napi::Error` will get thrown. | ||
|
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.
empy -> empty
doc/basic_types.md
Outdated
Wraps a `napi_value` as a `Napi::Array`. If an error occurs, a `Napi::Error` | ||
will get thrown. | ||
|
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.
Move this on top and here something like this: Returns the primitive top wrap.
doc/basic_types.md
Outdated
``` | ||
|
||
Returns the underlying N-API value primitive. If the instance is _empty_, |
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.
How about `Returns the underlying N-API napi_value'. If ...
doc/basic_types.md
Outdated
``` | ||
|
||
Returns `true` if this value strictly equals another value, or `false` otherwise |
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 need full sentences so needs a period at the end of the sentence. Say goes throughout the rest of the doc.
- `[in] env` - The `napi_env` environment in which to construct the Value object. | ||
- `[in] value` - The C++ type to represent in JavaScript. | ||
|
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.
Needs a Returns... before the explanation of how it works.
template <typename T> T As() const; | ||
``` | ||
|
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.
Needs Returns.... same for other places, won't mention it specifically in those other places.
doc/basic_types.md
Outdated
|
||
This conversion does NOT coerce the type. Calling any methods inappropriate for | ||
the actual value type will throw `Napi::Error`. |
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 an example here would help.
doc/basic_types.md
Outdated
``` | ||
|
||
Gets the environment the value is associated with. See `napi_env` for more |
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 should probably reference the Env class as opposed to napi_env.
doc/basic_types.md
Outdated
|
||
When C++ exceptions are disabled at compile time, a method with a `Value` | ||
return type may return an empty value to indicate a pending exception. So when |
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.
So when --> Therefore when
doc/basic_types.md
Outdated
occurs, a `Napi::Error` will get thrown. | ||
|
||
#### New |
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 should be #### Length
@@ -39,13 +33,41 @@ operator std::u16string() const; | |||
``` |
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 an example or more description might be useful here.
String::New(napi_env env, const std::string& value); | ||
String::New(napi_env env, const std::u16string& value); | ||
String::New(napi_env env, const char* value); | ||
String::New(napi_env env, const char16_t* value); |
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.
We should talk about this. Its not consistent with anything I've seen elsewhere in the node documentation
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.
But with overrides it does make sense to me
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.
Yes, that was kind of what I was thinking. Anyone else have thoughts?
Left a few comments but a really good first cut. |
@digitalinfinity are you going to get a chance to update for the comments? |
@mhdawson yes- so sorry, I've been sidetracked with other things for the past couple weeks but I should be able to find some cycles this week to incorporate all the great feedback provided so far. |
4a0aee8
to
f83f63f
Compare
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.
Just a few nits.
doc/basic_types.md
Outdated
[C++ wrapper classes for the ABI-stable C APIs for Node.js](https://nodejs.github.io/node-addon-api/) | ||
Node Addon API consists of a few fundamental data types. These allow a user of | ||
the API to create, convert and introspect fundamental JavaScript types, and | ||
interop with their C++ counterparts. |
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 you should expand this to "interoperate".
doc/basic_types.md
Outdated
Returns `true` if the value is uninitialized. | ||
|
||
An empty value is invalid, and most attempts to perform an operation on an | ||
empty value will result in an exception. Note an empty value is distinct from |
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 don't think you need "Note" here.
doc/basic_types.md
Outdated
bool IsBuffer() const; | ||
``` | ||
|
||
Returns `true` if the underlying value is a Node `Buffer` or `false` |
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.
We should write "Node.js" instead of "Node".
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.
+1
doc/basic_types.md
Outdated
|
||
## Array | ||
|
||
Arrays are native representations of JavaScript Arrays. `Napi::Array` is sugar |
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 say "a wrapper" instead of "sugar".
doc/basic_types.md
Outdated
|
||
Returns an empty array. | ||
|
||
If an error occurs, a `Napi::Error` will get thrown. If C++ exceptions are not |
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.
"will be thrown" might be better – here, and subsequently.
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.
+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.
LGTM. After the few minor comments I think it is good to land and we can iterate after that if necessary.
I believe all comments are now addressed will land. |
PR-URL: #268 Reviewed-By: Michael Dawson <michael_dawson@ca.ibm.com>
Landed as e029a07 |
PR-URL: nodejs/node-addon-api#268 Reviewed-By: Michael Dawson <michael_dawson@ca.ibm.com>
PR-URL: nodejs/node-addon-api#268 Reviewed-By: Michael Dawson <michael_dawson@ca.ibm.com>
PR-URL: nodejs/node-addon-api#268 Reviewed-By: Michael Dawson <michael_dawson@ca.ibm.com>
PR-URL: nodejs/node-addon-api#268 Reviewed-By: Michael Dawson <michael_dawson@ca.ibm.com>
Added docs for Basic Types, Strings and Symbols. Feedback welcome, I think this will take a couple more iterations to get right.