round-core 0.1.1 → 0.1.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.
- package/README.md +78 -3
- package/package.json +17 -11
- package/src/cli.js +609 -0
- package/src/compiler/index.js +2 -0
- package/src/compiler/transformer.js +525 -0
- package/src/compiler/vite-plugin.d.ts +8 -0
- package/src/compiler/vite-plugin.js +472 -0
- package/{dist → src}/index.d.ts +75 -44
- package/src/index.js +42 -0
- package/src/runtime/context.js +101 -0
- package/src/runtime/dom.js +401 -0
- package/src/runtime/error-boundary.js +48 -0
- package/src/runtime/error-reporter.js +13 -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 +484 -0
- package/src/runtime/store.js +215 -0
- package/src/runtime/suspense.js +128 -0
- package/dist/cli.js +0 -579
- package/dist/index.js +0 -2047
- package/dist/vite-plugin.js +0 -857
package/README.md
CHANGED
|
@@ -20,7 +20,7 @@ Extension for [VSCode](https://marketplace.visualstudio.com/items?itemName=ZtaMD
|
|
|
20
20
|
|
|
21
21
|
---
|
|
22
22
|
|
|
23
|
-
Instead of a Virtual DOM diff, Round updates the UI by subscribing DOM updates directly to reactive primitives
|
|
23
|
+
Instead of a Virtual DOM diff, Round updates the UI by subscribing DOM updates directly to reactive primitives **signals** and **bindables**. This keeps rendering predictable, small, and fast for interactive apps.
|
|
24
24
|
|
|
25
25
|
The `round-core` package is the **foundation of RoundJS**.
|
|
26
26
|
|
|
@@ -163,6 +163,23 @@ effect(() => {
|
|
|
163
163
|
name('Grace');
|
|
164
164
|
```
|
|
165
165
|
|
|
166
|
+
### `untrack(fn)`
|
|
167
|
+
|
|
168
|
+
Run a function without tracking any signals it reads.
|
|
169
|
+
|
|
170
|
+
```javascript
|
|
171
|
+
import { signal, untrack, effect } from 'round-core';
|
|
172
|
+
|
|
173
|
+
const count = signal(0);
|
|
174
|
+
effect(() => {
|
|
175
|
+
console.log('Count is:', count());
|
|
176
|
+
untrack(() => {
|
|
177
|
+
// This read won't trigger the effect if it changes elsewhere
|
|
178
|
+
console.log('Static value:', count());
|
|
179
|
+
});
|
|
180
|
+
});
|
|
181
|
+
```
|
|
182
|
+
|
|
166
183
|
### `bindable(initialValue)`
|
|
167
184
|
|
|
168
185
|
`bindable()` creates a signal intended for **two-way DOM bindings**.
|
|
@@ -206,14 +223,24 @@ export function TodoList() {
|
|
|
206
223
|
|
|
207
224
|
return (
|
|
208
225
|
<div>
|
|
209
|
-
{
|
|
226
|
+
{for(todo in todos()){
|
|
227
|
+
<div>{todo.text}</div>
|
|
228
|
+
}}
|
|
210
229
|
<button onClick={() => store.addTodo('Buy Milk')}>Add</button>
|
|
211
230
|
</div>
|
|
212
231
|
);
|
|
213
232
|
}
|
|
214
233
|
|
|
215
234
|
// 3. Persistence (Optional)
|
|
216
|
-
store.persist('my-app-store'
|
|
235
|
+
store.persist('my-app-store', {
|
|
236
|
+
debounce: 100, // ms
|
|
237
|
+
exclude: ['someSecretKey']
|
|
238
|
+
});
|
|
239
|
+
|
|
240
|
+
// 4. Advanced Methods
|
|
241
|
+
store.patch({ filter: 'completed' }); // Update multiple keys at once
|
|
242
|
+
const data = store.snapshot({ reactive: false }); // Get static JSON of state
|
|
243
|
+
store.set('todos', []); // Direct set
|
|
217
244
|
```
|
|
218
245
|
|
|
219
246
|
### `bindable.object(initialObject)` and deep binding
|
|
@@ -241,6 +268,38 @@ export function Profile() {
|
|
|
241
268
|
}
|
|
242
269
|
```
|
|
243
270
|
|
|
271
|
+
## Lifecycle Hooks
|
|
272
|
+
|
|
273
|
+
Round provides hooks to tap into the lifecycle of components. These must be called during the synchronous execution of your component function.
|
|
274
|
+
|
|
275
|
+
### `onMount(fn)`
|
|
276
|
+
Runs after the component is first created and its elements are added to the DOM. If `fn` returns a function, it's used as a cleanup (equivalent to `onUnmount`).
|
|
277
|
+
|
|
278
|
+
### `onUnmount(fn)`
|
|
279
|
+
Runs when the component's elements are removed from the DOM.
|
|
280
|
+
|
|
281
|
+
### `onUpdate(fn)`
|
|
282
|
+
Runs whenever any signal read during the component's *initial* render is updated.
|
|
283
|
+
|
|
284
|
+
### `onCleanup(fn)`
|
|
285
|
+
Alias for `onUnmount`.
|
|
286
|
+
|
|
287
|
+
```jsx
|
|
288
|
+
import { onMount, onUnmount } from 'round-core';
|
|
289
|
+
|
|
290
|
+
export function MyComponent() {
|
|
291
|
+
onMount(() => {
|
|
292
|
+
console.log('Mounted!');
|
|
293
|
+
const timer = setInterval(() => {}, 1000);
|
|
294
|
+
return () => clearInterval(timer); // Cleanup
|
|
295
|
+
});
|
|
296
|
+
|
|
297
|
+
onUnmount(() => console.log('Goodbye!'));
|
|
298
|
+
|
|
299
|
+
return <div>Hello</div>;
|
|
300
|
+
}
|
|
301
|
+
```
|
|
302
|
+
|
|
244
303
|
### `.validate(validator, options)`
|
|
245
304
|
|
|
246
305
|
Attach validation to a signal/bindable.
|
|
@@ -398,6 +457,22 @@ Round aims to provide strong developer feedback:
|
|
|
398
457
|
- Runtime error reporting with safe boundaries.
|
|
399
458
|
- `ErrorBoundary` to catch render-time errors and show a fallback.
|
|
400
459
|
|
|
460
|
+
### `ErrorBoundary`
|
|
461
|
+
|
|
462
|
+
Wrap components to prevent the whole app from crashing if a child fails to render.
|
|
463
|
+
|
|
464
|
+
```jsx
|
|
465
|
+
import { ErrorBoundary } from 'round-core';
|
|
466
|
+
|
|
467
|
+
function DangerousComponent() {
|
|
468
|
+
throw new Error('Boom!');
|
|
469
|
+
}
|
|
470
|
+
|
|
471
|
+
<ErrorBoundary fallback={(err) => <div className="error">Something went wrong: {err.message}</div>}>
|
|
472
|
+
<DangerousComponent />
|
|
473
|
+
</ErrorBoundary>
|
|
474
|
+
```
|
|
475
|
+
|
|
401
476
|
## CLI
|
|
402
477
|
|
|
403
478
|
The CLI is intended for day-to-day development:
|
package/package.json
CHANGED
|
@@ -1,26 +1,36 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "round-core",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.3",
|
|
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
|
},
|
|
18
|
+
"files": [
|
|
19
|
+
"src",
|
|
20
|
+
"README.md",
|
|
21
|
+
"LICENSE"
|
|
22
|
+
],
|
|
12
23
|
"type": "module",
|
|
13
24
|
"icon": "Round.png",
|
|
14
25
|
"repository": {
|
|
15
26
|
"url": "https://github.com/ZtaMDev/RoundJS.git"
|
|
16
27
|
},
|
|
17
28
|
"bin": {
|
|
18
|
-
"round": "./
|
|
29
|
+
"round": "./src/cli.js"
|
|
19
30
|
},
|
|
20
31
|
"scripts": {
|
|
21
32
|
"dev": "node ./src/cli.js dev --config ./test/main/round.config.json",
|
|
22
33
|
"build": "node ./src/cli.js build --config ./test/main/round.config.json",
|
|
23
|
-
"build:core": "vite build -c vite.config.build.js",
|
|
24
34
|
"bench": "bun run --cwd benchmarks bench",
|
|
25
35
|
"bench:build": "bun run --cwd benchmarks bench:build",
|
|
26
36
|
"bench:runtime": "bun run --cwd benchmarks bench:runtime"
|
|
@@ -33,11 +43,7 @@
|
|
|
33
43
|
],
|
|
34
44
|
"author": "Round Framework Team",
|
|
35
45
|
"license": "MIT",
|
|
36
|
-
"files": [
|
|
37
|
-
"dist"
|
|
38
|
-
],
|
|
39
46
|
"dependencies": {
|
|
40
|
-
"marked": "^12.0.2",
|
|
41
47
|
"vite": "^5.0.0"
|
|
42
48
|
},
|
|
43
49
|
"devDependencies": {
|