Documentation update for avvio PR 82#1498
Documentation update for avvio PR 82#1498mcollina merged 15 commits intofastify:masterfrom alex-ppg:documentation-update
Conversation
mcollina
left a comment
There was a problem hiding this comment.
Good work! I've left some notes.
Also https://github.com/fastify/fastify/blob/master/docs/Plugins.md needs to be updated.
|
I integrated your comments, let me know your thoughts. P.S. Plugins.md was updated as well in the initial commit, should I expand more / is it not clear enough? |
Co-Authored-By: alex-ppg <[email protected]>
|
An interesting and potentially unwanted behaviour of the The This means that it is possible to declare routes on the This is showcased in the test suite but a quick example would be: fastify.register((instance, options, next) => {
console.log(instance.plugin_opts === 'hello') // Evaluates to true
instance.decorate('local', () => 'world')
}, parent => {
parent.decorate('plugin_opts', 'hello')
parent.get('/', (request, reply) => {
reply.send({ hello: parent.local() }) // Will send { "hello": "world" }
})
})
fastify.after(() => {
console.log(fastify.plugin_opts === undefined) // Evaluates to true
console.log(fastify.local === undefined) // Evaluates to true
})Not sure if this is behaviour we want to remove as it is possible to accidentally declare an externally available plugin if the plugin's function is wrapped by fastify.register(fp((instance, options, next) => {
instance.decorate('my_plugin', () => 'world')
}), parent => {
parent.decorate('accidental_plugin', () => 'hello')
})
fastify.after(() => {
console.log(fastify.my_plugin() === 'world') // Evaluates to true, as it should
console.log(fastify.accidental_plugin() === 'hello') // Evaluates to true, potentially unwanted behaviour
})The unwanted behaviour I believe could be removed by calling override once again within the |
|
I don't see problems with it. cc @fastify/fastify what do you think? |
No problem for me either. |
|
This pull request has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs. |
Hey everyone,
You can find some updated documentation to reflect the changes made to the plugin registration API for the
optionsparameter. It refers to the avvio PR82. I believe it is clear enough but contributions are more than welcome!Checklist
npm run testandnpm run benchmark