From 77995f76f68b7223c902aaabe069ce6a1ce44475 Mon Sep 17 00:00:00 2001 From: Luis Blanco Date: Sun, 10 Nov 2019 22:50:09 +0300 Subject: [PATCH] wip doc --- doc/class-wrapping.md | 28 +++++++++++++++++++--------- 1 file changed, 19 insertions(+), 9 deletions(-) diff --git a/doc/class-wrapping.md b/doc/class-wrapping.md index 559adb9..6733277 100644 --- a/doc/class-wrapping.md +++ b/doc/class-wrapping.md @@ -40,20 +40,19 @@ the second is the name of the setter to be created. ## Class Implementation ``` +// Some utility stuff IMPLEMENT_ES5_CLASS(ClassName); + +// Fill the properties and export the class void ClassName::init(Napi::Env env, Napi::Object exports) { - Napi::Function ctor = wrap(env); - JS_ASSIGN_METHOD(destroy); - JS_ASSIGN_GETTER(isDestroyed); - + // ... exports.Set("JSClassName", ctor); - } -Body::Body(const Napi::CallbackInfo &info) { NAPI_ENV; +ClassName::ClassName(const Napi::CallbackInfo &info) { NAPI_ENV; super(info); @@ -63,15 +62,26 @@ Body::Body(const Napi::CallbackInfo &info) { NAPI_ENV; } -Body::~Body() { +ClassName::~ClassName() { _destroy(); } - -void Body::_destroy() { DES_CHECK; +void ClassName::_destroy() { DES_CHECK; + // ... _isDestroyed = true; } +JS_IMPLEMENT_METHOD(ClassName, destroy) { THIS_CHECK; + emit("destroy"); + _destroy(); + RET_UNDEFINED; +} + + +JS_IMPLEMENT_GETTER(ClassName, isDestroyed) { THIS_CHECK; + RET_BOOL(_isDestroyed); +} + ```