From 2ebb6d128d01ca35de13dce99c7a69cf9c8b4bef Mon Sep 17 00:00:00 2001 From: Amir Raminfar Date: Sun, 19 Jul 2020 17:16:39 -0700 Subject: [PATCH] Created reset() --- assets/components/LogEventSource.vue | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/assets/components/LogEventSource.vue b/assets/components/LogEventSource.vue index c19ade03..524a7bef 100644 --- a/assets/components/LogEventSource.vue +++ b/assets/components/LogEventSource.vue @@ -29,14 +29,8 @@ export default { }, methods: { loadLogs(id) { - if (this.es) { - this.es.close(); - this.messages = []; - this.buffer = []; - this.es = null; - } + this.reset(); this.es = new EventSource(`${config.base}/api/logs/stream?id=${this.id}`); - this.es.addEventListener("container-stopped", (e) => { this.es.close(); this.buffer.push({ event: "container-stopped", message: "Container stopped", date: new Date() }); @@ -54,6 +48,14 @@ export default { this.messages.push(...this.buffer); this.buffer = []; }, + reset() { + if (this.es) { + this.es.close(); + this.es = null; + } + this.messages = []; + this.buffer = []; + }, async loadOlderLogs() { if (this.messages.length < 300) return;