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.

Updating Lifecycle Event Names to `onEvent`

See original GitHub issue

The object returned by plugins represent the config, name, and the handlers that respond to lifecycle events.

These lifecycle events are events that happen during the course of a build. For example preBuild postBuild, preDeploy etc

Because these handler functions are responding to events, I think it would improve clarity of the plugin API to make the keys of event handler functions look more like an event handler.

For example, instead of prebuild using onPrebuild.

Changes

module.exports = function myPlugin(config) {
  return {
-   preBuild: () => {
+   onPreBuild: () => {
      // run thing on pre-build
    },
-   build: () => {
+   onBuild: () => {
      // run thing on build
    },
-   postBuild: () => {
+   onPostBuild: () => {
      // run thing on post build
    }
  }
}

I believe this would make it a little more clear that the keys beginning with on are bits of functionality that response to a particular lifecycle event.

I also think this will make it easier to evolve the plugin API without running into namespace clashes. E.g. (random example) if we wanted to use the build key in the future for some kind of config


We can achieve this with a breaking change or non-breaking change.

The non-breaking change would require some mapping of existing keys & deprecation notices for plugins using the “older” non onXyz syntax

Issue Analytics

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

github_iconTop GitHub Comments

1reaction
DavidWellscommented, Dec 2, 2019

Lets go ahead and change this.

Part 2 before merging the code changes will be updating the plugin content we can edit. https://www.notion.so/netlify/Build-Plugins-Reference-Guide-2b5ed75d19254b5389f2713bfc0fef6a


Just to be clear, the expected behavior is migrating the lifecycle events in a backward compatible way.

E.g.

  1. build would change to onBuild (etc)
  2. Older plugins with build will still operate as normal but will log out the build lifecycle has been updated to onBuild, please update your plugins accordingly
  3. At some future date we can retired the non onXyz lifecycle events
1reaction
ehmickycommented, Nov 28, 2019

I think this is a good idea. 👍

Tagging @verythorough as this would require some documentation/articles updates.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Lifecycle Methods, Handling Events, Render List - ReactJS
We can manage user input in React by using the text field's onChange event. When the text field's value changes, the event handler...
Read more >
Chapter 6. Handling events in React - liveBook · Manning
There's a simple way to attach unsupported events like resize and most custom elements you need to support: using React component lifecycle events....
Read more >
Event reference - MDN Web Docs - Mozilla
A full list of the different event types is given in Event > Interfaces based on Event. This topic provides an index to...
Read more >
Amazon S3 Event Notifications
Amazon S3 can send event notification messages to the following destinations. You specify the Amazon Resource Name (ARN) value of these destinations in...
Read more >
Handle Events - Salesforce Lightning Component Library
There are two ways to listen for an event: declaratively from the component's HTML template, or programmatically using an imperative JavaScript API.
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