1
0
Fork 0
freesewing/sites/dev/docs/reference/api/pattern/on/readme.mdx

43 lines
900 B
Text
Raw Normal View History

---
title: Pattern.on()
---
2022-09-20 18:09:28 +02:00
The `Pattern.on()` method allows you to attach a function to one of the
2021-09-25 17:05:18 +02:00
pattern's [lifecycle hooks](/reference/hooks/). It takes the
lifecycle hook's name as the first argument and the function as the second.
This method will then be triggered by the lifecycle hook.
2024-09-29 07:14:59 +02:00
:::note
This method is chainable as it returns the Pattern object
:::
2021-09-25 17:05:18 +02:00
## Pattern.on() signature
```js
2021-09-25 17:05:18 +02:00
Pattern pattern.on(string hook, function method)
2022-02-19 08:04:25 +01:00
```
:::tip
2021-09-25 17:05:18 +02:00
Refer to [the Lifecycle hooks documentation](/reference/hooks/) for a list
2022-12-14 12:52:37 -08:00
of all available lifecycle hooks, as well as the signature of the function you
2021-09-25 17:05:18 +02:00
should pass it.
:::
2021-09-25 17:05:18 +02:00
## Pattern.on() example
```js
2024-09-29 07:14:59 +02:00
pattern.on('preRender', function (svg) {
svg.style += 'svg { background: yellow;}'
2021-09-25 17:05:18 +02:00
})
```
Your pattern now has a yellow background.
:::tip
2021-09-25 17:05:18 +02:00
The [plugin guide](/guides/plugins/) contains more info on how you can use hooks
:::