🎨 Refactor and update the examples
This commit is contained in:
parent
1d0a7d4234
commit
4b02026e94
|
@ -0,0 +1,116 @@
|
||||||
|
{
|
||||||
|
"root": true,
|
||||||
|
"env": {
|
||||||
|
"node" : true,
|
||||||
|
"es6" : true,
|
||||||
|
"mocha" : true
|
||||||
|
},
|
||||||
|
"globals": {
|
||||||
|
"expect" : true,
|
||||||
|
"chai" : true,
|
||||||
|
"sinon" : true
|
||||||
|
},
|
||||||
|
"extends": ["eslint:recommended"],
|
||||||
|
"parserOptions": {
|
||||||
|
"ecmaVersion": 8,
|
||||||
|
"ecmaFeatures": {
|
||||||
|
"experimentalObjectRestSpread": true
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"rules": {
|
||||||
|
"arrow-parens": ["error", "as-needed"],
|
||||||
|
"no-trailing-spaces": [
|
||||||
|
"error",
|
||||||
|
{
|
||||||
|
"skipBlankLines": true
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"indent": [
|
||||||
|
"error",
|
||||||
|
"tab",
|
||||||
|
{
|
||||||
|
"SwitchCase": 1
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"linebreak-style": [
|
||||||
|
"error",
|
||||||
|
"unix"
|
||||||
|
],
|
||||||
|
"max-len": ["error", 110],
|
||||||
|
"quotes": [
|
||||||
|
"error",
|
||||||
|
"single"
|
||||||
|
],
|
||||||
|
"semi": [
|
||||||
|
"error",
|
||||||
|
"always"
|
||||||
|
],
|
||||||
|
"no-multiple-empty-lines": ["error", { "max": 3, "maxEOF": 1, "maxBOF": 1 }],
|
||||||
|
"keyword-spacing": ["error", { "before": true, "after": true }],
|
||||||
|
"space-before-blocks": ["error"],
|
||||||
|
"space-before-function-paren": ["error", {"anonymous": "always", "named": "never", "asyncArrow": "always"}],
|
||||||
|
"space-infix-ops": ["error"],
|
||||||
|
"space-unary-ops": [
|
||||||
|
"error", {
|
||||||
|
"words": true,
|
||||||
|
"nonwords": false,
|
||||||
|
"overrides": {
|
||||||
|
"!": true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"spaced-comment": [0],
|
||||||
|
"camelcase": ["error"],
|
||||||
|
"no-tabs": [0],
|
||||||
|
"comma-dangle": [0],
|
||||||
|
"global-require": [0],
|
||||||
|
"func-names": [0],
|
||||||
|
"no-param-reassign": [0],
|
||||||
|
"no-underscore-dangle": [0],
|
||||||
|
"no-restricted-syntax": [
|
||||||
|
"error",
|
||||||
|
{
|
||||||
|
"selector": "LabeledStatement",
|
||||||
|
"message": "Labels are a form of GOTO; using them makes code confusing and hard to maintain and understand."
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"selector": "WithStatement",
|
||||||
|
"message": "`with` is disallowed in strict mode because it makes code impossible to predict and optimize."
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"no-mixed-operators": [0],
|
||||||
|
"no-plusplus": [0],
|
||||||
|
"comma-spacing": [0],
|
||||||
|
"default-case": [0],
|
||||||
|
"no-shadow": [0],
|
||||||
|
"no-console": [0],
|
||||||
|
"key-spacing": [0],
|
||||||
|
"no-return-assign": [0],
|
||||||
|
"consistent-return": [0],
|
||||||
|
"class-methods-use-this": [0],
|
||||||
|
"no-multi-spaces": [
|
||||||
|
"error",
|
||||||
|
{
|
||||||
|
"exceptions": {
|
||||||
|
"VariableDeclarator": true,
|
||||||
|
"Property": true,
|
||||||
|
"ImportDeclaration": true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"array-callback-return": [0],
|
||||||
|
"no-use-before-define": [
|
||||||
|
"error",
|
||||||
|
{
|
||||||
|
"functions": false,
|
||||||
|
"classes": true,
|
||||||
|
"variables": true
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"padded-blocks": [0],
|
||||||
|
"space-in-parens": [0],
|
||||||
|
"valid-jsdoc": [0],
|
||||||
|
"no-unused-expressions": [0],
|
||||||
|
"import/no-dynamic-require": [0]
|
||||||
|
}
|
||||||
|
}
|
|
@ -2,10 +2,10 @@
|
||||||
.cproject
|
.cproject
|
||||||
.project
|
.project
|
||||||
.lock-wscript
|
.lock-wscript
|
||||||
build*
|
build*/
|
||||||
.DS_Store
|
.DS_Store
|
||||||
Debug
|
Debug/
|
||||||
node_modules
|
node_modules/
|
||||||
package-lock.json
|
package-lock.json
|
||||||
binary
|
binary/
|
||||||
*.log
|
*.log
|
|
@ -1,14 +1,15 @@
|
||||||
.idea
|
|
||||||
.cproject
|
|
||||||
.project
|
|
||||||
.lock-wscript
|
|
||||||
build*
|
|
||||||
.DS_Store
|
|
||||||
Debug
|
|
||||||
node_modules
|
|
||||||
package-lock.json
|
|
||||||
binary
|
|
||||||
*.log
|
*.log
|
||||||
examples
|
.cproject
|
||||||
|
.eslintrc
|
||||||
.gitignore
|
.gitignore
|
||||||
test
|
.idea
|
||||||
|
.lock-wscript
|
||||||
|
.project
|
||||||
|
binary/
|
||||||
|
build*/
|
||||||
|
CPPLINT.cfg
|
||||||
|
Debug/
|
||||||
|
examples/
|
||||||
|
package-lock.json
|
||||||
|
test/
|
||||||
|
qt/
|
|
@ -0,0 +1,13 @@
|
||||||
|
set noparent
|
||||||
|
linelength=110
|
||||||
|
filter=-legal/copyright
|
||||||
|
filter=-build/include_order
|
||||||
|
filter=-build/header_guard
|
||||||
|
filter=-build/namespaces
|
||||||
|
filter=-build/include_what_you_use
|
||||||
|
filter=-whitespace/blank_line
|
||||||
|
filter=-whitespace/comments
|
||||||
|
filter=-whitespace/tab
|
||||||
|
filter=-whitespace/end_of_line
|
||||||
|
filter=-whitespace/indent
|
||||||
|
filter=-readability/todo
|
|
@ -12,7 +12,7 @@ using namespace std;
|
||||||
extern "C" {
|
extern "C" {
|
||||||
|
|
||||||
|
|
||||||
void init(Handle<Object> target) {
|
void init(V8_VAR_OBJ target) {
|
||||||
|
|
||||||
EventEmitter::init(target);
|
EventEmitter::init(target);
|
||||||
Example::init(target);
|
Example::init(target);
|
||||||
|
@ -20,7 +20,7 @@ void init(Handle<Object> target) {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
NODE_MODULE(NODE_GYP_MODULE_NAME, init);
|
NODE_MODULE(example, init);
|
||||||
|
|
||||||
|
|
||||||
} // extern "C"
|
} // extern "C"
|
|
@ -8,6 +8,9 @@ using namespace v8;
|
||||||
using namespace node;
|
using namespace node;
|
||||||
using namespace std;
|
using namespace std;
|
||||||
|
|
||||||
|
|
||||||
|
// ------ Aux macros
|
||||||
|
|
||||||
#define THIS_EXAMPLE \
|
#define THIS_EXAMPLE \
|
||||||
Example *example = ObjectWrap::Unwrap<Example>(info.This());
|
Example *example = ObjectWrap::Unwrap<Example>(info.This());
|
||||||
|
|
||||||
|
@ -15,15 +18,33 @@ using namespace std;
|
||||||
if (example->_isDestroyed) return;
|
if (example->_isDestroyed) return;
|
||||||
|
|
||||||
|
|
||||||
Nan::Persistent<v8::Function> Example::_ctorExample;
|
// ------ Constructor and Destructor
|
||||||
|
|
||||||
|
Example::Example() : EventEmitter() {
|
||||||
|
|
||||||
|
_isDestroyed = false;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
void Example::init(Handle<Object> target) {
|
Example::~Example() {
|
||||||
|
|
||||||
Local<FunctionTemplate> proto = Nan::New<FunctionTemplate>(newCtor);
|
_destroy();
|
||||||
|
|
||||||
// class Example extends EventEmitter
|
}
|
||||||
Local<FunctionTemplate> parent = Nan::New(EventEmitter::_protoEventEmitter);
|
|
||||||
|
// ------ System methods and props for ObjectWrap
|
||||||
|
|
||||||
|
V8_STORE_FT Example::_protoExample;
|
||||||
|
V8_STORE_FUNC Example::_ctorExample;
|
||||||
|
|
||||||
|
|
||||||
|
void Example::init(V8_VAR_OBJ target) {
|
||||||
|
|
||||||
|
V8_VAR_FT proto = Nan::New<FunctionTemplate>(newCtor);
|
||||||
|
|
||||||
|
// class AudioBufferSourceNode inherits AudioScheduledSourceNode
|
||||||
|
V8_VAR_FT parent = Nan::New(EventEmitter::_protoEventEmitter);
|
||||||
proto->Inherit(parent);
|
proto->Inherit(parent);
|
||||||
|
|
||||||
proto->InstanceTemplate()->SetInternalFieldCount(1);
|
proto->InstanceTemplate()->SetInternalFieldCount(1);
|
||||||
|
@ -33,8 +54,9 @@ void Example::init(Handle<Object> target) {
|
||||||
Nan::SetPrototypeMethod(proto, "destroy", destroy);
|
Nan::SetPrototypeMethod(proto, "destroy", destroy);
|
||||||
|
|
||||||
// -------- static
|
// -------- static
|
||||||
Local<Function> ctor = Nan::GetFunction(proto).ToLocalChecked();
|
V8_VAR_FUNC ctor = Nan::GetFunction(proto).ToLocalChecked();
|
||||||
|
|
||||||
|
_protoExample.Reset(proto);
|
||||||
_ctorExample.Reset(ctor);
|
_ctorExample.Reset(ctor);
|
||||||
|
|
||||||
Nan::Set(target, JS_STR("Example"), ctor);
|
Nan::Set(target, JS_STR("Example"), ctor);
|
||||||
|
@ -54,20 +76,6 @@ NAN_METHOD(Example::newCtor) {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
Example::Example() : EventEmitter() {
|
|
||||||
|
|
||||||
_isDestroyed = false;
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
Example::~Example() {
|
|
||||||
|
|
||||||
_destroy();
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void Example::_destroy() { DES_CHECK;
|
void Example::_destroy() { DES_CHECK;
|
||||||
|
|
||||||
_isDestroyed = true;
|
_isDestroyed = true;
|
||||||
|
@ -79,6 +87,8 @@ void Example::_destroy() { DES_CHECK;
|
||||||
|
|
||||||
NAN_METHOD(Example::destroy) { THIS_EXAMPLE; THIS_CHECK;
|
NAN_METHOD(Example::destroy) { THIS_EXAMPLE; THIS_CHECK;
|
||||||
|
|
||||||
|
example->emit("destroy");
|
||||||
|
|
||||||
example->_destroy();
|
example->_destroy();
|
||||||
|
|
||||||
}
|
}
|
|
@ -9,13 +9,15 @@ class Example : public EventEmitter {
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
static void init(v8::Handle<v8::Object> target);
|
~Example();
|
||||||
|
|
||||||
|
static void init(V8_VAR_OBJ target);
|
||||||
|
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
|
||||||
Example();
|
Example();
|
||||||
~Example();
|
|
||||||
void _destroy();
|
void _destroy();
|
||||||
|
|
||||||
|
|
||||||
|
@ -28,7 +30,8 @@ private:
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
static Nan::Persistent<v8::Function> _ctorExample;
|
static V8_STORE_FT _protoExample;
|
||||||
|
static V8_STORE_FUNC _ctorExample;
|
||||||
|
|
||||||
bool _isDestroyed;
|
bool _isDestroyed;
|
||||||
|
|
|
@ -0,0 +1,9 @@
|
||||||
|
{
|
||||||
|
"name": "example",
|
||||||
|
"version": "0.0.0",
|
||||||
|
"private": true,
|
||||||
|
"main": "index.js",
|
||||||
|
"dependencies": {
|
||||||
|
"addon-tools-raub": "file:../../"
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,9 @@
|
||||||
|
{
|
||||||
|
"name": "example",
|
||||||
|
"version": "0.0.0",
|
||||||
|
"private": true,
|
||||||
|
"main": "index.js",
|
||||||
|
"dependencies": {
|
||||||
|
"addon-tools-raub": "file:../../"
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,25 +0,0 @@
|
||||||
{
|
|
||||||
"name": "example",
|
|
||||||
"version": "0.0.1",
|
|
||||||
"description": "EXAMPLE",
|
|
||||||
"main": "index.js",
|
|
||||||
"author": "Luis Blanco <raubtierxxx@gmail.com>",
|
|
||||||
"keywords": [
|
|
||||||
"addon"
|
|
||||||
],
|
|
||||||
"maintainers": [
|
|
||||||
{
|
|
||||||
"name": "Luis Blanco",
|
|
||||||
"email": "raubtierxxx@gmail.com",
|
|
||||||
"skype": "rauber666"
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"license": "MIT",
|
|
||||||
"repository": {
|
|
||||||
"type": "git",
|
|
||||||
"url": "https://github.com/raub/node-addon-tools"
|
|
||||||
},
|
|
||||||
"dependencies": {
|
|
||||||
"addon-tools-raub": "../../"
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,29 +0,0 @@
|
||||||
{
|
|
||||||
"name": "deps-example",
|
|
||||||
"author": "Luis Blanco <raubtierxxx@gmail.com>",
|
|
||||||
"description": "EXAMPLE",
|
|
||||||
"version": "0.0.1",
|
|
||||||
"main": "index.js",
|
|
||||||
"keywords": [
|
|
||||||
"deps",
|
|
||||||
"dependency",
|
|
||||||
"lib",
|
|
||||||
"library",
|
|
||||||
"binary"
|
|
||||||
],
|
|
||||||
"maintainers": [
|
|
||||||
{
|
|
||||||
"name": "Luis Blanco",
|
|
||||||
"email": "raubtierxxx@gmail.com",
|
|
||||||
"skype": "rauber666"
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"license": "MIT",
|
|
||||||
"repository": {
|
|
||||||
"type": "git",
|
|
||||||
"url": "https://github.com/raub/node-addon-tools"
|
|
||||||
},
|
|
||||||
"dependencies": {
|
|
||||||
"addon-tools-raub": "../../"
|
|
||||||
}
|
|
||||||
}
|
|
Loading…
Reference in New Issue