@askrjs/askr 0.0.3 → 0.0.5

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 (62) hide show
  1. package/README.md +8 -5
  2. package/dist/fx.d.ts +186 -0
  3. package/dist/fx.js +636 -0
  4. package/dist/fx.js.map +1 -0
  5. package/dist/index.d.ts +74 -407
  6. package/dist/index.js +3706 -779
  7. package/dist/index.js.map +1 -1
  8. package/dist/{types-DLTViI21.d.ts → jsx-AzPM8gMS.d.ts} +6 -21
  9. package/dist/{jsx/jsx-dev-runtime.d.ts → jsx-dev-runtime.d.ts} +3 -2
  10. package/dist/jsx-dev-runtime.js +17 -0
  11. package/dist/jsx-dev-runtime.js.map +1 -0
  12. package/dist/jsx-runtime.d.ts +14 -0
  13. package/dist/{chunk-SALJX5PZ.js → jsx-runtime.js} +6 -9
  14. package/dist/jsx-runtime.js.map +1 -0
  15. package/dist/resources.d.ts +21 -0
  16. package/dist/resources.js +785 -0
  17. package/dist/resources.js.map +1 -0
  18. package/dist/router-DaGtH1Sq.d.ts +36 -0
  19. package/dist/router.d.ts +64 -0
  20. package/dist/{chunk-2ONGHQ7Z.js → router.js} +719 -689
  21. package/dist/router.js.map +1 -0
  22. package/dist/ssr.d.ts +123 -0
  23. package/dist/{index.cjs → ssr.js} +1472 -2737
  24. package/dist/ssr.js.map +1 -0
  25. package/dist/types-uOPfcrdz.d.ts +25 -0
  26. package/dist/vite/index.d.ts +17 -0
  27. package/dist/vite/index.js +2306 -0
  28. package/dist/vite/index.js.map +1 -0
  29. package/package.json +37 -28
  30. package/dist/chunk-2ONGHQ7Z.js.map +0 -1
  31. package/dist/chunk-H3NSVHA7.js +0 -80
  32. package/dist/chunk-H3NSVHA7.js.map +0 -1
  33. package/dist/chunk-JHOGWTAW.js +0 -16
  34. package/dist/chunk-JHOGWTAW.js.map +0 -1
  35. package/dist/chunk-OFW6DFBM.js +0 -716
  36. package/dist/chunk-OFW6DFBM.js.map +0 -1
  37. package/dist/chunk-SALJX5PZ.js.map +0 -1
  38. package/dist/index.cjs.map +0 -1
  39. package/dist/index.d.cts +0 -501
  40. package/dist/jsx/jsx-dev-runtime.cjs +0 -46
  41. package/dist/jsx/jsx-dev-runtime.cjs.map +0 -1
  42. package/dist/jsx/jsx-dev-runtime.d.cts +0 -11
  43. package/dist/jsx/jsx-dev-runtime.js +0 -19
  44. package/dist/jsx/jsx-dev-runtime.js.map +0 -1
  45. package/dist/jsx/jsx-runtime.cjs +0 -54
  46. package/dist/jsx/jsx-runtime.cjs.map +0 -1
  47. package/dist/jsx/jsx-runtime.d.cts +0 -20
  48. package/dist/jsx/jsx-runtime.d.ts +0 -20
  49. package/dist/jsx/jsx-runtime.js +0 -16
  50. package/dist/jsx/jsx-runtime.js.map +0 -1
  51. package/dist/navigate-CZEUXFPM.js +0 -16
  52. package/dist/navigate-CZEUXFPM.js.map +0 -1
  53. package/dist/route-USEXGOBT.js +0 -31
  54. package/dist/route-USEXGOBT.js.map +0 -1
  55. package/dist/ssr-QJ5NTQR6.js +0 -28
  56. package/dist/ssr-QJ5NTQR6.js.map +0 -1
  57. package/dist/types-DLTViI21.d.cts +0 -50
  58. package/src/jsx/index.ts +0 -4
  59. package/src/jsx/jsx-dev-runtime.ts +0 -23
  60. package/src/jsx/jsx-runtime.ts +0 -48
  61. package/src/jsx/types.ts +0 -46
  62. package/src/jsx/utils.ts +0 -19
