1
0
Fork 0
freesewing/markdown/dev/guides/plugins/hooks/en.md
2022-12-25 21:13:48 -08:00

1.1 KiB

title order
Lifecycle hook methods 110

FreeSewing plugins can provide hooks, which is a way to hook into the pattern's lifecycle.

Signature

To provide one or more hooks, your plugin should have a hooks property that is an object where the keys are the lifecycle hook name and the value holds a method. When the lifecycle hook is triggered, your method will be called.

const myPlugin = {
  name: 'example',
  version: '0.0.1',
  hooks: {
    hookName: function (obj, data = {}) {
    }
  }
}

If you want to attach multiple methods to the same lifecycle hook, you can pass them as an array:

const myPlugin = {
  name: 'example',
  version: '0.0.1',
  hooks: {
    hookName: [
      function one (obj, data = {}) { },
      function two (obj, data = {}) { }
    ]
  }
}

Arguments

All lifecycle methods will receive two parameters:

  • An object relevant to the lifecycle hook. See the hooks API reference for details.
  • Data passed when the hook was registered (optional)

Notes

Refer to the hooks API reference for a list of all available lifecycle hooks.