Make the speaker retain its last spoken message

This commit is contained in:
Talia 2021-11-25 10:04:27 +01:00
parent 5036259d75
commit 8161b80081

View file

@ -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)