@ydant/async 0.1.0 → 0.1.1

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 (2) hide show
  1. package/README.md +26 -16
  2. package/package.json +3 -3
package/README.md CHANGED
@@ -13,7 +13,8 @@ pnpm add @ydant/async
13
13
  ### Suspense
14
14
 
15
15
  ```typescript
16
- import { div, text, type Component } from "@ydant/core";
16
+ import { type Component } from "@ydant/core";
17
+ import { div, text } from "@ydant/base";
17
18
  import { Suspense, createResource } from "@ydant/async";
18
19
 
19
20
  // Create async resource
@@ -30,7 +31,7 @@ const UserProfile: Component = () =>
30
31
  const App: Component = () =>
31
32
  Suspense({
32
33
  fallback: () => text("Loading..."),
33
- children: UserProfile,
34
+ children: () => UserProfile(),
34
35
  });
35
36
  ```
36
37
 
@@ -41,7 +42,7 @@ import { ErrorBoundary } from "@ydant/async";
41
42
 
42
43
  const App: Component = () =>
43
44
  ErrorBoundary({
44
- fallback: (error) => text(`Error: ${error.message}`),
45
+ fallback: (error, reset) => text(`Error: ${error.message}`),
45
46
  children: () => RiskyComponent(),
46
47
  });
47
48
  ```
@@ -51,11 +52,11 @@ const App: Component = () =>
51
52
  ```typescript
52
53
  const App: Component = () =>
53
54
  ErrorBoundary({
54
- fallback: (error) => text(`Error: ${error.message}`),
55
+ fallback: (error, reset) => text(`Error: ${error.message}`),
55
56
  children: () =>
56
57
  Suspense({
57
58
  fallback: () => text("Loading..."),
58
- children: AsyncContent,
59
+ children: () => AsyncContent(),
59
60
  }),
60
61
  });
61
62
  ```
@@ -65,11 +66,11 @@ const App: Component = () =>
65
66
  ### Suspense
66
67
 
67
68
  ```typescript
68
- function Suspense(props: SuspenseProps): ElementGenerator;
69
+ function* Suspense(props: SuspenseProps): Render;
69
70
 
70
71
  interface SuspenseProps {
71
72
  fallback: () => Render;
72
- children: Component;
73
+ children: () => ChildContent;
73
74
  }
74
75
  ```
75
76
 
@@ -78,25 +79,34 @@ Shows fallback while async content is loading.
78
79
  ### ErrorBoundary
79
80
 
80
81
  ```typescript
81
- function ErrorBoundary(props: ErrorBoundaryProps): ElementGenerator;
82
+ function* ErrorBoundary(props: ErrorBoundaryProps): Render;
82
83
 
83
84
  interface ErrorBoundaryProps {
84
- fallback: (error: Error) => Render;
85
- children: () => ElementGenerator;
85
+ fallback: (error: Error, reset: () => void) => Render;
86
+ children: () => ChildContent;
86
87
  }
87
88
  ```
88
89
 
89
- Catches errors in child components and shows fallback.
90
+ Catches errors in child components and shows fallback. The `reset` callback allows retrying.
90
91
 
91
92
  ### createResource
92
93
 
93
94
  ```typescript
94
- function createResource<T>(fetcher: () => Promise<T>): Resource<T>;
95
+ function createResource<T>(
96
+ fetcher: () => Promise<T>,
97
+ options?: {
98
+ initialValue?: T;
99
+ refetchInterval?: number;
100
+ },
101
+ ): Resource<T>;
95
102
 
96
103
  interface Resource<T> {
97
104
  (): T; // Throws promise if pending, error if failed
98
- refetch(): void;
99
- state: "pending" | "ready" | "error";
105
+ peek(): T; // Read without suspend (throws if pending/error)
106
+ readonly loading: boolean;
107
+ readonly error: Error | null;
108
+ refetch(): Promise<void>;
109
+ dispose(): void; // Stop auto-refetch
100
110
  }
101
111
  ```
102
112
 
@@ -104,6 +114,6 @@ Creates a resource that suspends while loading.
104
114
 
105
115
  ## Module Structure
106
116
 
107
- - `suspense.ts` - Suspense component
108
- - `error-boundary.ts` - ErrorBoundary component
117
+ - `Suspense.ts` - Suspense component
118
+ - `ErrorBoundary.ts` - ErrorBoundary component
109
119
  - `resource.ts` - createResource
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ydant/async",
3
- "version": "0.1.0",
3
+ "version": "0.1.1",
4
4
  "description": "Async components (Suspense, ErrorBoundary) for Ydant",
5
5
  "keywords": [
6
6
  "async",
@@ -39,8 +39,8 @@
39
39
  }
40
40
  },
41
41
  "peerDependencies": {
42
- "@ydant/base": "0.1.0",
43
- "@ydant/core": "0.1.0"
42
+ "@ydant/base": "0.1.2",
43
+ "@ydant/core": "0.1.1"
44
44
  },
45
45
  "scripts": {
46
46
  "build": "vite build",