node: make plugin methods optional.
This commit is contained in:
parent
5915338407
commit
677d85de1c
@ -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();
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user