Skip to content

Commit df2ba65

Browse files
committed
fix: some performance update
async import some large modules
1 parent 4e5a116 commit df2ba65

File tree

4 files changed

+75
-52
lines changed

4 files changed

+75
-52
lines changed

.vscode/extensions.json

Lines changed: 0 additions & 3 deletions
This file was deleted.

src/components/codecovEcharts.vue

Lines changed: 33 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
<script lang="ts" setup>
2-
import * as echarts from "echarts";
32
import { ref, Ref, onMounted, inject } from "vue";
43
import { getSunBurstData, getTotalCov, SunBurstData } from "@/hooks/codecov";
54
const covchartsDom = ref<HTMLInputElement | null>(null);
@@ -9,40 +8,42 @@ const totalCovTarget = ref("Pivot Lang");
98
const isMobile = inject("isMobile") as boolean;
109
1110
onMounted(async () => {
12-
const data = getSunBurstData(await getTotalCov());
13-
totalCov.value = data.coverage;
14-
const option = {
15-
tooltip: {
16-
trigger: "item",
17-
},
18-
series: {
19-
type: "sunburst",
20-
sort: undefined,
11+
import("echarts").then(async (echarts) => {
12+
const data = getSunBurstData(await getTotalCov());
13+
totalCov.value = data.coverage;
14+
const option = {
2115
tooltip: {
22-
formatter: handleCovChange,
23-
},
24-
emphasis: {
25-
disable: true,
16+
trigger: "item",
2617
},
27-
data: data.children,
28-
label: {
29-
formatter: "",
30-
show: false,
18+
series: {
19+
type: "sunburst",
20+
sort: undefined,
21+
tooltip: {
22+
formatter: handleCovChange,
23+
},
24+
emphasis: {
25+
disable: true,
26+
},
27+
data: data.children,
28+
label: {
29+
formatter: "",
30+
show: false,
31+
},
32+
levels: [],
3133
},
32-
levels: [],
33-
},
34-
};
35-
const myChart = echarts.init(covchartsDom.value as HTMLElement);
36-
const loadEcharts = () => {
37-
const { top, bottom } = (
38-
covchartsDom.value as HTMLElement
39-
).getBoundingClientRect();
40-
if (top < window.innerHeight && bottom > 0) {
41-
window.removeEventListener("scroll", loadEcharts);
42-
myChart.setOption(option);
43-
}
44-
};
45-
window.addEventListener("scroll", loadEcharts);
34+
};
35+
const myChart = echarts.init(covchartsDom.value as HTMLElement);
36+
const loadEcharts = () => {
37+
const { top, bottom } = (
38+
covchartsDom.value as HTMLElement
39+
).getBoundingClientRect();
40+
if (top < window.innerHeight && bottom > 0) {
41+
window.removeEventListener("scroll", loadEcharts);
42+
myChart.setOption(option);
43+
}
44+
};
45+
window.addEventListener("scroll", loadEcharts);
46+
});
4647
// myChart.setOption(option);
4748
});
4849

src/components/tabList.vue

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
<script lang="ts" setup>
2-
import { PlMonaco } from "@pivot-lang/create-monaco";
32
import axios from "axios";
43
import { nextTick } from "vue";
54
import { onMounted, ref } from "vue";

src/pages/index.vue

Lines changed: 42 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -15,17 +15,20 @@ import {
1515
import { ref, onMounted, watch } from "vue";
1616
import { basicCode } from "@/constant";
1717
import { memberList } from "@/constant";
18-
import createMonaco, { PlMonaco } from "@pivot-lang/create-monaco";
18+
// import createMonaco, { PlMonaco } from "@pivot-lang/create-monaco";
1919
import CodeBlock from "@/components/codeBlock.vue";
2020
import { cp } from "fs";
2121
import "xterm/css/xterm.css";
2222
import { Terminal } from "xterm";
2323
2424
const tabVal = ref("hello world");
2525
const tabList = basicCode.map((item) => item.title);
26-
let monaco: PlMonaco;
2726
let code = ref("");
2827
let runResult = ref("");
28+
let initialized = ref(false);
29+
let watchCallback = (val:string) => {
30+
console.log('not initialized yet...');
31+
};
2932
function gotoEmail() {
3033
window.location.href = "mailto:[email protected]";
3134
}
@@ -47,41 +50,47 @@ function handleOutput(re: string) {
4750
}
4851
4952
onMounted(async () => {
50-
monaco = createMonaco(
51-
document.getElementById("container")!,
52-
basicCode[0].code
53-
);
5453
code.value = basicCode[0].code;
55-
monaco.editor.onDidChangeModelContent(() => {
56-
code.value = monaco.editor.getModel()!.getValue();
54+
import("@pivot-lang/create-monaco").then(pl=>{
55+
let monaco = pl.default(
56+
document.getElementById("container")!,
57+
basicCode[0].code
58+
);
59+
monaco.editor.onDidChangeModelContent(() => {
60+
code.value = monaco.editor.getModel()!.getValue();
61+
});
62+
terminal.open(document.querySelector(".code-block") as HTMLElement);
63+
terminal.resize(44, 17);
64+
watchCallback = (val) => {
65+
const code1 = basicCode.find((item) => item.title === val)?.code || "";
66+
code.value = code1;
67+
monaco.setContent(code1);
68+
};
69+
initialized.value = true;
5770
});
58-
terminal.open(document.querySelector(".code-block") as HTMLElement);
59-
terminal.resize(44, 17);
6071
});
6172
watch(
6273
() => tabVal.value,
6374
(val) => {
64-
const code1 = basicCode.find((item) => item.title === val)?.code || "";
65-
code.value = code1;
66-
monaco.setContent(code1);
75+
watchCallback(val);
6776
}
6877
);
6978
</script>
7079

7180
<template>
7281
<div class="container">
7382
<Nav></Nav>
74-
<FirstPage :monaco="monaco"></FirstPage>
83+
<FirstPage></FirstPage>
7584
<div id="code-show">
7685
<div class="gradient-font title">Enjoy coding pivot lang now!</div>
7786
<div class="detail-describe">
7887
With the help of Web Assembly technology, we are able to provide support
7988
for some of the Pivot Lang syntax in the browser for you to experience.
8089
</div>
81-
<div class="code-now-container">
90+
<div v-show="initialized" class="code-now-container">
8291
<div class="code-box">
8392
<TabList
84-
@updateVal="(val) => (tabVal = val)"
93+
@updateVal="(val:string) => (tabVal = val)"
8594
@updateOutput="handleOutput"
8695
:tablist="tabList"
8796
:val="tabVal"
@@ -96,6 +105,9 @@ watch(
96105
<div class="code-block"></div>
97106
</div>
98107
</div>
108+
<div v-show="!initialized" class="code-now-container">
109+
<div class="spinner"></div>
110+
</div>
99111
</div>
100112
<div id="advantage">
101113
<div class="gradient-font title">Immix Garbage Collector</div>
@@ -334,4 +346,18 @@ watch(
334346
}
335347
}
336348
}
349+
@keyframes spin {
350+
0% { transform: rotate(0deg); }
351+
100% { transform: rotate(360deg); }
352+
}
353+
354+
.spinner {
355+
border: 16px solid #f3f3f3; /* Light grey */
356+
border-top: 16px solid #3498db; /* Blue */
357+
border-radius: 50%;
358+
width: 120px;
359+
height: 120px;
360+
animation: spin 2s linear infinite;
361+
margin: auto;
362+
}
337363
</style>

0 commit comments

Comments
 (0)