Skip to content

Commit d1d0bc5

Browse files
fix: unsubscribe on unmount for emiiter events #29 (#32)
1 parent a7dfceb commit d1d0bc5

File tree

6 files changed

+30
-6
lines changed

6 files changed

+30
-6
lines changed

src/renderer/components/editor/TheEditor.vue

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
</template>
2929

3030
<script setup lang="ts">
31-
import { computed, onMounted, reactive, ref, watch } from 'vue'
31+
import { computed, onMounted, onUnmounted, reactive, ref, watch } from 'vue'
3232
import type { Ace } from 'ace-builds'
3333
import ace from 'ace-builds'
3434
import './module-resolver'
@@ -271,6 +271,10 @@ watch(
271271
272272
emitter.on('snippet:format', () => format())
273273
274+
onUnmounted(() => {
275+
emitter.off('snippet:format')
276+
})
277+
274278
window.addEventListener('resize', () => {
275279
forceRefresh.value = Math.random()
276280
})

src/renderer/components/sidebar/SidebarList.vue

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@
4646
</template>
4747

4848
<script setup lang="ts">
49-
import { computed, nextTick, ref } from 'vue'
49+
import { computed, nextTick, onUnmounted, ref } from 'vue'
5050
import type { Tab, Tabs } from '@shared/types/renderer/sidebar'
5151
import { emitter, setScrollPosition } from '@/composable'
5252
@@ -90,6 +90,10 @@ emitter.on('scroll-to:folder', id => {
9090
}
9191
})
9292
})
93+
94+
onUnmounted(() => {
95+
emitter.off('scroll-to:folder')
96+
})
9397
</script>
9498

9599
<style lang="scss" scoped>

src/renderer/components/sidebar/TheFolder.vue

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
import { emitter } from '@/composable'
2424
import { useFolderStore } from '@/store/folders'
2525
import { onClickOutside } from '@vueuse/core'
26-
import { computed, nextTick, ref, watch } from 'vue'
26+
import { computed, nextTick, onUnmounted, ref, watch } from 'vue'
2727
2828
interface Props {
2929
id: string
@@ -62,6 +62,10 @@ watch(isEdit, () => {
6262
emitter.on('folder:rename', id => {
6363
if (id === props.id) isEdit.value = true
6464
})
65+
66+
onUnmounted(() => {
67+
emitter.off('folder:rename')
68+
})
6569
</script>
6670

6771
<style lang="scss" scoped>

src/renderer/components/snippets/SnippetHeader.vue

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636
import { emitter, onAddNewFragment, onCopySnippet } from '@/composable'
3737
import { useSnippetStore } from '@/store/snippets'
3838
import { useDebounceFn } from '@vueuse/core'
39-
import { computed, ref } from 'vue'
39+
import { computed, onUnmounted, ref } from 'vue'
4040
import { useAppStore } from '@/store/app'
4141
4242
const snippetStore = useSnippetStore()
@@ -62,6 +62,10 @@ const onClickMarkdownPreview = () => {
6262
emitter.on('snippet:focus-name', () => {
6363
inputRef.value?.select()
6464
})
65+
66+
onUnmounted(() => {
67+
emitter.off('snippet:focus-name')
68+
})
6569
</script>
6670

6771
<style lang="scss" scoped>

src/renderer/components/snippets/SnippetList.vue

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
import { emitter, setScrollPosition } from '@/composable'
3535
import { useAppStore } from '@/store/app'
3636
import { useSnippetStore } from '@/store/snippets'
37-
import { onMounted, ref, watch } from 'vue'
37+
import { onMounted, onUnmounted, ref, watch } from 'vue'
3838
import interact from 'interactjs'
3939
import { store } from '@/electron'
4040
@@ -73,6 +73,10 @@ watch(
7373
emitter.on('folder:click', () => {
7474
setScrollPosition(bodyRef.value!, 0)
7575
})
76+
77+
onUnmounted(() => {
78+
emitter.off('folder:click')
79+
})
7680
</script>
7781

7882
<style lang="scss" scoped>

src/renderer/components/snippets/SnippetListHeader.vue

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
import { emitter, onAddNewSnippet } from '@/composable'
2828
import { useSnippetStore } from '@/store/snippets'
2929
import { useDebounceFn } from '@vueuse/core'
30-
import { computed, ref } from 'vue'
30+
import { computed, onUnmounted, ref } from 'vue'
3131
import { track } from '@/electron'
3232
3333
const snippetStore = useSnippetStore()
@@ -52,6 +52,10 @@ const onReset = () => {
5252
emitter.on('search:focus', () => {
5353
inputRef.value?.focus()
5454
})
55+
56+
onUnmounted(() => {
57+
emitter.off('search:focus')
58+
})
5559
</script>
5660

5761
<style lang="scss" scoped>

0 commit comments

Comments
 (0)