avvio icon indicating copy to clipboard operation
avvio copied to clipboard

Add onRegister for plugins

Open SerayaEryn opened this issue 6 years ago • 2 comments

As discussed in fastify/fastify#1812 this adds support for an optional onRegister function that can be called synchronously before a plugin is loaded.

SerayaEryn avatar Sep 08 '19 06:09 SerayaEryn

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. :)

SerayaEryn avatar Sep 18 '19 18:09 SerayaEryn

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()
}

Eomm avatar Oct 12 '19 19:10 Eomm

Any updates on this? PR is over 3 years old at this point, is it still required?

Fdawgs avatar Jan 07 '23 09:01 Fdawgs

Can be closed

mcollina avatar Jan 07 '23 19:01 mcollina