Skip to content

Commit 86d7115

Browse files
committed
Shared code docs update
Signed-off-by: macdonst <simon.macdonald@gmail.com>
1 parent 94eda7b commit 86d7115

File tree

1 file changed

+25
-1
lines changed

1 file changed

+25
-1
lines changed

app/docs/md/patterns/architect-migration.md

+25-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,31 @@ Enhance uses file-based routing so that a route handler responds based on its fi
1212
Enhance project routes are in effect an Architect route handler with the data API and HTML response split into two files. Enhance also includes the Enhance SSR renderer for expanding Custom Elements on the server.
1313

1414
## Shared code (shared, views, models, and app)
15-
If you are familiar with Architect apps they use the convention of a `src/views` and `src/shared` folder to share code between handlers. View code is available only to `GET` routes and shared is available to all handlers. Enhance renames these folders so that views becomes `/app` and shared becomes `/models`.
15+
If you are familiar with Architect apps they use the convention of a `src/views` and `src/shared` folder to share code between handlers. View code is available only to `GET` routes and shared is available to all handlers. Enhance renames these folders so that views becomes `/app` and shared becomes `/shared`.
16+
17+
Any code placed in the `/shared` folder will be accessible from both the Enhance and Architect parts of your project. However, importing it is a bit odd.
18+
19+
In your Architect routes, use the `@architect/shared` package as you normally would. For example:
20+
21+
<doc-code filename="src/http/get-notes/index.mjs">
22+
23+
```javascript
24+
import data from '@architect/shared/notes.mjs'
25+
```
26+
27+
</doc-code>
28+
29+
From an Enhance API in `app/api` you would use a relative path in your import. For example:
30+
31+
<doc-code filename="app/api/notes.mjs">
32+
33+
```javascript
34+
import notes from '../../shared/notes.mjs'
35+
```
36+
37+
</doc-code>
38+
39+
For reference an [example project](https://github.com/macdonst/shared-code) is available.
1640

1741
## Convert routes from Architect and Enhance
1842
An Architect route is defined in the `app.arc` manifest.

0 commit comments

Comments
 (0)