round-core 0.1.2 → 0.1.4
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 +68 -18
- package/package.json +13 -8
- package/src/cli.js +609 -0
- package/src/compiler/index.js +2 -0
- package/src/compiler/transformer.js +610 -0
- package/src/compiler/vite-plugin.d.ts +8 -0
- package/src/compiler/vite-plugin.js +472 -0
- package/{dist → src}/index.d.ts +86 -19
- package/src/index.js +34 -0
- package/src/runtime/context-shared.js +63 -0
- package/src/runtime/context.js +70 -0
- package/src/runtime/dom.js +402 -0
- package/src/runtime/error-boundary.js +48 -0
- package/src/runtime/error-reporter.js +21 -0
- package/src/runtime/error-store.js +85 -0
- package/src/runtime/errors.js +152 -0
- package/src/runtime/lifecycle.js +140 -0
- package/src/runtime/router.js +475 -0
- package/src/runtime/signals.js +577 -0
- package/src/runtime/store.js +215 -0
- package/src/runtime/suspense.js +128 -0
- package/dist/cli.js +0 -607
- package/dist/index.js +0 -2071
- package/dist/vite-plugin.js +0 -883
package/README.md
CHANGED
|
@@ -73,9 +73,19 @@ A **signal** is a small reactive container.
|
|
|
73
73
|
Round includes a CLI with a project initializer.
|
|
74
74
|
|
|
75
75
|
```bash
|
|
76
|
+
# Install the CLI
|
|
77
|
+
npm install round
|
|
78
|
+
|
|
79
|
+
# Create a new app
|
|
76
80
|
round init myapp
|
|
81
|
+
|
|
82
|
+
# Navigate to the app directory
|
|
77
83
|
cd myapp
|
|
84
|
+
|
|
85
|
+
# Install dependencies
|
|
78
86
|
npm install
|
|
87
|
+
|
|
88
|
+
# Run the app
|
|
79
89
|
npm run dev
|
|
80
90
|
```
|
|
81
91
|
|
|
@@ -163,6 +173,39 @@ effect(() => {
|
|
|
163
173
|
name('Grace');
|
|
164
174
|
```
|
|
165
175
|
|
|
176
|
+
### `asyncSignal(fetcher)`
|
|
177
|
+
|
|
178
|
+
Create a signal that manages asynchronous data fetching.
|
|
179
|
+
|
|
180
|
+
- It returns a signal that resolves to the data once fetched.
|
|
181
|
+
- **`.pending`**: A reactive signal (boolean) indicating if the fetch is in progress.
|
|
182
|
+
- **`.error`**: A reactive signal containing any error that occurred during fetching.
|
|
183
|
+
- **`.refetch()`**: A method to manually trigger a re-fetch.
|
|
184
|
+
|
|
185
|
+
```jsx
|
|
186
|
+
import { asyncSignal } from 'round-core';
|
|
187
|
+
|
|
188
|
+
const user = asyncSignal(async () => {
|
|
189
|
+
const res = await fetch('/api/user');
|
|
190
|
+
return res.json();
|
|
191
|
+
});
|
|
192
|
+
|
|
193
|
+
export function UserProfile() {
|
|
194
|
+
return (
|
|
195
|
+
<div>
|
|
196
|
+
{if(user.pending()){
|
|
197
|
+
<div>Loading...</div>
|
|
198
|
+
} else if(user.error()){
|
|
199
|
+
<div>Error: {user.error().message}</div>
|
|
200
|
+
} else {
|
|
201
|
+
<div>Welcome, {user().name}</div>
|
|
202
|
+
}}
|
|
203
|
+
<button onClick={() => user.refetch()}>Reload</button>
|
|
204
|
+
</div>
|
|
205
|
+
);
|
|
206
|
+
}
|
|
207
|
+
```
|
|
208
|
+
|
|
166
209
|
### `untrack(fn)`
|
|
167
210
|
|
|
168
211
|
Run a function without tracking any signals it reads.
|
|
@@ -385,6 +428,25 @@ Notes:
|
|
|
385
428
|
- The `switch` expression is automatically wrapped in a reactive tracker, ensuring that the view updates surgically when the condition (e.g., a signal) changes.
|
|
386
429
|
- Each case handles its own rendering without re-running the parent component.
|
|
387
430
|
|
|
431
|
+
### `try / catch`
|
|
432
|
+
|
|
433
|
+
Round supports both static and **reactive** `try/catch` blocks inside JSX.
|
|
434
|
+
|
|
435
|
+
- **Static**: Just like standard JS, but renders fragments.
|
|
436
|
+
- **Reactive**: By passing a signal to `try(signal)`, the block will **automatically re-run** if the signal (or its dependencies) update. This is perfect for handling transient errors in async data.
|
|
437
|
+
|
|
438
|
+
```jsx
|
|
439
|
+
{try(user()) {
|
|
440
|
+
{if(user() && user().name) {
|
|
441
|
+
<div>Hello {user().name}</div>
|
|
442
|
+
} else if(user.pending()) {
|
|
443
|
+
<div>⏳ Loading...</div>
|
|
444
|
+
}}
|
|
445
|
+
} catch(e) {
|
|
446
|
+
<div className="error"> Failed to load user: {e.message} </div>
|
|
447
|
+
}}
|
|
448
|
+
```
|
|
449
|
+
|
|
388
450
|
## Routing
|
|
389
451
|
|
|
390
452
|
Round includes router primitives intended for SPA navigation. All route paths must start with a forward slash `/`.
|
|
@@ -452,26 +514,14 @@ const LazyWidget = lazy(() => import('./Widget'));
|
|
|
452
514
|
|
|
453
515
|
## Error handling
|
|
454
516
|
|
|
455
|
-
Round
|
|
456
|
-
|
|
457
|
-
- Runtime error reporting with safe boundaries.
|
|
458
|
-
- `ErrorBoundary` to catch render-time errors and show a fallback.
|
|
459
|
-
|
|
460
|
-
### `ErrorBoundary`
|
|
461
|
-
|
|
462
|
-
Wrap components to prevent the whole app from crashing if a child fails to render.
|
|
517
|
+
Round JS favors individual error control and standard browser debugging:
|
|
463
518
|
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
function DangerousComponent() {
|
|
468
|
-
throw new Error('Boom!');
|
|
469
|
-
}
|
|
519
|
+
1. **Explict `try/catch`**: Use the JSX `try/catch` syntax to handle local component failures gracefully.
|
|
520
|
+
2. **Console-First Reporting**: Unhandled errors in component rendering or reactive effects are logged to the browser console with descriptive metadata (component name, render phase) and then allowed to propagate.
|
|
521
|
+
3. **No Intrusive Overlays**: Round has removed conflicting global error boundaries to ensure that your local handling logic always takes precedence and the developer experience remains clean.
|
|
470
522
|
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
</ErrorBoundary>
|
|
474
|
-
```
|
|
523
|
+
Example of a descriptive console log:
|
|
524
|
+
`[round] Error in phase "component.render" of component <UserProfile />: TypeError: Cannot read property 'avatar' of undefined`
|
|
475
525
|
|
|
476
526
|
## CLI
|
|
477
527
|
|
package/package.json
CHANGED
|
@@ -1,16 +1,22 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "round-core",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.4",
|
|
4
4
|
"description": "A lightweight frontend framework for SPA with signals and fine grained reactivity",
|
|
5
|
-
"main": "./
|
|
6
|
-
"types": "./
|
|
5
|
+
"main": "./src/index.js",
|
|
6
|
+
"types": "./src/index.d.ts",
|
|
7
7
|
"readme": "README.md",
|
|
8
8
|
"exports": {
|
|
9
|
-
".":
|
|
10
|
-
|
|
9
|
+
".": {
|
|
10
|
+
"types": "./src/index.d.ts",
|
|
11
|
+
"default": "./src/index.js"
|
|
12
|
+
},
|
|
13
|
+
"./vite-plugin": {
|
|
14
|
+
"types": "./src/compiler/vite-plugin.d.ts",
|
|
15
|
+
"default": "./src/compiler/vite-plugin.js"
|
|
16
|
+
}
|
|
11
17
|
},
|
|
12
18
|
"files": [
|
|
13
|
-
"
|
|
19
|
+
"src",
|
|
14
20
|
"README.md",
|
|
15
21
|
"LICENSE"
|
|
16
22
|
],
|
|
@@ -20,12 +26,11 @@
|
|
|
20
26
|
"url": "https://github.com/ZtaMDev/RoundJS.git"
|
|
21
27
|
},
|
|
22
28
|
"bin": {
|
|
23
|
-
"round": "./
|
|
29
|
+
"round": "./src/cli.js"
|
|
24
30
|
},
|
|
25
31
|
"scripts": {
|
|
26
32
|
"dev": "node ./src/cli.js dev --config ./test/main/round.config.json",
|
|
27
33
|
"build": "node ./src/cli.js build --config ./test/main/round.config.json",
|
|
28
|
-
"build:core": "vite build -c vite.config.build.js",
|
|
29
34
|
"bench": "bun run --cwd benchmarks bench",
|
|
30
35
|
"bench:build": "bun run --cwd benchmarks bench:build",
|
|
31
36
|
"bench:runtime": "bun run --cwd benchmarks bench:runtime"
|