From 8161b800811ac9107caf02ff1515a6400506f33e Mon Sep 17 00:00:00 2001 From: DarkWiiPlayer Date: Thu, 25 Nov 2021 10:04:27 +0100 Subject: [PATCH] Make the speaker retain its last spoken message --- speaker.js | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/speaker.js b/speaker.js index b7aef77..8a67e95 100644 --- a/speaker.js +++ b/speaker.js @@ -2,16 +2,20 @@ class Speaker { #callbacks = new Set() #immediate #scheduled = [] + #current - constructor(immediate) { + constructor(immediate, current=[]) { this.#immediate = immediate + this.#current = current } listen(callback) { this.#callbacks.add(callback) + return this.#current } speak(...args) { + this.#current = args if (this.#immediate) { for (let callback of this.#callbacks) { callback(...args)