From af2e55fda02ac70e0a30bbb5ad03cf4b19363f96 Mon Sep 17 00:00:00 2001 From: macdonst Date: Wed, 20 Mar 2024 10:49:40 -0400 Subject: [PATCH] Shared code docs update Signed-off-by: macdonst --- app/docs/md/patterns/architect-migration.md | 26 ++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) diff --git a/app/docs/md/patterns/architect-migration.md b/app/docs/md/patterns/architect-migration.md index f04b8d37..22173e78 100644 --- a/app/docs/md/patterns/architect-migration.md +++ b/app/docs/md/patterns/architect-migration.md @@ -12,7 +12,31 @@ Enhance uses file-based routing so that a route handler responds based on its fi 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. ## Shared code (shared, views, models, and app) -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`. +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`. + +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. + +In your Architect routes, use the `@architect/shared` package as you normally would. For example: + + + +```javascript +import data from '@architect/shared/notes.mjs' +``` + + + +From an Enhance API in `app/api` you would use a relative path in your import. For example: + + + +```javascript +import notes from '../../shared/notes.mjs' +``` + + + +For reference an [example project](https://github.com/macdonst/shared-code) is available. ## Convert routes from Architect and Enhance An Architect route is defined in the `app.arc` manifest.