Change status list to es6 Map

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

View File

@ -14,7 +14,7 @@
<div id="timelines"> <div id="timelines">
<div v-for="(value, key, index) in pubTL" :key="index" class="tl"> <div v-for="(value, key, index) in pubTL" :key="index" class="tl">
{{value.name}} {{value.name}}
<div v-for="(status, key, index) in value.statuses" :key="index" class="tl">{{status.id}}</div> <div v-for="[id,status] in Array.from(value.statuses)" :key="id" class="tl">{{status.id}}</div>
</div> </div>
</div> </div>
<BaseButton <BaseButton
@ -34,7 +34,7 @@ import { Status } from 'megalodon'
type Instance = string type Instance = string
type Timeline = { type Timeline = {
name: string name: string
statuses: Status[] statuses: Map<number, Status>
} }
type UpdateListener = (e: Event, status: Status) => void type UpdateListener = (e: Event, status: Status) => void
type Timelines = Timeline[] type Timelines = Timeline[]
@ -59,28 +59,28 @@ export default class AddColumn extends Vue {
this.showInput = false this.showInput = false
let instance = this.instance let instance = this.instance
this.pubTL.push({ name: instance, statuses: [] }) let timeline: Timeline = { name: this.instance, statuses: new Map() }
this.timeline()
this.pubTL.push(timeline)
this.loadTL(timeline)
let updateListener = (_: Event, status: Status) => { let updateListener = (_: Event, status: Status) => {
this.pubTL.filter(tl => tl.name === instance).forEach(function (tl) { this.pubTL.filter(tl => tl.name === timeline.name).forEach(function (tl) {
tl.statuses.unshift(status) tl.statuses.set(status.id, status)
}) })
this.$forceUpdate() this.$forceUpdate()
} }
ipcRenderer.on(`update-${instance}-no-auth`, updateListener) ipcRenderer.on(`update-${timeline.name}-no-auth`, updateListener)
this.updateListeners.push([`update-${instance}-no-auth`, updateListener]) this.updateListeners.push([`update-${timeline.name}-no-auth`, updateListener])
ipcRenderer.send('open-streaming', instance, 'no-auth') ipcRenderer.send('open-streaming', instance, 'no-auth')
} }
public timeline() { public loadTL(timeline: Timeline) {
this.pubTL.forEach(function (tl) { ipcRenderer.once(`timeline-${timeline.name}-no-auth`, (_: Event, statuses: Status[]) => {
ipcRenderer.on(`timeline-${tl.name}-no-auth`, (_: Event, statuses: Status[]) => { timeline.statuses = new Map(statuses.map((status): [number, Status] => [status.id, status]))
tl.statuses = statuses
})
ipcRenderer.send('no-auth-timeline', tl.name)
}) })
ipcRenderer.send('no-auth-timeline', timeline.name)
} }
} }
</script>= </script>=