2022-10-12 21:52:47 +02:00
|
|
|
---
|
|
|
|
title: Store methods
|
|
|
|
order: 130
|
|
|
|
---
|
|
|
|
|
|
|
|
FreeSewing plugins can provide store methods, which facilitate data handling
|
|
|
|
within a pattern.
|
|
|
|
|
|
|
|
## Signature
|
|
|
|
|
2023-04-28 08:58:58 +02:00
|
|
|
To provide one or more store methods, your plugin should have a `store` property that
|
2022-10-12 21:52:47 +02:00
|
|
|
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.
|
2022-12-25 21:13:48 -08:00
|
|
|
As it happens, this is how you should implement a custom logging solution,
|
|
|
|
by overwriting the logging methods under the store's `log` key,
|
2022-10-12 21:52:47 +02:00
|
|
|
|
2022-12-25 21:13:48 -08:00
|
|
|
However, the following store methods cannot be overwritten:
|
2022-10-12 21:52:47 +02:00
|
|
|
|
2022-12-25 21:13:48 -08:00
|
|
|
- `extend()`
|
|
|
|
- `get()`
|
|
|
|
- `push()`
|
|
|
|
- `set()`
|
|
|
|
- `setIfUnset()`
|
|
|
|
- `unset()`
|
2022-10-12 21:52:47 +02:00
|
|
|
|
|
|
|
## Return value
|
|
|
|
|
|
|
|
Store methods do not need to return anything. If they do, it will be ignored.
|