node: make plugin methods optional.

This commit is contained in:
Christopher Jeffrey 2017-05-13 02:01:22 -07:00
parent 5915338407
commit 677d85de1c
No known key found for this signature in database
GPG Key ID: 8962AB9DE6666BBD

View File

@ -296,8 +296,10 @@ Node.prototype.use = function use(plugin) {
instance = plugin.init(this);
assert(typeof instance.open === 'function', '`open` must be a function.');
assert(typeof instance.close === 'function', '`close` must be a function.');
assert(!instance.open || typeof instance.open === 'function',
'`open` must be a function.');
assert(!instance.close || typeof instance.close === 'function',
'`close` must be a function.');
if (plugin.id) {
assert(typeof plugin.id === 'string', '`id` must be a string.');
@ -407,7 +409,8 @@ Node.prototype.openPlugins = co(function* openPlugins() {
for (i = 0; i < this.stack.length; i++) {
plugin = this.stack[i];
yield plugin.open();
if (plugin.open)
yield plugin.open();
}
});
@ -421,7 +424,8 @@ Node.prototype.closePlugins = co(function* closePlugins() {
for (i = 0; i < this.stack.length; i++) {
plugin = this.stack[i];
yield plugin.close();
if (plugin.close)
yield plugin.close();
}
});