question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

🚀 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:closed
  • Created 2 years ago
  • Comments:6 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
fox1tcommented, Mar 29, 2021

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. 😃

1reaction
galvezcommented, Mar 29, 2021

Here you go – https://github.com/galvez/fastify-applynpm i fastify-apply.

Please review @mcollina @delvedor @RafaelGSS 🙏

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found