package/README.md CHANGED
@@ -65,9 +65,12 @@ function Home() {
65
65
  );
66
66
  }
67
67
 
68
+ ```
68
69
 
69
70
  **Tip:** Prefer functional updates when updating based on previous state: `count.set(prev => prev + 1)`.
70
71
 
72
+ ```ts
73
+
71
74
  function User({ id }: { id: string }) {
72
75
  return (
73
76
  <div>
@@ -131,16 +134,16 @@ Askr doesn’t introduce a new cancellation concept. When work becomes stale (un
131
134
  Example (recommended pattern):
132
135
 
133
136
  ```ts
134
- import { route, resource, getSignal } from '@askrjs/askr';
137
+ import { route, resource } from '@askrjs/askr';
135
138
 
136
139
  function User({ id }: { id: string }) {
137
- const user = resource(async () => {
138
- const res = await fetch(`/api/users/${id}`, { signal: getSignal() });
140
+ const user = resource(async ({ signal }) => {
141
+ const res = await fetch(`/api/users/${id}`, { signal });
139
142
  return res.json();
140
143
  }, [id]);
141
144
 
142
- if (!user) return <div>Loading...</div>;
143
- return <pre>{JSON.stringify(user, null, 2)}</pre>;
145
+ if (user.pending) return <div>Loading...</div>;
146
+ return <pre>{JSON.stringify(user.value, null, 2)}</pre>;
144
147
  }
145
148
 
146
149
  route('/user/{id}', ({ id }) => <User id={id} />);
package/dist/fx.d.ts ADDED
@@ -0,0 +1,186 @@
1
+ /**
2
+ * Timing utilities — pure helpers for common async patterns
3
+ * No framework coupling. No lifecycle awareness.
4
+ */
5
+ interface DebounceOptions {
6
+ leading?: boolean;
7
+ trailing?: boolean;
8
+ }
9
+ interface ThrottleOptions {
10
+ leading?: boolean;
11
+ trailing?: boolean;
12
+ }
13
+ interface RetryOptions$1 {
14
+ maxAttempts?: number;
15
+ delayMs?: number;
16
+ backoff?: (attemptIndex: number) => number;
17
+ }
18
+ /**
19
+ * Debounce — delay execution, coalesce rapid calls
20
+ *
21
+ * Useful for: text input, resize, autosave
22
+ *
23
+ * @param fn Function to debounce
24
+ * @param ms Delay in milliseconds
25
+ * @param options trailing (default true), leading
26
+ * @returns Debounced function with cancel() method
27
+ *
28
+ * @example
29
+ * ```ts
30
+ * const save = debounce((text) => api.save(text), 500);
31
+ * input.addEventListener('input', (e) => save(e.target.value));
32
+ * save.cancel(); // stop any pending execution
33
+ * ```
34
+ */
35
+ declare function debounce<T extends (...args: unknown[]) => unknown>(fn: T, ms: number, options?: DebounceOptions): T & {
36
+ cancel(): void;
37
+ };
38
+ /**
39
+ * Throttle — rate-limit execution, keep first/last
40
+ *
41
+ * Useful for: scroll, mouse move, high-frequency events
42
+ *
43
+ * @param fn Function to throttle
44
+ * @param ms Minimum interval between calls in milliseconds
45
+ * @param options leading (default true), trailing (default true)
46
+ * @returns Throttled function with cancel() method
47
+ *
48
+ * @example
49
+ * ```ts
50
+ * const handleScroll = throttle(updateUI, 100);
51
+ * window.addEventListener('scroll', handleScroll);
52
+ * handleScroll.cancel();
53
+ * ```
54
+ */
55
+ declare function throttle<T extends (...args: unknown[]) => unknown>(fn: T, ms: number, options?: ThrottleOptions): T & {
56
+ cancel(): void;
57
+ };
58
+ /**
59
+ * Once — guard against double execution
60
+ *
61
+ * Useful for: init logic, event safety
62
+ *
63
+ * @param fn Function to call at most once
64
+ * @returns Function that executes fn only on first call
65
+ *
66
+ * @example
67
+ * ```ts
68
+ * const init = once(setup);
69
+ * init(); // runs
70
+ * init(); // does nothing
71
+ * init(); // does nothing
72
+ * ```
73
+ */
74
+ declare function once<T extends (...args: unknown[]) => unknown>(fn: T): T;
75
+ /**
76
+ * Defer — schedule on microtask queue
77
+ *
78
+ * Useful for: run-after-current-stack logic
79
+ * More reliable than setTimeout(..., 0)
80
+ *
81
+ * @param fn Function to defer
82
+ *
83
+ * @example
84
+ * ```ts
85
+ * defer(() => update()); // runs after current stack, before next macrotask
86
+ * ```
87
+ */
88
+ declare function defer(fn: () => void): void;
89
+ /**
90
+ * RAF — coalesce multiple updates into single frame
91
+ *
92
+ * Useful for: animation, layout work, render updates
93
+ *
94
+ * @param fn Function to schedule on next animation frame
95
+ * @returns Function that schedules fn on requestAnimationFrame
96
+ *
97
+ * @example
98
+ * ```ts
99
+ * const update = raf(render);
100
+ * update(); // schedules on next frame
101
+ * update(); // same frame, no duplicate
102
+ * ```
103
+ */
104
+ declare function raf<T extends (...args: unknown[]) => unknown>(fn: T): T;
105
+ /**
106
+ * Idle — schedule low-priority work
107
+ *
108
+ * Useful for: background prep, non-urgent updates
109
+ * Falls back to setTimeout if requestIdleCallback unavailable
110
+ *
111
+ * @param fn Function to call when idle
112
+ * @param options timeout for fallback
113
+ *
114
+ * @example
115
+ * ```ts
116
+ * idle(() => prefetchData());
117
+ * ```
118
+ */
119
+ declare function idle(fn: () => void, options?: {
120
+ timeout?: number;
121
+ }): void;
122
+ /**
123
+ * Timeout — Promise-based delay
124
+ *
125
+ * Useful for: readable async code, waiting between retries
126
+ *
127
+ * @param ms Milliseconds to wait
128
+ * @returns Promise that resolves after delay
129
+ *
130
+ * @example
131
+ * ```ts
132
+ * await timeout(300);
133
+ * console.log('300ms later');
134
+ * ```
135
+ */
136
+ declare function timeout(ms: number): Promise<void>;
137
+ /**
138
+ * Retry — attempt function with backoff
139
+ *
140
+ * Useful for: network calls, transient failures
141
+ *
142
+ * @param fn Async function to retry
143
+ * @param options maxAttempts, delayMs, backoff function
144
+ * @returns Promise with final result or error
145
+ *
146
+ * @example
147
+ * ```ts
148
+ * const data = await retry(() => fetch(url), {
149
+ * maxAttempts: 3,
150
+ * delayMs: 100,
151
+ * });
152
+ * ```
153
+ */
154
+ declare function retry<T>(fn: () => Promise<T>, options?: RetryOptions$1): Promise<T>;
155
+
156
+ type CancelFn = () => void;
157
+ declare function debounceEvent(ms: number, handler: EventListener, options?: {
158
+ leading?: boolean;
159
+ trailing?: boolean;
160
+ }): EventListener & {
161
+ cancel(): void;
162
+ flush(): void;
163
+ };
164
+ declare function throttleEvent(ms: number, handler: EventListener, options?: {
165
+ leading?: boolean;
166
+ trailing?: boolean;
167
+ }): EventListener & {
168
+ cancel(): void;
169
+ };
170
+ declare function rafEvent(handler: EventListener): EventListener & {
171
+ cancel(): void;
172
+ };
173
+ declare function scheduleTimeout(ms: number, fn: () => void): CancelFn;
174
+ declare function scheduleIdle(fn: () => void, options?: {
175
+ timeout?: number;
176
+ }): CancelFn;
177
+ interface RetryOptions {
178
+ maxAttempts?: number;
179
+ delayMs?: number;
180
+ backoff?: (attemptIndex: number) => number;
181
+ }
182
+ declare function scheduleRetry<T>(fn: () => Promise<T>, options?: RetryOptions): {
183
+ cancel(): void;
184
+ };
185
+
186
+ export { type DebounceOptions, type RetryOptions$1 as RetryOptions, type ThrottleOptions, debounce, debounceEvent, defer, idle, once, raf, rafEvent, retry, scheduleIdle, scheduleRetry, scheduleTimeout, throttle, throttleEvent, timeout };