Something went wrong. Try again.
Experiment to rebuild Diffuse using web applets.
Something went wrong. Try again.
12345678910111213141516171819202122232425262728293031323334353637383940<script> import { applets } from "@web-applets/sdk"; import { QueueItem, State } from "./types";
//////////////////////////////////////////// // SETUP //////////////////////////////////////////// const context = applets.register<State>();
// Initial state context.data = { past: [], now: null, future: [], };
// State helpers function update(partial: Partial<State>): void { context.data = { ...context.data, ...partial }; }
//////////////////////////////////////////// // ACTIONS //////////////////////////////////////////// context.setActionHandler("add", add); context.setActionHandler("shift", shift);
function add(items: QueueItem[]) { update({ future: [...context.data.future, ...items] }); }
function shift() { const now = context.data.future[0] || null; const future = context.data.future.slice(1); const past = context.data.now ? [...context.data.past, context.data.now] : context.data.past;
update({ past, now, future }); }</script>