feat(lib/progress): streaming and headless nodes #56
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "progress"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
resolves #33.
resolves #47.
resolves #40.
should try #34
this PR reworks log and progress, and adds many more treats to make that a reality.
for a general intro on what progress is, check out it's documentation comment
https://git.paperclover.net/clo/sitegen/src/commit/progress/lib/progress.ts#L1
description contained within commit messages
WIP: pls extract the other stuff into own commits node signaling is done by providing a `progress.Root` to every node, dispatching events to it when the node changes. the root is connected to an observer to construct a UI out of it. this commit adds two built in observers: `attachToScreen` binds a root to a TTY screen (via the log.Widget API). the primary use of this is to implement the top level `progress.start`. `encodeStream` converts these events into a `ReadableStream`. by batching events together, the stream contents remain small, that way the code that constructs progress nodes do not have to worry about calling many setters at once, it gets debounced be the serializer. a server may: const root = new progress.Root(); doActionWithProgress(root satisfies progress.Ref) .then( (result) => root.end({ success: true, result }), (error) => root.end({ success: false, error }) ); if (req.headers.get("Accept").includes(progress.contentType)) return new Response(progress.encodeStream(root), { headers: { 'Content-Type': progress.contentType }, }); // to support non-streaming clients const result = await root.once("end"); return result.success ? ... : ...; and `decodeStream` on the client: const output = document.getElementById("output"); const res = await fetch(...); if (!res.ok) throw ...; const root = progress.decodeStream(res.body); output.innerHTML = progress.formatHtml(root.active); root.on("change", () => { output.innerHTML = progress.formatHtml(root.active); }); const result = await root.once("end"); output.innerText = JSON.stringify(result); this feature is something that my work is interested in using. while `progress.ts` will not be the home of a React hook -- it's trivial to implement the library overall gains extra features: - a typed event emitter (`Events.ts`) compatible with the browser - cancelable promises in `async.ts` - more type helpers in `ts.ts`22117eb74dtod9ea7b59e2d9ea7b59e2tob9ea8d17b4WIP: feat(lib/progress): implement streaming and headless nodesto WIP: feat(lib/progress): streaming and headless nodesb9ea8d17b4tob6c06ac082b6c06ac082to499919bf30499919bf30to8ea7ee1a9a8ea7ee1a9atod16f542723WIP: feat(lib/progress): streaming and headless nodesto feat(lib/progress): streaming and headless nodesd16f542723to3782c6c124blockers
@ -6,3 +5,1 @@* // Extra types are in a `declare namespace`* const opts: Lru.Options = { capacity: 2 };* const lru = new Lru(opts);* ``````ts
@ -405,0 +1328,4 @@estimatedTimeNonNull: boolean;futureProofingPacket: boolean;unhandled
@ -4,20 +4,47 @@### breakingensure up to date
@ -201,13 +201,16 @@ export function mergeStyles(code: string): string {* turned into their original names.*/export function debugAnsi(text: string): string {// return JSON.stringify(text);delete this
3782c6c124to63ef745f16