1const msg = new TextEncoder().encode("💩");
2const initialDelay = 20;
3export default async function(req: Request): Promise<Response> {
4 let timerId: number | undefined;
5 const body = new ReadableStream({
6 start(controller) {
7 let currentDelay = initialDelay;
8 function writeToStream() {
9 currentDelay *= 1.03;
10 controller.enqueue(msg);
1const msg = new TextEncoder().encode("💩");
2const delay = 10;
3export default async function(req: Request): Promise<Response> {
4 let timerId: number | undefined;
5 const body = new ReadableStream({
4
5const scale = 0.15;
6export default async function(req: Request) {
7 let timerId: number | undefined;
8 const body = new ReadableStream({
19const messages = ["What should I build today?", "Very cool. Can you make it even cooler?"];
20
21export default async function(req: Request): Promise<Response> {
22 const url = new URL(req.url);
23 if (url.pathname === "/favicon.ico") {
1import { getRandomEmoji } from "https://esm.town/v/maxm/getRandomEmoji";
2
3export default async function(req: Request): Promise<Response> {
4 let timer: number | undefined = undefined;
5 const body = new ReadableStream({
1import emojis from "https://esm.sh/emojis-list";
2export function getRandomEmoji(): string {
3 return emojis[Math.floor(Math.random() * emojis.length)];
4}
121. **Random Joke Generator:** Fetch a random joke from an API and display it.
132. **Daily Weather Update:** Pull weather data for your location using an API and create a daily summary.
143. **Mini Todo List:** Create a simple to-do list app with add, edit, and delete functionalities.
154. **Chuck Norris Facts:** Display a random Chuck Norris fact sourced from an API.
165. **Motivational Quote of the Day:** Fetch and display a random motivational quote each day.
7// import "https://esm.sh/tldraw/tldraw.css";
8
9export function App() {
10 return (
11 <>
27const TIMEOUT = 5 * oneSecond;
28
29const DEFAULT_HANDLER = `export default async function (req: Request): Promise<Response> {
30 console.log(req.url)
31 return Response.json([1, 1+1, 12/4, parseInt("4")]);
41`;
42
43function parseResultSet<T>(row: ResultSet): T[] {
44 return row.rows.map((r) => Object.fromEntries(r.map((c, i) => [row.columns[i], c]))) as T[];
45}
55 get(target, key) {
56 const real = target[key];
57 if (typeof real === "function" && typeof key === "string") {
58 const fn = function(...args: any[]) {
59 logs.push({
60 level: key,
317
318// The script we run within the worker. Don't reference anything
319// outside of this function as it won't be available within the worker.
320const workerScript = () => {
321 const requests: FetchInfo[] = [];
390 get(target, key) {
391 const real = target[key];
392 if (typeof real === "function" && typeof key === "string") {
393 const fn = function(...args: any[]) {
394 logs.push({
395 level: key,
404 },
405 });
406 async function evaluate(url) {
407 try {
408 const _ = await import(url);
8
9// this script runs client-side
10export const reloadOnVals = async function(vals: ValRef[]) {
11 const valVersions = await Promise.all(vals.map(getCurrentValVersionNumber));
12 // console.log("initialValVersions: ", valVersions);
22
23// experimental - don't use this
24export function reloadOnSaveHonoMiddleware(vals: ValRef[] = [rootValRef()]): MiddlewareHandler {
25 return async function(c, next) {
26 await next();
27 // don't reload on custom domains, only reload on val.run URLs
40 * @param vals to watch
41 */
42export function reloadOnSaveFetchMiddleware(
43 handler: (req: Request) => Response | Promise<Response>,
44 vals = [rootValRef()],