Composition and Inheritance of Wrapped Objects Examples

Open
#72 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
3/5
Estimated time
1-2 days
Newbie friendliness
45/100
Issue type
Documentation
Clarity
Mostly clear
Activity status
Stale
Tech stack
cpp, nodejs
Domain
documentation

Research direction

Read the existing 6_object_wrap/node-addon-api example and the inherits_from_event_emitter/node-addon-api example first, including their build files and JavaScript usage. Add focused examples covering composition and inheritance of ObjectWrap-based C++ classes, with each class independently instantiable from JavaScript, and verify the examples build and run.

Written by the indexing model from the issue text.

Description

Can examples of composition and inheritance of wrapped objects be added? I think one could potentially figure it out with the current examples, but I'm not able to figure it out.

class BasicClass { int IntValue; };
class BasicComposition
{
    int foo;
    BasicClass bc;
};
class BasicInheritance : BasicClass
{
    double yValue;
};
class InheritanceAndComposition : BasicInheritance
{
    std::string strValue;
    BasicComposition bcValue;
};

// Export all classes to JS

One should be able to instantiate and use each C++ class in JavaScript (e.g. create an instance of BasicClass independent of instances of BasicComposition).

It seems to me that only the case of BasicClass has an example in 6_object_wrap. The other cases with inheritance and composition of classes extending ObjectWrap<T> do not appear to exist. Inheritance might be covered in inherits_from_event_emitter, but it is not clear to me what is going on in that example.

I'm hoping someone with more experience with node-addon-api can provide these types of examples. It would greatly assist me in defining more complex relationships in Napi.

Dominant language
C++
Stars
2.6k
Forks
602
PR merge metrics
No merged PRs in 30d

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from nodejs/node-addon-examples

All issues in nodejs/node-addon-examples

Similar issues

More C++ issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.