Skip to content

Commit edd22bc

Browse files
authored
chore: use mermaid engine and mermaid in markdown (#2759)
1 parent eb884c5 commit edd22bc

File tree

3 files changed

+63
-6
lines changed

3 files changed

+63
-6
lines changed

docs/api/api-lifecycle.md

Lines changed: 33 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,39 @@ An Undici [Client](Client.md) can be best described as a state machine. The foll
2121
* At any point in time, the *destroy* event will transition the `Client` from the **processing** state to the **destroyed** state, destroying any queued requests.
2222
* The **destroyed** state is a final state and the `Client` is no longer functional.
2323

24-
![A state diagram representing an Undici Client instance](../assets/lifecycle-diagram.png)
25-
26-
> The diagram was generated using Mermaid.js Live Editor. Modify the state diagram [here](https://mermaid-js.github.io/mermaid-live-editor/#/edit/eyJjb2RlIjoic3RhdGVEaWFncmFtLXYyXG4gICAgWypdIC0tPiBpZGxlXG4gICAgaWRsZSAtLT4gcGVuZGluZyA6IGNvbm5lY3RcbiAgICBpZGxlIC0tPiBkZXN0cm95ZWQgOiBkZXN0cm95L2Nsb3NlXG4gICAgXG4gICAgcGVuZGluZyAtLT4gaWRsZSA6IHRpbWVvdXRcbiAgICBwZW5kaW5nIC0tPiBkZXN0cm95ZWQgOiBkZXN0cm95XG5cbiAgICBzdGF0ZSBjbG9zZV9mb3JrIDw8Zm9yaz4-XG4gICAgcGVuZGluZyAtLT4gY2xvc2VfZm9yayA6IGNsb3NlXG4gICAgY2xvc2VfZm9yayAtLT4gcHJvY2Vzc2luZ1xuICAgIGNsb3NlX2ZvcmsgLS0-IGRlc3Ryb3llZFxuXG4gICAgcGVuZGluZyAtLT4gcHJvY2Vzc2luZyA6IHByb2Nlc3NcblxuICAgIHByb2Nlc3NpbmcgLS0-IHBlbmRpbmcgOiBrZWVwYWxpdmVcbiAgICBwcm9jZXNzaW5nIC0tPiBkZXN0cm95ZWQgOiBkb25lXG4gICAgcHJvY2Vzc2luZyAtLT4gZGVzdHJveWVkIDogZGVzdHJveVxuXG4gICAgc3RhdGUgcHJvY2Vzc2luZyB7XG4gICAgICAgIHJ1bm5pbmcgLS0-IGJ1c3kgOiBuZWVkRHJhaW5cbiAgICAgICAgYnVzeSAtLT4gcnVubmluZyA6IGRyYWluQ29tcGxldGVcbiAgICAgICAgcnVubmluZyAtLT4gWypdIDoga2VlcGFsaXZlXG4gICAgICAgIHJ1bm5pbmcgLS0-IGNsb3NpbmcgOiBjbG9zZVxuICAgICAgICBjbG9zaW5nIC0tPiBbKl0gOiBkb25lXG4gICAgICAgIFsqXSAtLT4gcnVubmluZ1xuICAgIH1cbiAgICAiLCJtZXJtYWlkIjp7InRoZW1lIjoiYmFzZSJ9LCJ1cGRhdGVFZGl0b3IiOmZhbHNlfQ)
27-
24+
A state diagram representing an Undici Client instance:
25+
26+
```mermaid
27+
stateDiagram-v2
28+
[*] --> idle
29+
idle --> pending : connect
30+
idle --> destroyed : destroy/close
31+
32+
pending --> idle : timeout
33+
pending --> destroyed : destroy
34+
35+
state close_fork <<fork>>
36+
pending --> close_fork : close
37+
close_fork --> processing
38+
close_fork --> destroyed
39+
40+
pending --> processing : process
41+
42+
processing --> pending : keepalive
43+
processing --> destroyed : done
44+
processing --> destroyed : destroy
45+
46+
destroyed --> [*]
47+
48+
state processing {
49+
[*] --> running
50+
running --> closing : close
51+
running --> busy : needDrain
52+
busy --> running : drainComplete
53+
running --> [*] : keepalive
54+
closing --> [*] : done
55+
}
56+
```
2857
## State details
2958

3059
### idle

docs/assets/lifecycle-diagram.png

-46 KB
Binary file not shown.

index.html

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,6 @@
88
<meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0">
99
<link rel="stylesheet" href="//cdn.jsdelivr.net/npm/docsify@4/lib/themes/vue.css">
1010
<link rel="icon" type="image/png" href="https://nodejs.org/static/images/favicons/favicon.png" />
11-
<style>
12-
</style>
1311
</head>
1412
<body>
1513
<div id="app"></div>
@@ -30,5 +28,35 @@
3028
</script>
3129
<!-- Docsify v4 -->
3230
<script src="//cdn.jsdelivr.net/npm/docsify@4"></script>
31+
<script type="module">
32+
import mermaid from "//cdn.jsdelivr.net/npm/[email protected]/+esm";
33+
mermaid.initialize({ startOnLoad: true });
34+
window.mermaid = mermaid;
35+
</script>
36+
<script>
37+
const plugin = (config) => (hook) => {
38+
hook.afterEach((html, next) => {
39+
const container = document.createElement('div');
40+
container.innerHTML = html;
41+
42+
const elements = container.querySelectorAll('pre[data-lang=mermaid]')
43+
for (const element of elements) {
44+
const replacement = document.createElement('div');
45+
replacement.textContent = element.textContent;
46+
replacement.classList.add('mermaid');
47+
element.parentNode.replaceChild(replacement, element);
48+
}
49+
50+
next(container.innerHTML);
51+
});
52+
53+
hook.doneEach(() => mermaid.run(config));
54+
}
55+
56+
window.$docsify = window.$docsify || {};
57+
58+
window.$docsify.plugins = window.$docsify.plugins || []
59+
window.$docsify.plugins.push(plugin(window.$docsify.mermaidConfig || { querySelector: ".mermaid" }));
60+
</script>
3361
</body>
3462
</html>

0 commit comments

Comments
 (0)