Skip to content

Commit f7cc5af

Browse files
committed
fix: debounce edition of code
1 parent 246dae5 commit f7cc5af

File tree

3 files changed

+12
-2
lines changed

3 files changed

+12
-2
lines changed

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
"acorn": "^6.1.1",
1616
"buble": "^0.19.7",
1717
"core-js": "^2.6.5",
18+
"lodash.debounce": "^4.0.8",
1819
"prismjs": "^1.16.0",
1920
"rewrite-imports": "^2.0.3",
2021
"vue": "^2.6.10",

src/VueLive.vue

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<template>
22
<VueLiveLayout>
33
<template v-slot:editor>
4-
<PrismEditor v-model="model" :language="prismLang"/>
4+
<PrismEditor :code="model" @change="updatePreview" :language="prismLang" :lineNumbers="true"/>
55
</template>
66
<template v-slot:preview>
77
<Preview
@@ -24,6 +24,7 @@ import "prismjs/components/prism-jsx.min";
2424
2525
import PrismEditor from "vue-prism-editor";
2626
import hash from "hash-sum";
27+
import debounce from "lodash.debounce";
2728
2829
import Preview from "./Preview.vue";
2930
import VueLiveLayout from "./VueLiveDefaultLayout.vue";
@@ -73,7 +74,10 @@ export default {
7374
methods: {
7475
switchLanguage(newLang) {
7576
this.prismLang = LANG_TO_PRISM[newLang];
76-
}
77+
},
78+
updatePreview: debounce(function(value) {
79+
this.model = value;
80+
}, 300)
7781
}
7882
};
7983
</script>

yarn.lock

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6615,6 +6615,11 @@ locate-path@^3.0.0:
66156615
p-locate "^3.0.0"
66166616
path-exists "^3.0.0"
66176617

6618+
lodash.debounce@^4.0.8:
6619+
version "4.0.8"
6620+
resolved "https://registry.yarnpkg.com/lodash.debounce/-/lodash.debounce-4.0.8.tgz#82d79bff30a67c4005ffd5e2515300ad9ca4d7af"
6621+
integrity sha1-gteb/zCmfEAF/9XiUVMArZyk168=
6622+
66186623
lodash.defaultsdeep@^4.6.0:
66196624
version "4.6.0"
66206625
resolved "https://registry.yarnpkg.com/lodash.defaultsdeep/-/lodash.defaultsdeep-4.6.0.tgz#bec1024f85b1bd96cbea405b23c14ad6443a6f81"

0 commit comments

Comments
 (0)