2021-10-17 18:26:00 +02:00
|
|
|
---
|
|
|
|
title: Part.shorthand()
|
|
|
|
---
|
2021-08-25 16:09:31 +02:00
|
|
|
|
2021-09-25 17:53:09 +02:00
|
|
|
A part's `shorthand()` method provides easy access to a number of
|
|
|
|
internal objects and properties. It does so be returning an object
|
2021-10-17 18:26:00 +02:00
|
|
|
that contains all you need to draft your pattern parts. It is
|
2021-09-25 17:53:09 +02:00
|
|
|
typically combined with object destructuring to pull out those
|
|
|
|
properties you need.
|
|
|
|
|
|
|
|
As the name implies, this method can save you a bunch of typing, and keep your
|
|
|
|
code concise. We highly recommend you use it.
|
|
|
|
|
|
|
|
## Part.shorthand() signature
|
|
|
|
|
2021-08-25 16:09:31 +02:00
|
|
|
```js
|
|
|
|
object Part.shorthand();
|
|
|
|
```
|
|
|
|
|
2021-09-25 17:53:09 +02:00
|
|
|
The `Part.shorthand()` method returns a plain object with the following properties:
|
2021-08-25 16:09:31 +02:00
|
|
|
|
2021-09-25 17:53:09 +02:00
|
|
|
| Property | Description |
|
|
|
|
| --------:| ----------- |
|
|
|
|
| `config` | The pattern configuration |
|
|
|
|
| `complete` | Holds `pattern.settings.complete` |
|
|
|
|
| `events` | An object holding the raised events (see [Part.raise](/reference/api/part/raise/)) |
|
|
|
|
| `final` | `true` is this is a full draft, or `false` if this is a sample. |
|
|
|
|
| `macro` | The macro runner. See [the macros documentation](/reference/macros/) |
|
|
|
|
| `measurements` | Holds `pattern.settings.measurements` |
|
|
|
|
| `paperless` | Holds `pattern.settings.paperless` |
|
|
|
|
| `Path` | The [Path constructor](/reference/api/path) |
|
|
|
|
| `paths` | Holds `part.paths` |
|
|
|
|
| `Point` | The [Point constructor](/reference/api/point) |
|
|
|
|
| `points` | Holds `part.points` |
|
|
|
|
| `Snippet` | The [Snippet constructor](/reference/api/snippet) |
|
|
|
|
| `snippets` | Holds `part.snippets` |
|
|
|
|
| `options` | Holds `pattern.settings.options` |
|
|
|
|
| `raise` | Holds [Part.raise](/reference/api/part/raise/) thus giving you access to the various raise methods |
|
|
|
|
| `sa` | Holds `pattern.settings.sa` |
|
|
|
|
| `store` | Holds `pattern.store`, a [Store](/reference/api/store) instance that is shared across parts |
|
|
|
|
| `utils` | A [Utils](/reference/api/utils) instance with utility methods |
|
|
|
|
| `units` | A context-aware version of `utils.units` |
|
|
|
|
|
|
|
|
## Part.shorthand() example
|
2021-08-25 16:09:31 +02:00
|
|
|
|
|
|
|
```js{16}
|
|
|
|
// You could write this:
|
|
|
|
part.points.from = new part.Point(
|
2021-09-25 17:53:09 +02:00
|
|
|
pattern.measurements.chest / 2,
|
|
|
|
pattern.options.armholeDepth
|
|
|
|
)
|
2021-08-25 16:09:31 +02:00
|
|
|
|
|
|
|
part.points.to = new part.Point(
|
|
|
|
part.points.from.x + pattern.settings.sa,
|
2021-09-25 17:53:09 +02:00
|
|
|
part.points.from.y
|
|
|
|
)
|
2021-08-25 16:09:31 +02:00
|
|
|
|
|
|
|
part.paths.example = new part.Path()
|
|
|
|
.move(parts.points.from)
|
2021-09-25 17:53:09 +02:00
|
|
|
.line(parts.points.to)
|
2021-08-25 16:09:31 +02:00
|
|
|
|
2021-09-25 17:53:09 +02:00
|
|
|
// Or use shorthand:
|
|
|
|
const { Point, points, measurements, options, sa } = part.shorthand()
|
2021-08-25 16:09:31 +02:00
|
|
|
|
|
|
|
points.from = new Point(
|
2021-09-25 17:53:09 +02:00
|
|
|
measurements.chest / 2,
|
|
|
|
options.armholeDepth
|
|
|
|
)
|
2021-08-25 16:09:31 +02:00
|
|
|
|
|
|
|
points.to = new part.Point(
|
|
|
|
points.from.x + sa,
|
2021-09-25 17:53:09 +02:00
|
|
|
points.from.y
|
|
|
|
)
|
2021-08-25 16:09:31 +02:00
|
|
|
|
|
|
|
paths.example = new Path()
|
|
|
|
.move(points.from)
|
2021-09-25 17:53:09 +02:00
|
|
|
.line(points.to)
|
2021-08-25 16:09:31 +02:00
|
|
|
```
|
|
|
|
|
|
|
|
<Tip>
|
|
|
|
|
2021-10-17 18:26:00 +02:00
|
|
|
As you can see in the example above, you can/should load only
|
2021-08-25 16:09:31 +02:00
|
|
|
the shorthand you need by using object destructuring.
|
|
|
|
|
|
|
|
</Tip>
|
2021-10-17 18:26:00 +02:00
|
|
|
|