T
Size: a a a
T
T
T
T
UT
T
T
T
T
UT
T
T
UT
T
UT
T
// main.js
module.exports = function (config) {
const thing = .... // created
const plugin = require(config.plugins[0]);
plugin.main(thing);
...
return thing
}
// plugin.js
function main (thing) {
thing = thing
if (cb) cb(thing)
...
}
var cb = null
var thing = null
function hook (callback) {
if (thing !== null) {
callback(thing)
} else {
cb = callback
}
}
module.exports = { main, hook }
T
T
T
const { EventEmitter } = require("events")
const bus = module.exports = new EventEmitter();
var i = 0;
setInterval(function() {
bus.emit("second", { time: i++ });
}, 1000);
const bus = require('file1.js');
bus.on("second", function(data) {
// data is { time: i++ }
});
bus.on("message", function(text) {
// text is "Hi there"
});
const bus = require('file1.js');
bus.emit("message", "Hi there")
UT