From a0e5b2777d7063cdb4cec0e9507222a00f82e63a Mon Sep 17 00:00:00 2001 From: kPherox Date: Wed, 24 Apr 2019 17:31:18 +0900 Subject: [PATCH] Change status list to es6 Map --- src/components/AddColumn/PublicTimeline.vue | 28 ++++++++++----------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/src/components/AddColumn/PublicTimeline.vue b/src/components/AddColumn/PublicTimeline.vue index 91c6dc9c..67607ddd 100644 --- a/src/components/AddColumn/PublicTimeline.vue +++ b/src/components/AddColumn/PublicTimeline.vue @@ -14,7 +14,7 @@
{{value.name}} -
{{status.id}}
+
{{status.id}}
} type UpdateListener = (e: Event, status: Status) => void type Timelines = Timeline[] @@ -59,28 +59,28 @@ export default class AddColumn extends Vue { this.showInput = false let instance = this.instance - this.pubTL.push({ name: instance, statuses: [] }) - this.timeline() + let timeline: Timeline = { name: this.instance, statuses: new Map() } + + this.pubTL.push(timeline) + this.loadTL(timeline) let updateListener = (_: Event, status: Status) => { - this.pubTL.filter(tl => tl.name === instance).forEach(function (tl) { - tl.statuses.unshift(status) + this.pubTL.filter(tl => tl.name === timeline.name).forEach(function (tl) { + tl.statuses.set(status.id, status) }) this.$forceUpdate() } - ipcRenderer.on(`update-${instance}-no-auth`, updateListener) - this.updateListeners.push([`update-${instance}-no-auth`, updateListener]) + ipcRenderer.on(`update-${timeline.name}-no-auth`, updateListener) + this.updateListeners.push([`update-${timeline.name}-no-auth`, updateListener]) ipcRenderer.send('open-streaming', instance, 'no-auth') } - public timeline() { - this.pubTL.forEach(function (tl) { - ipcRenderer.on(`timeline-${tl.name}-no-auth`, (_: Event, statuses: Status[]) => { - tl.statuses = statuses - }) - ipcRenderer.send('no-auth-timeline', tl.name) + public loadTL(timeline: Timeline) { + ipcRenderer.once(`timeline-${timeline.name}-no-auth`, (_: Event, statuses: Status[]) => { + timeline.statuses = new Map(statuses.map((status): [number, Status] => [status.id, status])) }) + ipcRenderer.send('no-auth-timeline', timeline.name) } } =