Skip to content

Instantly share code, notes, and snippets.

View jacob-ebey's full-sized avatar

Jacob Ebey jacob-ebey

View GitHub Profile
@jacob-ebey
jacob-ebey / n-bottles.neva
Last active January 13, 2025 08:15
Neva n-bottles (99 bottles with input)
import { fmt, strconv, strings }
def Main(start any) (stop any) {
print For<int>{Next2Lines}
wait Wait
readInt ReadInt
range Range
printErr fmt.Println
---
// Notify the range and readInt actions to start
type OptionsOrString<TOptions extends string> = (string & {}) | TOptions
type ElementOrArray<T> = T | T[]
interface PromptGenerationConsole {
log(...data: any[]): void
warn(...data: any[]): void
debug(...data: any[]): void
error(...data: any[]): void
}
@jacob-ebey
jacob-ebey / use-transition-on-value-change.ts
Last active February 3, 2025 13:25
useTransitonOnValueChange
import { useEffect, useRef } from "react";
export function useTransitonOnValueChange(value: unknown) {
if (!document.startViewTransition) return;
const lastValueRef = useRef(value);
const deferredRef = useRef<Deferred<void> | null>(null);
const viewTransitionRef = useRef<ViewTransition | null>(null);
if (lastValueRef.current !== value) {
@jacob-ebey
jacob-ebey / rsc-bundler-integration-api.md
Created October 14, 2024 18:14
React RFC: RSC Bundler Integration API

React RFC: RSC Bundler Integration API

Summary

We are interested in building a react-server integration for Remix (and Vite). We've noticed a coupling between the React internals and the bundler API, and we’d like to propose a few small changes that would invert control to provide hooks that can be used by any flight runtime. As a result, all `react-server-dom-*` runtimes should be able to implement the touchpoints in a concise manner allowing the individual packages to focus on what to serialize for references, and how to deserialize/load references.

Background

Today, each individual `react-server-dom-*` package (`react-server-dom-webpack`, `react-server-dom-turbopack`, etc.) essentially concatenates shared runtime modules with the entry points for that package. Each package implements a few functions that are opaquely called in the shared runtime source, including `resolveClientReferenceMetadata`, `resolveServerReference`, `preloadModule`, `requireModule`, etc.

@jacob-ebey
jacob-ebey / chat-app-element.ts
Created October 12, 2024 05:22
Micro HTMX Streaming Chat App
customElements.define(
"chat-app",
class extends HTMLElement {
connectedCallback() {
if (!this.isConnected) return;
const form = window.querySelectorExt(
this,
"find form",
) as HTMLFormElement;
@jacob-ebey
jacob-ebey / worker.ts
Created June 20, 2024 21:27
Workerd Durable Object Vite Proxy POC
import { DurableObject } from "cloudflare:workers";
class TestDO extends DurableObject {
exp: string;
constructor(ctx: DurableObjectState, env: any) {
super(ctx, env);
this.exp = "exp";
}
sayHello() {
return "Hello, " + this.exp + "!";
@jacob-ebey
jacob-ebey / federated-rsc-stream
Last active January 9, 2024 18:48
example-federated-rsc-stream
1:I["rsc/remote/client/_example_consumer:./__/__/framework/dist/framework.client.js#OutletProvider",["rsc/remote/client/_example_consumer:./__/__/framework/dist/framework.client.js#OutletProvider"],"OutletProvider"]
2:I["rsc/remote/client/_example_consumer:./app/components/counter.tsx#Counter",["rsc/remote/client/_example_consumer:./app/components/counter.tsx#Counter"],"Counter"]
5:I["rsc/remote/client/_example_consumer:./__/__/framework/dist/framework.client.js#Outlet",["rsc/remote/client/_example_consumer:./__/__/framework/dist/framework.client.js#Outlet"],"Outlet"]
0:["$","$L1",null,{"outlets":{"_example_consumer/_public._index":[["$","h1",null,{"children":"Hello Index"}],["$","$L2",null,{}],["$","div",null,{"style":{"backgroundColor":"red","color":"black","padding":"1rem"},"children":"$L3"}]],"_example_consumer/_public":"$L4"},"children":["$","$L5","_example_consumer/_public",{"id":"_example_consumer/_public"}]}]
6:I["rsc/remote/client/_example_consumer:./__/__/framework/dist/framework.client.js#StreamRea
@jacob-ebey
jacob-ebey / routes.test.ts
Last active December 4, 2023 09:39
Assemble react-router routes from Vite `import.meta.glob`
import { describe, it, expect } from "vitest";
import { routesFromGlob, type RoutesFromGlob } from "./routes";
describe("routesFromGlob", () => {
it("correctly transforms routes", () => {
let routes = {
"./routes/_index/route.tsx": () => "Index Route",
"./routes/single/route.tsx": () => "Single Route",
"./routes/$param/route.tsx": () => "Param Route",
@jacob-ebey
jacob-ebey / example.tsx
Last active December 4, 2023 09:13
vite-react-router-remix-glob-routes
import { createBrowserRouter, RouterProvider } from "react-router-dom";
import { globRoutes } from "@/lib/routes";
const router = createBrowserRouter(
globRoutes(import.meta.glob("./routes/**/route.tsx"))
);
function App() {
return <RouterProvider router={router} />;
@jacob-ebey
jacob-ebey / toggle.jsx
Created October 27, 2023 16:05 — forked from AndrewIngram/toggle.jsx
Naive sketch of mutation API
function getIsLiked(viewerId, entityId) {
// hit a database or something
}
function toggleLikeStatus(viewerId, entityId) {
// hit a database or something
return !currentStatus;
}