1
0
Fork 0

wip: Working on better developer docs

This commit is contained in:
joostdecock 2021-09-25 17:05:18 +02:00
parent c16b212bb9
commit e0a261731f
25 changed files with 461 additions and 152 deletions

View file

@ -1,15 +1,41 @@
---
title: on()
title: Pattern.on()
---
A pattern's `on()` method allows you to attach a function to one of the
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
```js
void pattern.on(string hook, function method)
Pattern pattern.on(string hook, function method)
```
Allows you to attach a method to one of our hooks.
<Tip>
Takes the hook name as a first argument, and your method as a second.
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.
See [extending freesewing](/extend/) for details about extending freesewing with hooks.
</Tip>
## Pattern.on() example
```js
pattern.on('preRender', function(svg) {
svg.style += "svg { background: yellow;}";
})
```
Your pattern now has a yellow background.
<Tip>
The [plugin guide](/guides/plugins/) contains more info on how you can use hooks
</Tip>
<Fixme>Code example</Fixme>