1
0
Fork 0
freesewing/markdown/dev/howtos/code/shared-dimensions/en.md
nikhil 0becd057b2 fix: Broken/misleading links to designs' source code
Some of these links were actually broken, since they expect to find designs under the `packages/` directory in the current `develop` branch. Other links were technically okay, since they link to old commits, but updating those links may still help to reduce confusion.

Also fix a reference to `packages/unice` in a `netlify.toml` file. (Untested, but I don't think this is an actual Netlify configuration.)
2022-08-21 12:31:23 -04:00

54 lines
1.3 KiB
Markdown

---
title: Share dimensions between pattern parts
for: developers
about: Shows how to share dimensions between similar pattern parts
---
<Note>
##### See this example in our source code
- [designs/aaron/src/shared.js](https://github.com/freesewing/freesewing/blob/3ca5d0edfe54c7ac20aaf3af2f3544aee72f9b99/designs/aaron/src/shared.js)
- [designs/aaron/src/front.js](https://github.com/freesewing/freesewing/blob/3ca5d0edfe54c7ac20aaf3af2f3544aee72f9b99/designs/aaron/src/front.js#L160)
</Note>
When you have different pattern parts that look similar -- like the front
and back of a garment -- you may find that there's a lot of dimensions
shared between them.
The example below is from Aaron where dimensions are shared between
the back and front part.
Aaron has a file called `shared.js` that looks like this:
```js
export function dimensions(macro, points, sa) {
macro('hd', {
from: points.cfHem,
to: points.hem,
y: points.hem.y + sa * 2.5 + 15
})
// more dimensions here
}
```
In both `front.js` and `back.js` we use this code to add these shared dimensions:
```js
import { dimensions } from './shared'
// ...
if (paperless) {
dimensions(macro, points, sa)
// ... specific dimensions
}
```
<Note>
Since our shared dimension method is a so-called _named export_ we need to
import it with the syntax you see above.
</Note>