ovr 2.0.1 → 2.0.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,7 +1,7 @@
1
1
  import { type JSX } from "../jsx/index.js";
2
2
  import type { ExtractParams } from "../types/index.js";
3
3
  import type { Middleware, Params } from "./index.js";
4
- type FormProps<P extends Params> = Omit<JSX.IntrinsicElements["form"], "action" | "method"> & (keyof P extends never ? {
4
+ type FormProps<P extends Params> = JSX.IntrinsicElements["form"] & (keyof P extends never ? {
5
5
  params?: never;
6
6
  } : {
7
7
  params: P;
@@ -21,9 +21,9 @@ export class Context {
21
21
  *
22
22
  * @example { slug: "my-post" }
23
23
  */
24
- params = {}; // set after match
24
+ params; // set after match
25
25
  /** The matched `Route` instance. */
26
- route = undefined; // set after match
26
+ route; // set after match
27
27
  /** [MDN Reference](https://developer.mozilla.org/en-US/docs/Web/API/Response/Response#body) */
28
28
  body = null;
29
29
  /** [MDN Reference](https://developer.mozilla.org/en-US/docs/Web/HTTP/Status) */
@@ -1,7 +1,7 @@
1
1
  import { type JSX } from "../jsx/index.js";
2
2
  import type { ExtractParams } from "../types/index.js";
3
3
  import type { Middleware, Params } from "./index.js";
4
- type AnchorProps<P extends Params> = Omit<JSX.IntrinsicElements["a"], "href"> & (keyof P extends never ? {
4
+ type AnchorProps<P extends Params> = JSX.IntrinsicElements["a"] & (keyof P extends never ? {
5
5
  params?: never;
6
6
  } : {
7
7
  params: P;
@@ -264,6 +264,7 @@ type InputAttributes = Attributes<{
264
264
  step: string;
265
265
  type: "button" | "checkbox" | "color" | "date" | "datetime-local" | "email" | "file" | "hidden" | "image" | "month" | "number" | "password" | "radio" | "range" | "reset" | "search" | "submit" | "tel" | "text" | "time" | "url" | "week";
266
266
  value: string;
267
+ webkitdirectory: boolean;
267
268
  width: string;
268
269
  }, never>;
269
270
  type InsAttributes = Attributes<{
package/dist/jsx/index.js CHANGED
@@ -1,4 +1,6 @@
1
+ import { isGenerator } from "./is-generator.js";
1
2
  import { merge } from "./merge-async-iterables.js";
3
+ import { YieldController } from "./yield-controller.js";
2
4
  // https://developer.mozilla.org/en-US/docs/Glossary/Void_element#self-closing_tags
3
5
  const voidElements = new Set([
4
6
  "area",
@@ -15,6 +17,7 @@ const voidElements = new Set([
15
17
  "track",
16
18
  "wbr",
17
19
  ]);
20
+ const yieldController = new YieldController();
18
21
  /**
19
22
  * The main function of the JSX transform cycle, each time JSX is encountered
20
23
  * it is passed into this function to be resolved.
@@ -82,15 +85,23 @@ export async function* toGenerator(element) {
82
85
  yield* toGenerator(children);
83
86
  }
84
87
  else if (Symbol.iterator in element) {
88
+ if (isGenerator(element)) {
89
+ // process lazily - avoid loading all in memory
90
+ for (const children of element)
91
+ yield* toGenerator(children);
92
+ }
85
93
  const generators = [];
86
94
  for (const children of element) {
87
- // this is where to escape string children if added in the future
88
95
  generators.push(toGenerator(children));
89
96
  }
90
97
  let queue = new Array(generators.length).fill("");
91
98
  const complete = new Set();
92
99
  let current = 0;
93
100
  for await (const { index, result } of merge(generators)) {
101
+ const maybeYield = yieldController.maybeYield();
102
+ // yield control back to event loop to stream current
103
+ if (maybeYield instanceof Promise)
104
+ await maybeYield;
94
105
  if (result.done) {
95
106
  complete.add(index);
96
107
  if (index === current) {
@@ -0,0 +1 @@
1
+ export declare const isGenerator: <T, R = unknown, N = unknown>(iterable: Iterable<T, R, N>) => iterable is Generator<T, R, N>;
@@ -0,0 +1,7 @@
1
+ export const isGenerator = (iterable) => {
2
+ const iterator = iterable[Symbol.iterator]();
3
+ return (iterable != null &&
4
+ typeof iterator.next === "function" &&
5
+ typeof iterator.throw === "function" &&
6
+ typeof iterator.return === "function");
7
+ };
@@ -0,0 +1,4 @@
1
+ export declare class YieldController {
2
+ count: number;
3
+ maybeYield(): Promise<unknown> | undefined;
4
+ }
@@ -0,0 +1,8 @@
1
+ export class YieldController {
2
+ count = 0;
3
+ maybeYield() {
4
+ if (++this.count % 50 === 0) {
5
+ return new Promise((res) => setImmediate(res));
6
+ }
7
+ }
8
+ }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "ovr",
3
3
  "description": "Progressive HTML Rendering",
4
- "version": "2.0.1",
4
+ "version": "2.0.3",
5
5
  "license": "MIT",
6
6
  "repository": {
7
7
  "type": "git",