@askrjs/askr 0.0.1 → 0.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.
Files changed (52) hide show
  1. package/README.md +18 -10
  2. package/dist/chunk-2ONGHQ7Z.js +3115 -0
  3. package/dist/chunk-2ONGHQ7Z.js.map +1 -0
  4. package/dist/{chunk-UUM5W2RM.js → chunk-H3NSVHA7.js} +2 -6
  5. package/dist/chunk-H3NSVHA7.js.map +1 -0
  6. package/dist/chunk-JHOGWTAW.js +16 -0
  7. package/dist/chunk-JHOGWTAW.js.map +1 -0
  8. package/dist/chunk-OFW6DFBM.js +716 -0
  9. package/dist/chunk-OFW6DFBM.js.map +1 -0
  10. package/dist/chunk-SALJX5PZ.js +26 -0
  11. package/dist/chunk-SALJX5PZ.js.map +1 -0
  12. package/dist/index.cjs +2785 -2327
  13. package/dist/index.cjs.map +1 -1
  14. package/dist/index.d.cts +100 -45
  15. package/dist/index.d.ts +100 -45
  16. package/dist/index.js +430 -84
  17. package/dist/index.js.map +1 -1
  18. package/dist/jsx/jsx-dev-runtime.cjs +9 -3
  19. package/dist/jsx/jsx-dev-runtime.cjs.map +1 -1
  20. package/dist/jsx/jsx-dev-runtime.d.cts +4 -9
  21. package/dist/jsx/jsx-dev-runtime.d.ts +4 -9
  22. package/dist/jsx/jsx-dev-runtime.js +7 -4
  23. package/dist/jsx/jsx-dev-runtime.js.map +1 -1
  24. package/dist/jsx/jsx-runtime.cjs +14 -5
  25. package/dist/jsx/jsx-runtime.cjs.map +1 -1
  26. package/dist/jsx/jsx-runtime.d.cts +9 -6
  27. package/dist/jsx/jsx-runtime.d.ts +9 -6
  28. package/dist/jsx/jsx-runtime.js +6 -4
  29. package/dist/{navigate-NLQOZQGM.js → navigate-CZEUXFPM.js} +5 -5
  30. package/dist/{route-TVYWYCEJ.js → route-USEXGOBT.js} +4 -4
  31. package/dist/{ssr-4ELUFK65.js → ssr-QJ5NTQR6.js} +9 -5
  32. package/dist/{types-DUDmnzD8.d.cts → types-DLTViI21.d.cts} +15 -3
  33. package/dist/{types-DUDmnzD8.d.ts → types-DLTViI21.d.ts} +15 -3
  34. package/package.json +7 -4
  35. package/src/jsx/index.ts +4 -0
  36. package/src/jsx/jsx-dev-runtime.ts +7 -10
  37. package/src/jsx/jsx-runtime.ts +23 -11
  38. package/src/jsx/types.ts +22 -3
  39. package/src/jsx/utils.ts +19 -0
  40. package/dist/chunk-4CV4JOE5.js +0 -27
  41. package/dist/chunk-HIWJVOS4.js +0 -503
  42. package/dist/chunk-HIWJVOS4.js.map +0 -1
  43. package/dist/chunk-L7RL4LYV.js +0 -3442
  44. package/dist/chunk-L7RL4LYV.js.map +0 -1
  45. package/dist/chunk-UUM5W2RM.js.map +0 -1
  46. package/dist/chunk-YNH3D4KW.js +0 -29
  47. package/dist/chunk-YNH3D4KW.js.map +0 -1
  48. package/dist/ssr-4ELUFK65.js.map +0 -1
  49. package/src/jsx/react-jsx-runtime.d.ts +0 -0
  50. /package/dist/{chunk-4CV4JOE5.js.map → navigate-CZEUXFPM.js.map} +0 -0
  51. /package/dist/{navigate-NLQOZQGM.js.map → route-USEXGOBT.js.map} +0 -0
  52. /package/dist/{route-TVYWYCEJ.js.map → ssr-QJ5NTQR6.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(count() + 1)}>Increment</button>
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
- When work becomes stale (unmount, route replacement), the runtime aborts an `AbortController`.
128
- You forward the provided `signal` into normal APIs:
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
- route('/user/{id}', async (params, ctx) => {
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