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.

Difference between `init` and the top-level plugin function

See original GitHub issue

In the following plugin:

const plugin = function(config) {
  return {
    init({ config, pluginConfig, api, constants }) { ... }
  }
}

It is not very clear what is the difference between the top-level function and the init function. Even if there is a one, users might not be sure which one to use.

init() provides with more arguments, such as the pluginConfig, api and constants. It also can run in parallel (depending on #168) and generally speaking can benefit from all the features given to lifecycle hooks.

Wouldn’t it be simpler to instead just do:

const plugin = {
  init({ config, pluginConfig, api, constants }) { ... }
}

And allow methods of the same plugin to share information by calling them with the same this context?

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:9 (9 by maintainers)

github_iconTop GitHub Comments

1reaction
DavidWellscommented, Oct 3, 2019

Both work. The function returning an object is just much more flexible for any use case

1reaction
DavidWellscommented, Oct 3, 2019

You could but you’d have to hardcode all possibilities and have those if statements.

That would also cause lots of lifecycle log output that really are just noOps

Read more comments on GitHub >

github_iconTop Results From Across the Web

Using Gradle Plugins
There are some key differences between the plugins {} block mechanism and ... The plugins {} block must also be a top level...
Read more >
__main__ — Top-level code environment — Python 3.11 ...
In Python, the special name__main__ is used for two important constructs: the name of the top-level environment of the program, which can be...
Read more >
Writing plugins — pytest documentation
A plugin contains one or multiple hook functions. Writing hooks explains the basics and details of how you can write a hook function...
Read more >
Best Practices | Plugin Developer Handbook
By default, all variables, functions and classes are defined in the global namespace, which means that it is possible for your plugin to...
Read more >
15.2.3. Plugins — xraylarch 0.9.47 documentation
First, each module file can have a initializeLarchPlugin() function that will be run immediately after the plugin is registered to initialize plugin ...
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