chore(markdown): Updated plugin guide for v3
This commit is contained in:
parent
d7442b9bc4
commit
cac698027c
15 changed files with 195 additions and 348 deletions
56
markdown/dev/guides/plugins/store/en.md
Normal file
56
markdown/dev/guides/plugins/store/en.md
Normal file
|
@ -0,0 +1,56 @@
|
|||
---
|
||||
title: Store methods
|
||||
order: 130
|
||||
---
|
||||
|
||||
FreeSewing plugins can provide store methods, which facilitate data handling
|
||||
within a pattern.
|
||||
|
||||
## Signature
|
||||
|
||||
To provide one or more store methods, your plugin should have a `macros` property that
|
||||
is an array where each member is itself an array with two members:
|
||||
|
||||
- The first member holds the key to attach the method to (in dot notation)
|
||||
- The second member holds the method to attach
|
||||
|
||||
```mjs
|
||||
const myPlugin = {
|
||||
name: 'example',
|
||||
version: '0.0.1',
|
||||
store: [
|
||||
[
|
||||
'log.panic',
|
||||
function(store, ...params) {
|
||||
store.setIfUnset('logs.panic', new Array())
|
||||
store.push(...params)
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
## Arguments
|
||||
|
||||
All store methods receive at least two arguments:
|
||||
|
||||
- `store`: The store object itself
|
||||
- `...params`: All additional plugins that were passed to the store method
|
||||
|
||||
## Overwriting store methods
|
||||
|
||||
You are allowed to overwrite existing store methods.
|
||||
As it happens, this is how you should implement a custom logging solution, but overwriting the logging methods under the store's `log` key,
|
||||
|
||||
However, the following methods cannot be overwritten:
|
||||
|
||||
- `extend`
|
||||
- `get`
|
||||
- `push`
|
||||
- `set`
|
||||
- `setIfUnset`
|
||||
- `unset`
|
||||
|
||||
## Return value
|
||||
|
||||
Store methods do not need to return anything. If they do, it will be ignored.
|
Loading…
Add table
Add a link
Reference in a new issue