jevstrudel.git / website / src / jev / jev.mjs
jev.mjsannotatedjev.mjssource25 lines · 1.3 KB · raw

What songs see: jev, the SDK's question builders choice, score and noul, and walk (a form's rules, in code), in the REPL's scope (repl/util.mjs evaluates every export of this module into it, so export nothing else). The API is in jevCore.mjs; here it is wired to the site's relay (ask.mjs) and to every listener's reactions (reactions.mjs).

6import { askJev } from './ask.mjs';
7import { nowPlaying } from './client.mjs';
8import { tallyFor } from './reactions.mjs';
9import { hear } from './meter.mjs';
10import { choice, createJev, noul, score, walk } from './jevCore.mjs';

How long until cycle begins, from the playing scheduler (null when the song is not playing, as before its opening): the relay logs it per call.

14const secondsUntil = (begins) => {
15  const scheduler = globalThis.strudelMirror?.repl?.scheduler;
16  if (!scheduler?.started || !(scheduler.cps > 0) || typeof begins !== 'number') return null;
17  return (begins - scheduler.now()) / scheduler.cps;
18};
20export const jev = createJev(
21  (state, questions, { begins } = {}) => askJev(questions, state, { secondsToSection: () => secondsUntil(begins) }),
22  // every listener's reactions to the playing song (reactions.mjs)
23  { hear, listeners: () => tallyFor(nowPlaying.get()) },
24);
25export { choice, noul, score, walk };