Add onRegister for plugins
As discussed in fastify/fastify#1812 this adds support for an optional onRegister function that can be called synchronously before a plugin is loaded.
In my opinion, we should think of a different approach to solving the issue.
I am not sure how another approch would look like. But I'd be happy to take a on another approch if there if someone has an idea. :)
Hello! Thank you for the pr! I'm 👎 with this change because while it improves the overall developer experience, makes a quite complicated and intricated plugin developer experience. In my opinion, we should think of a different approach to solving the issue.
I would propose this: the plugin can implement the on function like event emitter:
function plugin (s, opts) {
console.log(`Hello ${opts.name}`)
return 'hello'
}
plugin.on = function (event, opts) {
// edit opts
}
So avvio should check if it must call the on sync function with some events like:
- onRegister
- onWhatWeWant
I'm not sure if we can also use directly an EventEmitter since we are not using new:
const { EventEmitter } = require('events')
const util = require('util')
util.inherits(plugin, EventEmitter)
function plugin (s, opts, cb) {
console.log(`Hello ${opts.name}`)
cb()
}
Any updates on this? PR is over 3 years old at this point, is it still required?
Can be closed