Comparing version 0.3.0 to 0.4.0
12
boot.js
@@ -106,2 +106,7 @@ 'use strict' | ||
// allows to override the instance of a server, given a plugin | ||
Boot.prototype.override = function (server) { | ||
return server | ||
} | ||
// load a plugin | ||
@@ -185,3 +190,4 @@ Boot.prototype.use = function (plugin, opts, callback) { | ||
const func = this.func | ||
func(server, this.opts, cb) | ||
this.server = this.parent.override(server) | ||
func(this.server, this.opts, cb) | ||
} | ||
@@ -197,5 +203,6 @@ | ||
function loadPlugin (toLoad, cb) { | ||
const last = this._current[0] | ||
// place the plugin at the top of _current | ||
this._current.unshift(toLoad) | ||
toLoad.exec(this._server, (err) => { | ||
toLoad.exec((last && last.server) || this._server, (err) => { | ||
if (err || !(toLoad.q.length() > 0 || toLoad.q.running() > 0)) { | ||
@@ -205,3 +212,2 @@ // finish now, because there is nothing left to do | ||
toLoad.finish(err, cb) | ||
return | ||
} else { | ||
@@ -208,0 +214,0 @@ // finish when the queue of nested plugins to load is empty |
{ | ||
"name": "avvio", | ||
"version": "0.3.0", | ||
"version": "0.4.0", | ||
"description": "Asynchronous bootstrapping of Node applications", | ||
@@ -29,4 +29,4 @@ "main": "boot.js", | ||
"pre-commit": "^1.1.3", | ||
"standard": "^8.6.0", | ||
"tap": "^9.0.0" | ||
"standard": "^9.0.0", | ||
"tap": "^10.0.0" | ||
}, | ||
@@ -33,0 +33,0 @@ "dependencies": { |
@@ -81,2 +81,3 @@ # avvio [![Build Status](https://travis-ci.org/mcollina/avvio.svg)](https://travis-ci.org/mcollina/avvio) | ||
* <a href="#ready"><code>instance.<b>ready()</b></code></a> | ||
* <a href="#override"><code>instance.<b>override()</b></code></a> | ||
* <a href="#express"><code>boot.<b>express()</b></code></a> | ||
@@ -205,3 +206,44 @@ | ||
------------------------------------------------------- | ||
<a name="override"></a> | ||
### app.override(server) | ||
Allows to override the instance of the server for each loading | ||
plugin. It allows the creation of an inheritance chain for the | ||
server instances. | ||
```js | ||
const boot = require('avvio') | ||
const assert = require('assert') | ||
const server = { count: 0 } | ||
const app = boot(server) | ||
console.log(app !== server, 'override must be set on the Avvio instance') | ||
app.override = function (s) { | ||
// create a new instance with the | ||
// server as the prototype | ||
const res = Object.create(s) | ||
res.count = res.count + 1 | ||
return res | ||
} | ||
app.use(function first (s1, opts, cb) { | ||
assert(s1 !== server) | ||
assert(server.isPrototypeOf(s1)) | ||
assert(s1.count === 1) | ||
s1.use(second, cb) | ||
function second (s2, opts, cb) { | ||
assert(s2 !== s1) | ||
assert(s1.isPrototypeOf(s2)) | ||
assert(s2.count === 2) | ||
cb() | ||
} | ||
}) | ||
``` | ||
------------------------------------------------------- | ||
## Acknowledgements | ||
@@ -208,0 +250,0 @@ |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
30475
15
868
257