@@ -13,47 +13,47 @@ You can even use visualizer to visualize the data. We create a simple example on
1313Inspector will be a top-level API in Milkdown. You can use it like this:
1414
1515``` ts
16- import { Editor } from " @milkdown/core" ;
17- import { Telemetry } from " @milkdown/ctx" ;
16+ import { Editor } from ' @milkdown/core'
17+ import { Telemetry } from ' @milkdown/ctx'
1818
1919const editor = await Editor .make ()
2020 // Inspector is disabled by default considering performance. You need to enable it manually.
2121 .enableInspector ()
2222 // ...
23- .create ();
23+ .create ()
2424
25- const telemetry: Telemetry [] = editor .inspect ();
25+ const telemetry: Telemetry [] = editor .inspect ()
2626```
2727
2828The ` Telemetry ` interface will have the following fields:
2929
3030``` ts
3131interface Telemetry {
3232 // User defined information for the plugin.
33- metadata: Meta ;
33+ metadata: Meta
3434
3535 // The slices and their current value defined by the plugin.
36- injectedSlices: { name: string ; value: unknown }[];
36+ injectedSlices: { name: string ; value: unknown }[]
3737
3838 // The slices and their current value consumed by the plugin.
39- consumedSlices: { name: string ; value: unknown }[];
39+ consumedSlices: { name: string ; value: unknown }[]
4040
4141 // The timers and their duration defined by the plugin.
42- recordedTimers: { name: string ; duration: number ; status: TimerStatus }[];
42+ recordedTimers: { name: string ; duration: number ; status: TimerStatus }[]
4343
4444 // The timers and their duration consumed by the plugin.
4545 // Generally, the plugin will wait for them.
46- waitTimers: { name: string ; duration: number ; status: TimerStatus }[];
46+ waitTimers: { name: string ; duration: number ; status: TimerStatus }[]
4747}
4848
49- type TimerStatus = " pending" | " resolved" | " rejected" ;
49+ type TimerStatus = ' pending' | ' resolved' | ' rejected'
5050
5151interface Meta {
52- displayName: string ;
53- description? : string ;
54- package: string ;
55- group? : string ;
56- additional? : Record <string , any >;
52+ displayName: string
53+ description? : string
54+ package: string
55+ group? : string
56+ additional? : Record <string , any >
5757}
5858```
5959
@@ -62,52 +62,52 @@ With the data, you'll know the sequence of the plugins loaded, the slices and ti
6262For example:
6363
6464``` ts
65- [
65+ ; [
6666 {
6767 metadata: {
68- displayName: " Config" ,
69- package: " @milkdown/core" ,
70- group: " System" ,
68+ displayName: ' Config' ,
69+ package: ' @milkdown/core' ,
70+ group: ' System' ,
7171 },
7272 injectedSlices: [],
7373 consumedSlices: [
7474 /* ... */
7575 ],
7676 recordedTimers: [
7777 {
78- name: " ConfigReady" ,
78+ name: ' ConfigReady' ,
7979 duration: 3 ,
80- status: " resolved" ,
80+ status: ' resolved' ,
8181 },
8282 ],
8383 waitTimers: [],
8484 },
8585 {
8686 metadata: {
87- displayName: " Init" ,
88- package: " @milkdown/core" ,
89- group: " System" ,
87+ displayName: ' Init' ,
88+ package: ' @milkdown/core' ,
89+ group: ' System' ,
9090 },
9191 injectedSlices: [],
9292 consumedSlices: [
9393 /* ... */
9494 ],
9595 recordedTimers: [
9696 {
97- name: " InitReady" ,
97+ name: ' InitReady' ,
9898 duration: 5 ,
99- status: " resolved" ,
99+ status: ' resolved' ,
100100 },
101101 ],
102102 waitTimers: [
103103 {
104- name: " ConfigReady" ,
104+ name: ' ConfigReady' ,
105105 duration: 5 ,
106- status: " resolved" ,
106+ status: ' resolved' ,
107107 },
108108 ],
109109 },
110- ];
110+ ]
111111```
112112
113113From above information, we can know that the ` Init ` plugin wait for ` Config ` plugin to be ready.
@@ -120,23 +120,23 @@ We can build a sequence diagram from the data.
120120For plugin maintainers, you can add metadata to your plugin to make it more friendly to the inspector.
121121
122122``` ts
123- import { MilkdownPlugin } from " @milkdown/ctx" ;
123+ import { MilkdownPlugin } from ' @milkdown/ctx'
124124
125125const yourMilkdownPlugin: MilkdownPlugin = () => {
126126 /* your implementation */
127- };
127+ }
128128
129129yourMilkdownPlugin .metadata = {
130- displayName: " Your Plugin" ,
131- package: " your-plugin-package" ,
132- description: " Your plugin description" ,
133- group: " If you have a lot of plugins in your package, you can group them." ,
130+ displayName: ' Your Plugin' ,
131+ package: ' your-plugin-package' ,
132+ description: ' Your plugin description' ,
133+ group: ' If you have a lot of plugins in your package, you can group them.' ,
134134 addtitional: {
135135 /* You can add any additional information here. */
136- version: " 1.0.0" ,
137- authror: " Mike" ,
136+ version: ' 1.0.0' ,
137+ authror: ' Mike' ,
138138 },
139- };
139+ }
140140```
141141
142142With metadata, your plugin will report telemetry correctly to the inspector.
0 commit comments