2021-10-17 18:26:00 +02:00
|
|
|
---
|
2021-08-25 16:09:31 +02:00
|
|
|
title: Sharing data between parts
|
2021-10-17 18:26:00 +02:00
|
|
|
---
|
2021-08-25 16:09:31 +02:00
|
|
|
|
2022-10-12 14:42:45 +02:00
|
|
|
Sometimes, you'll want to access data from one part into another part. For
|
|
|
|
example, you may store the length of the armhole in your front and back parts,
|
|
|
|
and then read that value when drafting the sleeve so you can verify the sleeve
|
|
|
|
fits the armhole.
|
2021-08-25 16:09:31 +02:00
|
|
|
|
2022-10-12 14:42:45 +02:00
|
|
|
For this, you should use the [Store](/reference/api/store/), which is available
|
|
|
|
via _destructuring_ in your part's draft method.
|
2021-08-25 16:09:31 +02:00
|
|
|
|
2022-10-12 14:42:45 +02:00
|
|
|
Setting a value in one part:
|
2021-08-25 16:09:31 +02:00
|
|
|
|
2022-10-12 14:42:45 +02:00
|
|
|
```mjs
|
|
|
|
function draftPartA({
|
|
|
|
// highlight-start
|
|
|
|
store,
|
|
|
|
// highlight-end
|
|
|
|
part,
|
|
|
|
}) {
|
|
|
|
// highlight-start
|
|
|
|
store.set('hello', 'world')
|
|
|
|
// highlight-end
|
|
|
|
|
|
|
|
return part()
|
2021-08-25 16:09:31 +02:00
|
|
|
}
|
|
|
|
```
|
|
|
|
|
2022-10-12 14:42:45 +02:00
|
|
|
Reading a value in another part:
|
|
|
|
|
|
|
|
```mjs
|
|
|
|
function draftPartB({
|
|
|
|
// highlight-start
|
|
|
|
store,
|
|
|
|
// highlight-end
|
|
|
|
part,
|
|
|
|
}) {
|
|
|
|
// highlight-start
|
|
|
|
const value = store.get('hello')
|
|
|
|
// value now contains 'world'
|
|
|
|
// highlight-end
|
2021-08-25 16:09:31 +02:00
|
|
|
|
2022-10-12 14:42:45 +02:00
|
|
|
return part()
|
2021-08-25 16:09:31 +02:00
|
|
|
}
|
|
|
|
```
|
|
|
|
|
|
|
|
In a case like this, the order in which parts are drafted becomes important, so you
|
2022-10-12 14:42:45 +02:00
|
|
|
should reflect that in the [part dependencies](/howtos/code/after).
|