2021-10-17 18:26:00 +02:00
|
|
|
---
|
2021-08-25 16:09:31 +02:00
|
|
|
title: Macros
|
2021-10-17 18:26:00 +02:00
|
|
|
---
|
2021-08-25 16:09:31 +02:00
|
|
|
|
2021-12-28 09:09:27 +01:00
|
|
|
Macros are a way to combine different operations into a single command.
|
2022-09-30 01:45:37 +02:00
|
|
|
Macros are typically provided by by plugins, but can also be added ad-hoc
|
|
|
|
without the need for a plugin.
|
2021-08-25 16:09:31 +02:00
|
|
|
|
2022-09-30 01:45:37 +02:00
|
|
|
## Signature
|
2021-08-25 16:09:31 +02:00
|
|
|
|
2022-09-30 01:45:37 +02:00
|
|
|
```js
|
|
|
|
null macro(object config, object props)
|
|
|
|
```
|
|
|
|
|
|
|
|
A macro receives a single configuration object as its first parameter.
|
|
|
|
The second parameter is the same object received by [the draft method in a
|
|
|
|
part](/reference/api/part/draft)
|
|
|
|
|
|
|
|
## Example
|
|
|
|
|
|
|
|
```js
|
|
|
|
pattern.use({
|
|
|
|
name: 'My adhoc plugin',
|
|
|
|
macros: {
|
|
|
|
myMacro: function (so, props) {
|
|
|
|
// Do something wonderful here
|
|
|
|
},
|
|
|
|
myOtherMacro: function (so, props) {
|
|
|
|
// Do something wonderful here
|
|
|
|
},
|
|
|
|
}
|
|
|
|
}
|
|
|
|
```
|
|
|
|
|
|
|
|
Now you can use these macros in your part:
|
2021-08-25 16:09:31 +02:00
|
|
|
|
2022-09-30 01:45:37 +02:00
|
|
|
```js
|
|
|
|
({ macro, part }) => {
|
2021-08-25 16:09:31 +02:00
|
|
|
|
2022-09-30 01:45:37 +02:00
|
|
|
macro('myMacro', {
|
|
|
|
some: [ 'config', 'here' ],
|
|
|
|
more: 'config'
|
|
|
|
})
|
|
|
|
macro('myOtherMacro', 'Just a string')
|
|
|
|
|
|
|
|
return part
|
|
|
|
}
|
|
|
|
```
|
|
|
|
|
|
|
|
## Macros we maintain
|
|
|
|
|
|
|
|
Below is a list of macros from [the plugins we maintain](/reference/plugins):
|
|
|
|
|
|
|
|
<ReadMore list />
|
2021-08-25 16:09:31 +02:00
|
|
|
|
2022-09-30 01:45:37 +02:00
|
|
|
## Notes
|
2021-08-25 16:09:31 +02:00
|
|
|
|
2022-09-30 01:45:37 +02:00
|
|
|
We recommend allowing to *undo* a macro by passing `false` as its parameter.
|