{"id":50948731,"url":"https://github.com/hyperpuncher/datastar-electron","last_synced_at":"2026-06-17T23:03:43.688Z","repository":{"id":358222391,"uuid":"1240501673","full_name":"hyperpuncher/datastar-electron","owner":"hyperpuncher","description":"Datastar + Electron. Replace IPC with HTTP.","archived":false,"fork":false,"pushed_at":"2026-05-16T09:48:58.000Z","size":12,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2026-05-16T11:28:55.588Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/hyperpuncher.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2026-05-16T07:55:02.000Z","updated_at":"2026-05-16T09:49:02.000Z","dependencies_parsed_at":null,"dependency_job_id":null,"html_url":"https://github.com/hyperpuncher/datastar-electron","commit_stats":null,"previous_names":["hyperpuncher/datastar-electron"],"tags_count":null,"template":false,"template_full_name":null,"purl":"pkg:github/hyperpuncher/datastar-electron","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hyperpuncher%2Fdatastar-electron","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hyperpuncher%2Fdatastar-electron/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hyperpuncher%2Fdatastar-electron/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hyperpuncher%2Fdatastar-electron/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/hyperpuncher","download_url":"https://codeload.github.com/hyperpuncher/datastar-electron/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hyperpuncher%2Fdatastar-electron/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":34468766,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-26T15:22:16.424Z","status":"online","status_checked_at":"2026-06-17T02:00:05.408Z","response_time":127,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2026-06-17T23:03:43.052Z","updated_at":"2026-06-17T23:03:43.683Z","avatar_url":"https://github.com/hyperpuncher.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# datastar-electron\n\nDatastar + Electron. No IPC, no server, just HTTP.\n\nInspired by [ssr-electron](https://github.com/StreamUI/ssr-electron) by Jordan Howlett.\n\n## How it works\n\nElectron intercepts `http://` requests from the renderer. Your handler returns a Response. That's it.\n\n```\ndata-on:click=\"@post('/increment')\"    ← Datastar in browser\n         ↓\nfetch('http://localhost/increment')    ← Electron intercepts (no network)\n         ↓\nyour handler(request)                  ← Your code\n         ↓\nDS.stream(...) → Response              ← Official SDK formats SSE\n         ↓\nDatastar patches signals into DOM      ← Browser updates reactively\n```\n\n## Install\n\n```bash\nnpm i datastar-electron\npnpm i datastar-electron\nbun i datastar-electron\n```\n\n## Quick start\n\n```typescript\nimport { app, BrowserWindow } from \"electron\";\nimport { createRouter, ServerSentEventGenerator as DS } from \"datastar-electron\";\n\nconst router = createRouter({ debug: true });\n\napp.whenReady().then(() =\u003e {\n\t// Serve HTML\n\trouter.registerRoute(\"/\", () =\u003e {\n\t\treturn new Response(\n\t\t\t`\u003c!DOCTYPE html\u003e\n\u003chtml\u003e\n\u003cbody data-signals=\"{count: 0}\"\u003e\n\t\u003ch1\u003eCount: \u003cspan data-text=\"$count\"\u003e0\u003c/span\u003e\u003c/h1\u003e\n\t\u003cbutton data-on:click=\"@post('/increment')\" data-indicator=\"loading\"\u003e\n\t\t\u003cspan data-show=\"$loading\"\u003eLoading...\u003c/span\u003e\n\t\tIncrement\n\t\u003c/button\u003e\n\t\u003cscript type=\"module\" src=\"https://cdn.jsdelivr.net/gh/starfederation/datastar@v1.0.1/bundles/datastar.js\"\u003e\u003c/script\u003e\n\u003c/body\u003e\n\u003c/html\u003e`,\n\t\t\t{ headers: { \"Content-Type\": \"text/html\" } },\n\t\t);\n\t});\n\n\t// Handle clicks with SSE\n\tlet count = 0;\n\trouter.registerRoute(\n\t\t\"/increment\",\n\t\t() =\u003e\n\t\t\tDS.stream(async (stream) =\u003e {\n\t\t\t\tstream.patchSignals(JSON.stringify({ count: ++count }));\n\t\t\t}),\n\t\t\"POST\",\n\t);\n\n\tconst win = new BrowserWindow({ width: 800, height: 600 });\n\twin.loadURL(\"http://localhost/\");\n});\n```\n\n## API\n\n### `createRouter(options?)`\n\nCreates the protocol handler. Auto-registers on app ready.\n\n```typescript\nconst router = createRouter({ debug: true });\n```\n\n### `router.registerRoute(path, handler, method?)`\n\nRegister a route. Supports `:params`.\n\n```typescript\nrouter.registerRoute(\"/api/data\", (req) =\u003e new Response(JSON.stringify({ ok: true })));\n\n// With params\nrouter.registerRoute(\n\t\"/toggle/:id\",\n\t(req) =\u003e {\n\t\tconst id = new URL(req.url).pathname.split(\"/\").pop();\n\t\t// ...\n\t},\n\t\"POST\",\n);\n```\n\n### `DS.stream(callback, options?)`\n\nReturns an SSE Response. From the official Datastar SDK.\n\n```typescript\nimport { ServerSentEventGenerator as DS } from \"datastar-electron\";\n\n// One-shot (auto-closes)\nreturn DS.stream(async (stream) =\u003e {\n\tstream.patchSignals('{\"count\": 42}');\n\tstream.patchElements(\"\u003cdiv\u003eUpdated\u003c/div\u003e\", { selector: \"#msg\" });\n});\n\n// Long-lived (stays open)\nreturn DS.stream(\n\tasync (stream) =\u003e {\n\t\twhile (true) {\n\t\t\tstream.patchSignals(\n\t\t\t\tJSON.stringify({ time: new Date().toLocaleTimeString() }),\n\t\t\t);\n\t\t\tawait new Promise((r) =\u003e setTimeout(r, 1000));\n\t\t}\n\t},\n\t{ keepalive: true },\n);\n```\n\n## License\n\nMIT\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhyperpuncher%2Fdatastar-electron","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fhyperpuncher%2Fdatastar-electron","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhyperpuncher%2Fdatastar-electron/lists"}