-
Notifications
You must be signed in to change notification settings - Fork 56
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
9e6f03e
commit c9ed664
Showing
1 changed file
with
51 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
# Architecture | ||
|
||
The Playground elements have three features that require a somewhat complex architecture: | ||
|
||
- Loading files from the main window into a preview iframe without using a server | ||
- Compiling TypeScript files and resolving bare import specifiers on the fly | ||
- Loading dependencies from a CDN | ||
|
||
To accomplish this, the Playground elements have a somewhat complex set of workers and iframes: | ||
- A preview iframe | ||
- A service worker to serve files to the preview iframe | ||
- A web worker to compile TypeScript files and resolve bare import specifiers | ||
- A proxy iframe to install and communicate with the service worker from the main page | ||
|
||
These workers and iframes are controlled by various Playground elements like `<playground-project>`, `<playground-preview>`, and `<playground-file-editor>`. | ||
|
||
```mermaid | ||
flowchart TD | ||
IDE{{<playground-ide>}} | ||
subgraph Project | ||
ProjectElement{{<playground-project>}} | ||
WebWorker(Build Worker) | ||
ProxyIframe[Proxy <iframe>] | ||
end | ||
subgraph Editors | ||
FileEditor1{{<playground-file-editor>}} | ||
FileEditor2{{<playground-file-editor>}} | ||
end | ||
subgraph Preview | ||
PreviewElement{{<playground-preview>}} | ||
PreviewIframe[Preview <iframe>] | ||
end | ||
subgraph Network | ||
ServiceWorker(Service Worker) | ||
CDN([CDN]) | ||
end | ||
IDE -...-> Project | ||
IDE -.-> Editors | ||
IDE -.-> Preview | ||
WebWorker -- Built Project Files --> ProjectElement | ||
ProjectElement -- Project Files --> WebWorker | ||
ProjectElement -- Built Project Files --> ProxyIframe | ||
Editors -- Project Files --> ProjectElement | ||
ProjectElement --> PreviewElement | ||
PreviewElement <--> PreviewIframe | ||
ProxyIframe -- Built Project Files --> ServiceWorker | ||
ServiceWorker -- All Files --> PreviewIframe | ||
CDN -- NPM Dependencies --> ServiceWorker | ||
CDN -- TypeScript Types --> WebWorker | ||
``` |