@askrjs/askr 0.0.1 → 0.0.2
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.
- package/README.md +18 -10
- package/dist/chunk-KR6HG7HF.js +38 -0
- package/dist/chunk-KR6HG7HF.js.map +1 -0
- package/dist/{chunk-L7RL4LYV.js → chunk-MIPES65F.js} +1486 -1905
- package/dist/chunk-MIPES65F.js.map +1 -0
- package/dist/{chunk-HIWJVOS4.js → chunk-PFOLLB6A.js} +38 -17
- package/dist/chunk-PFOLLB6A.js.map +1 -0
- package/dist/chunk-QECQ2TF6.js +28 -0
- package/dist/chunk-QECQ2TF6.js.map +1 -0
- package/dist/{chunk-UUM5W2RM.js → chunk-RJWOOUYV.js} +2 -2
- package/dist/chunk-RJWOOUYV.js.map +1 -0
- package/dist/index.cjs +1760 -1972
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +52 -40
- package/dist/index.d.ts +52 -40
- package/dist/index.js +226 -52
- package/dist/index.js.map +1 -1
- package/dist/jsx/jsx-dev-runtime.cjs +9 -3
- package/dist/jsx/jsx-dev-runtime.cjs.map +1 -1
- package/dist/jsx/jsx-dev-runtime.d.cts +4 -9
- package/dist/jsx/jsx-dev-runtime.d.ts +4 -9
- package/dist/jsx/jsx-dev-runtime.js +10 -4
- package/dist/jsx/jsx-dev-runtime.js.map +1 -1
- package/dist/jsx/jsx-runtime.cjs +14 -5
- package/dist/jsx/jsx-runtime.cjs.map +1 -1
- package/dist/jsx/jsx-runtime.d.cts +9 -6
- package/dist/jsx/jsx-runtime.d.ts +9 -6
- package/dist/jsx/jsx-runtime.js +6 -2
- package/dist/{navigate-NLQOZQGM.js → navigate-SDZNA2ZE.js} +5 -5
- package/dist/{route-TVYWYCEJ.js → route-P5YQBT4T.js} +4 -4
- package/dist/{ssr-4ELUFK65.js → ssr-65K3IJ6B.js} +9 -5
- package/dist/{types-DUDmnzD8.d.cts → types-DLTViI21.d.cts} +15 -3
- package/dist/{types-DUDmnzD8.d.ts → types-DLTViI21.d.ts} +15 -3
- package/package.json +5 -3
- package/src/jsx/index.ts +4 -0
- package/src/jsx/jsx-dev-runtime.ts +7 -10
- package/src/jsx/jsx-runtime.ts +23 -11
- package/src/jsx/types.ts +22 -3
- package/src/jsx/utils.ts +19 -0
- package/dist/chunk-4CV4JOE5.js +0 -27
- package/dist/chunk-HIWJVOS4.js.map +0 -1
- package/dist/chunk-L7RL4LYV.js.map +0 -1
- package/dist/chunk-UUM5W2RM.js.map +0 -1
- package/dist/chunk-YNH3D4KW.js +0 -29
- package/dist/chunk-YNH3D4KW.js.map +0 -1
- package/dist/ssr-4ELUFK65.js.map +0 -1
- package/src/jsx/react-jsx-runtime.d.ts +0 -0
- /package/dist/{chunk-4CV4JOE5.js.map → navigate-SDZNA2ZE.js.map} +0 -0
- /package/dist/{navigate-NLQOZQGM.js.map → route-P5YQBT4T.js.map} +0 -0
- /package/dist/{route-TVYWYCEJ.js.map → ssr-65K3IJ6B.js.map} +0 -0
package/README.md
CHANGED
|
@@ -57,7 +57,7 @@ function Home() {
|
|
|
57
57
|
<div>
|
|
58
58
|
<h1>Home</h1>
|
|
59
59
|
<p>Count: {count()}</p>
|
|
60
|
-
<button onClick={() => count.set(
|
|
60
|
+
<button onClick={() => count.set(prev => prev + 1)}>Increment</button>
|
|
61
61
|
<p>
|
|
62
62
|
<Link href="/users/42">User 42</Link>
|
|
63
63
|
</p>
|
|
@@ -65,6 +65,9 @@ function Home() {
|
|
|
65
65
|
);
|
|
66
66
|
}
|
|
67
67
|
|
|
68
|
+
|
|
69
|
+
**Tip:** Prefer functional updates when updating based on previous state: `count.set(prev => prev + 1)`.
|
|
70
|
+
|
|
68
71
|
function User({ id }: { id: string }) {
|
|
69
72
|
return (
|
|
70
73
|
<div>
|
|
@@ -123,19 +126,24 @@ We believe the best frameworks are the ones you stop thinking about.
|
|
|
123
126
|
|
|
124
127
|
## Cancellation is not a feature
|
|
125
128
|
|
|
126
|
-
Askr doesn’t introduce a new cancellation concept.
|
|
127
|
-
|
|
128
|
-
|
|
129
|
+
Askr doesn’t introduce a new cancellation concept. When work becomes stale (unmount, route replacement), the runtime aborts an `AbortController` and you should forward a cancellable `signal` into normal APIs. **Important:** route handlers are executed synchronously during navigation and must return a VNode — they must not be `async` functions that return a Promise. For async data use runtime helpers like `resource()` or perform async work inside component mount operations and use `getSignal()` for cancellation.
|
|
130
|
+
|
|
131
|
+
Example (recommended pattern):
|
|
129
132
|
|
|
130
133
|
```ts
|
|
131
|
-
import { route } from '@askrjs/askr';
|
|
134
|
+
import { route, resource, getSignal } from '@askrjs/askr';
|
|
135
|
+
|
|
136
|
+
function User({ id }: { id: string }) {
|
|
137
|
+
const user = resource(async () => {
|
|
138
|
+
const res = await fetch(`/api/users/${id}`, { signal: getSignal() });
|
|
139
|
+
return res.json();
|
|
140
|
+
}, [id]);
|
|
132
141
|
|
|
133
|
-
|
|
134
|
-
const user = await fetch(`/api/users/${params.id}`, {
|
|
135
|
-
signal: ctx?.signal,
|
|
136
|
-
}).then((r) => r.json());
|
|
142
|
+
if (!user) return <div>Loading...</div>;
|
|
137
143
|
return <pre>{JSON.stringify(user, null, 2)}</pre>;
|
|
138
|
-
}
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
route('/user/{id}', ({ id }) => <User id={id} />);
|
|
139
147
|
```
|
|
140
148
|
|
|
141
149
|
## Principles
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import {
|
|
2
|
+
__esm,
|
|
3
|
+
init_types
|
|
4
|
+
} from "./chunk-QECQ2TF6.js";
|
|
5
|
+
|
|
6
|
+
// src/jsx/jsx-runtime.ts
|
|
7
|
+
function jsxDEV(type, props, key) {
|
|
8
|
+
return {
|
|
9
|
+
$$typeof: ELEMENT_TYPE,
|
|
10
|
+
type,
|
|
11
|
+
props: props ?? {},
|
|
12
|
+
key: key ?? null
|
|
13
|
+
};
|
|
14
|
+
}
|
|
15
|
+
function jsx(type, props, key) {
|
|
16
|
+
return jsxDEV(type, props, key);
|
|
17
|
+
}
|
|
18
|
+
function jsxs(type, props, key) {
|
|
19
|
+
return jsxDEV(type, props, key);
|
|
20
|
+
}
|
|
21
|
+
var ELEMENT_TYPE, Fragment;
|
|
22
|
+
var init_jsx_runtime = __esm({
|
|
23
|
+
"src/jsx/jsx-runtime.ts"() {
|
|
24
|
+
init_types();
|
|
25
|
+
ELEMENT_TYPE = /* @__PURE__ */ Symbol.for("askr.element");
|
|
26
|
+
Fragment = /* @__PURE__ */ Symbol.for("askr.fragment");
|
|
27
|
+
}
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
export {
|
|
31
|
+
ELEMENT_TYPE,
|
|
32
|
+
Fragment,
|
|
33
|
+
jsxDEV,
|
|
34
|
+
jsx,
|
|
35
|
+
jsxs,
|
|
36
|
+
init_jsx_runtime
|
|
37
|
+
};
|
|
38
|
+
//# sourceMappingURL=chunk-KR6HG7HF.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/jsx/jsx-runtime.ts"],"sourcesContent":["/**\n * JSX dev runtime\n * Same shape as production runtime, with room for dev warnings.\n */\n\nimport './types';\n\nexport const ELEMENT_TYPE = Symbol.for('askr.element');\nexport const Fragment = Symbol.for('askr.fragment');\n\nexport interface JSXElement {\n $$typeof: symbol;\n type: unknown;\n props: Record<string, unknown>;\n key: string | number | null;\n}\n\nexport function jsxDEV(\n type: unknown,\n props: Record<string, unknown> | null,\n key?: string | number\n): JSXElement {\n return {\n $$typeof: ELEMENT_TYPE,\n type,\n props: props ?? {},\n key: key ?? null,\n };\n}\n\n// Production-style helpers: alias to the DEV factory for now\nexport function jsx(\n type: unknown,\n props: Record<string, unknown> | null,\n key?: string | number\n) {\n return jsxDEV(type, props, key);\n}\n\nexport function jsxs(\n type: unknown,\n props: Record<string, unknown> | null,\n key?: string | number\n) {\n return jsxDEV(type, props, key);\n}\n\n// `Fragment` is already exported above.\n"],"mappings":";;;;;;AAiBO,SAAS,OACd,MACA,OACA,KACY;AACZ,SAAO;AAAA,IACL,UAAU;AAAA,IACV;AAAA,IACA,OAAO,SAAS,CAAC;AAAA,IACjB,KAAK,OAAO;AAAA,EACd;AACF;AAGO,SAAS,IACd,MACA,OACA,KACA;AACA,SAAO,OAAO,MAAM,OAAO,GAAG;AAChC;AAEO,SAAS,KACd,MACA,OACA,KACA;AACA,SAAO,OAAO,MAAM,OAAO,GAAG;AAChC;AA7CA,IAOa,cACA;AARb;AAAA;AAKA;AAEO,IAAM,eAAe,uBAAO,IAAI,cAAc;AAC9C,IAAM,WAAW,uBAAO,IAAI,eAAe;AAAA;AAAA;","names":[]}
|