2021-10-17 18:26:00 +02:00
|
|
|
---
|
|
|
|
title: Pattern.on()
|
|
|
|
---
|
2021-08-25 16:09:31 +02:00
|
|
|
|
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-28 13:13:48 +02:00
|
|
|
:::noteThis method is chainable as it returns the Pattern object:::
|
2021-09-25 17:05:18 +02:00
|
|
|
|
|
|
|
## 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)
|
2022-02-19 08:04:25 +01:00
|
|
|
```
|
2021-08-25 16:09:31 +02:00
|
|
|
|
2024-09-28 13:13:48 +02: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.
|
|
|
|
|
2024-09-28 13:13:48 +02:00
|
|
|
:::
|
2021-09-25 17:05:18 +02:00
|
|
|
|
|
|
|
## Pattern.on() example
|
|
|
|
|
|
|
|
```js
|
|
|
|
pattern.on('preRender', function(svg) {
|
|
|
|
svg.style += "svg { background: yellow;}";
|
|
|
|
})
|
|
|
|
```
|
|
|
|
|
|
|
|
Your pattern now has a yellow background.
|
|
|
|
|
2024-09-28 13:13:48 +02:00
|
|
|
:::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
|
|
|
|
2024-09-28 13:13:48 +02:00
|
|
|
:::
|