Object Syntax
See original GitHub issue🚀 Feature Proposal
A way to define plugins as objects.
Motivation
Less code to write for simple plugins, smaller, compact format when it makes sense.
Examples
export default {
decorate: {
helper () {
console.log('helper')
}
},
decorateRequest: {
$placeholder: null
},
async onRequest (req) {
req.$placeholder = 'something'
},
}
With fastify-plugin
:
export default {
encapsulate: true,
decorate: {
helper () {
console.log('helper')
}
},
decorateRequest: {
$placeholder: null
},
async onRequest (req) {
req.$placeholder = 'something'
},
}
Issue Analytics
- State:
- Created 2 years ago
- Comments:6 (5 by maintainers)
Top Results From Across the Web
Working with objects - JavaScript - MDN Web Docs - Mozilla
An object is a collection of properties, and a property is an association ... The syntax for an object using an object initializer...
Read more >JavaScript Objects - W3Schools
JavaScript objects are containers for named values called properties. Object Methods. Objects can also have methods. Methods are actions that can be performed ......
Read more >Objects - The Modern JavaScript Tutorial
The syntax: for (key in object) { // executes the body for each key among object properties }. For instance, let's output all...
Read more >JavaScript Objects: Create Objects, Access Properties ...
In JavaScript, an object can be created in two ways: 1) using Object Literal/Initializer Syntax 2) using the Object() Constructor function with the...
Read more >JavaScript Objects
In JavaScript, an object is an unordered collection of key-value pairs. Each key-value pair is called a property. The key of a property...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
I am not sure I like the idea of having another method to register a plugin. The exposed surface is already broad, and it isn’t easy for a newcomer to even understand what is going on during the boot or the req/res cycle.
I think that this functionality is a perfect match for a fastify-plugin itself, though. 😃
Here you go – https://github.com/galvez/fastify-apply –
npm i fastify-apply
.Please review @mcollina @delvedor @RafaelGSS 🙏