Remove listener when component destroy

This commit is contained in:
kPherox 2019-04-24 17:15:42 +09:00
parent 52c6ff22ee
commit cee7b7f079
No known key found for this signature in database
GPG Key ID: C04751C2BFA2F62D

View File

@ -32,18 +32,25 @@ import { Component, Vue } from 'vue-property-decorator'
import { Status } from 'megalodon'
type Instance = string
type showInput = boolean
type Timeline = {
name: string
statuses: Status[]
}
type UpdateListener = (e: Event, status: Status) => void
type Timelines = Timeline[]
@Component
export default class AddColumn extends Vue {
public instance: Instance = ''
public showInput: showInput = true
public showInput: boolean = true
public updateListeners: [string, UpdateListener][] = []
public pubTL: Timelines = []
beforeDestroy() {
this.updateListeners.forEach(([name, listener]) => {
ipcRenderer.removeListener(name, listener)
})
}
public get hasDomain() {
return this.instance != ''
}
@ -55,12 +62,16 @@ export default class AddColumn extends Vue {
this.pubTL.push({ name: instance, statuses: [] })
this.timeline()
ipcRenderer.send('open-streaming', instance, 'no-auth')
ipcRenderer.on(`update-${instance}-no-auth`, (_: Event, status: Status) => {
let updateListener = (_: Event, status: Status) => {
this.pubTL.filter(tl => tl.name === instance).forEach(function (tl) {
tl.statuses.unshift(status)
})
})
this.$forceUpdate()
}
ipcRenderer.on(`update-${instance}-no-auth`, updateListener)
this.updateListeners.push([`update-${instance}-no-auth`, updateListener])
ipcRenderer.send('open-streaming', instance, 'no-auth')
}
public timeline() {