Difference between `init` and the top-level plugin function
See original GitHub issueIn 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:
- Created 4 years ago
- Comments:9 (9 by maintainers)
Top 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 >
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
Both work. The function returning an object is just much more flexible for any use case
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