Published
Edited
Apr 7, 2021
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
speakWorker = {
const set = v => viewof isChecked.setValue(v)
while (sayText.length) {
yield 'waiting to start'
await Promises.delay(PLAYBACK_SPEED * 7)
for (const char of morseLib.encode(sayText)) {
if (char === '.') {
yield 'saying .'
set(true)
await Promises.delay(PLAYBACK_SPEED)
set(false)
} else if (char === '-') {
yield 'saying -'
set(true)
await Promises.delay(PLAYBACK_SPEED * 3)
set(false)
} else if (char === ' ') {
yield 'saying space'
set(false)
await Promises.delay(PLAYBACK_SPEED)
}
await Promises.delay(PLAYBACK_SPEED)
}
}
yield 'idle'
}
Insert cell
Insert cell
interactivityWorker = {
yield 'waiting...'
yield Promises.delay(2000, 'fetching...')
if (text.length) {
mutable clickTimes = []
const resp = await fetch(`https://morse.xkcd.com:8000/say/${sessionId ? sessionId + '/' : ''}${text}`)
const data = await resp.json()
mutable sessionId = data.state
mutable sayText = data.say
yield data.say
}
}
Insert cell
morseLib = require('morse-decoder')
Insert cell

Purpose-built for displays of data

Observable is your go-to platform for exploring data and creating expressive data visualizations. Use reactive JavaScript notebooks for prototyping and a collaborative canvas for visual data exploration and dashboard creation.
Learn more