2021-10-17 18:26:00 +02:00
|
|
|
---
|
|
|
|
title: Pattern.on()
|
|
|
|
---
|
2021-08-25 16:09:31 +02:00
|
|
|
|
2021-10-17 18:26:00 +02:00
|
|
|
A pattern's `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.
|
|
|
|
|
|
|
|
<Note>Since FreeSewing v2.19, this method is chainable as it returns the Pattern object</Note>
|
|
|
|
|
|
|
|
## Pattern.on() signature
|
|
|
|
|
2021-08-25 16:09:31 +02:00
|
|
|
```js
|
2021-09-25 17:05:18 +02:00
|
|
|
Pattern pattern.on(string hook, function method)
|
2021-10-17 18:26:00 +02:00
|
|
|
```
|
2021-08-25 16:09:31 +02:00
|
|
|
|
2021-09-25 17:05:18 +02:00
|
|
|
<Tip>
|
|
|
|
|
|
|
|
Refer to [the Lifecycle hooks documentation](/reference/hooks/) for a list
|
|
|
|
of all avaialble lifecycle hooks, as well as the signature of the function you
|
|
|
|
should pass it.
|
|
|
|
|
|
|
|
</Tip>
|
|
|
|
|
|
|
|
## Pattern.on() example
|
|
|
|
|
|
|
|
```js
|
|
|
|
pattern.on('preRender', function(svg) {
|
|
|
|
svg.style += "svg { background: yellow;}";
|
|
|
|
})
|
|
|
|
```
|
|
|
|
|
|
|
|
Your pattern now has a yellow background.
|
|
|
|
|
|
|
|
<Tip>
|
2021-08-25 16:09:31 +02:00
|
|
|
|
2021-09-25 17:05:18 +02:00
|
|
|
The [plugin guide](/guides/plugins/) contains more info on how you can use hooks
|
2021-08-25 16:09:31 +02:00
|
|
|
|
2021-09-25 17:05:18 +02:00
|
|
|
</Tip>
|
2021-10-17 18:26:00 +02:00
|
|
|
|