round-core 0.0.4 → 0.0.6
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/.github/workflows/benchmarks.yml +2 -2
- package/README.md +36 -8
- package/bun.lock +11 -0
- package/dist/cli.js +53 -56
- package/dist/index.d.ts +326 -0
- package/dist/index.js +71 -21
- package/dist/vite-plugin.js +7 -0
- package/package.json +47 -47
- package/src/cli.js +54 -52
- package/src/compiler/vite-plugin.js +8 -0
- package/src/index.d.ts +326 -0
- package/src/runtime/context.js +34 -11
- package/src/runtime/dom.js +10 -0
- package/src/runtime/router.js +111 -14
- package/src/runtime/signals.js +38 -0
- package/src/runtime/store.js +7 -0
- package/vite.config.build.js +14 -13
- package/index.html +0 -19
package/src/runtime/signals.js
CHANGED
|
@@ -12,6 +12,13 @@ function subscribe(running, subscriptions) {
|
|
|
12
12
|
running.dependencies.add(subscriptions);
|
|
13
13
|
}
|
|
14
14
|
|
|
15
|
+
/**
|
|
16
|
+
* Run a function without tracking any signals it reads.
|
|
17
|
+
* Any signals accessed inside `fn` will not become dependencies of the current effect.
|
|
18
|
+
* @template T
|
|
19
|
+
* @param {() => T} fn The function to execute.
|
|
20
|
+
* @returns {T} The return value of `fn`.
|
|
21
|
+
*/
|
|
15
22
|
export function untrack(fn) {
|
|
16
23
|
context.push(null);
|
|
17
24
|
try {
|
|
@@ -21,6 +28,13 @@ export function untrack(fn) {
|
|
|
21
28
|
}
|
|
22
29
|
}
|
|
23
30
|
|
|
31
|
+
/**
|
|
32
|
+
* Create a reactive side-effect that runs whenever its signal dependencies change.
|
|
33
|
+
* @param {(() => any) | any[]} arg1 Either the callback function or an array of explicit dependencies.
|
|
34
|
+
* @param {(() => any)} [arg2] The callback function if the first argument was explicit dependencies.
|
|
35
|
+
* @param {object} [arg3] Optional configuration (e.g., { onLoad: false }).
|
|
36
|
+
* @returns {() => void} A function to stop and cleanup the effect.
|
|
37
|
+
*/
|
|
24
38
|
export function effect(arg1, arg2, arg3) {
|
|
25
39
|
let callback;
|
|
26
40
|
let explicitDeps = null;
|
|
@@ -241,6 +255,12 @@ function attachHelpers(s) {
|
|
|
241
255
|
return s;
|
|
242
256
|
}
|
|
243
257
|
|
|
258
|
+
/**
|
|
259
|
+
* Create a reactive signal.
|
|
260
|
+
* @template T
|
|
261
|
+
* @param {T} [initialValue] The starting value.
|
|
262
|
+
* @returns {RoundSignal<T>} A signal function that reads/writes the value.
|
|
263
|
+
*/
|
|
244
264
|
export function signal(initialValue) {
|
|
245
265
|
let value = initialValue;
|
|
246
266
|
const subscriptions = new Set();
|
|
@@ -285,6 +305,12 @@ export function signal(initialValue) {
|
|
|
285
305
|
return attachHelpers(signal);
|
|
286
306
|
}
|
|
287
307
|
|
|
308
|
+
/**
|
|
309
|
+
* Create a bindable signal intended for two-way DOM bindings.
|
|
310
|
+
* @template T
|
|
311
|
+
* @param {T} [initialValue] The starting value.
|
|
312
|
+
* @returns {RoundSignal<T>} A signal function marked as bindable.
|
|
313
|
+
*/
|
|
288
314
|
export function bindable(initialValue) {
|
|
289
315
|
const s = signal(initialValue);
|
|
290
316
|
try {
|
|
@@ -345,6 +371,12 @@ function parsePath(path) {
|
|
|
345
371
|
return [String(path)];
|
|
346
372
|
}
|
|
347
373
|
|
|
374
|
+
/**
|
|
375
|
+
* Create a read/write view of a specific path within a signal object.
|
|
376
|
+
* @param {RoundSignal<any>} root The source signal.
|
|
377
|
+
* @param {string | string[]} path The property path (e.g., 'user.profile.name' or ['user', 'profile', 'name']).
|
|
378
|
+
* @returns {RoundSignal<any>} A signal-like view of the path.
|
|
379
|
+
*/
|
|
348
380
|
export function pick(root, path) {
|
|
349
381
|
if (!isSignalLike(root)) {
|
|
350
382
|
throw new Error('[round] pick(root, path) expects root to be a signal (use bindable.object(...) or signal({...})).');
|
|
@@ -499,6 +531,12 @@ bindable.object = function (initialObject = {}) {
|
|
|
499
531
|
return createBindableObjectProxy(root, []);
|
|
500
532
|
};
|
|
501
533
|
|
|
534
|
+
/**
|
|
535
|
+
* Create a read-only computed signal derived from other signals.
|
|
536
|
+
* @template T
|
|
537
|
+
* @param {() => T} fn A function that computes the value.
|
|
538
|
+
* @returns {(() => T)} A function that returns the derived value.
|
|
539
|
+
*/
|
|
502
540
|
export function derive(fn) {
|
|
503
541
|
const derived = signal();
|
|
504
542
|
|
package/src/runtime/store.js
CHANGED
|
@@ -5,6 +5,13 @@ function hasWindow() {
|
|
|
5
5
|
return typeof window !== 'undefined' && typeof document !== 'undefined';
|
|
6
6
|
}
|
|
7
7
|
|
|
8
|
+
/**
|
|
9
|
+
* Create a shared global state store with actions and optional persistence.
|
|
10
|
+
* @template T
|
|
11
|
+
* @param {T} [initialState={}] Initial state object.
|
|
12
|
+
* @param {Record<string, (state: T, ...args: any[]) => any>} [actions] Action reducers.
|
|
13
|
+
* @returns {RoundStore<T>} The store object.
|
|
14
|
+
*/
|
|
8
15
|
export function createStore(initialState = {}, actions = null) {
|
|
9
16
|
const state = (initialState && typeof initialState === 'object') ? initialState : {};
|
|
10
17
|
const signals = Object.create(null);
|
package/vite.config.build.js
CHANGED
|
@@ -2,32 +2,21 @@ import { defineConfig } from 'vite';
|
|
|
2
2
|
import path from 'node:path';
|
|
3
3
|
import fs from 'node:fs';
|
|
4
4
|
|
|
5
|
-
// Custom plugin to move .d.ts files or raw assets if needed,
|
|
6
|
-
// for now we just handle JS bundling.
|
|
7
|
-
|
|
8
|
-
// Custom plugin to move .d.ts files or raw assets if needed,
|
|
9
|
-
// for now we just handle JS bundling.
|
|
10
|
-
|
|
11
5
|
export default defineConfig({
|
|
12
6
|
build: {
|
|
13
|
-
// Target modern environments
|
|
14
7
|
target: 'es2022',
|
|
15
8
|
outDir: 'dist',
|
|
16
9
|
emptyOutDir: true,
|
|
17
|
-
minify: false,
|
|
18
|
-
// Wait, user asked for "extremo rapido y liviano" (extremely fast and light).
|
|
19
|
-
// So I SHOULD minify.
|
|
10
|
+
minify: false,
|
|
20
11
|
lib: {
|
|
21
12
|
entry: {
|
|
22
13
|
index: path.resolve(__dirname, 'src/index.js'),
|
|
23
14
|
cli: path.resolve(__dirname, 'src/cli.js'),
|
|
24
|
-
// We expose the plugin separately so users can import it in their vite.config.js
|
|
25
15
|
'vite-plugin': path.resolve(__dirname, 'src/compiler/vite-plugin.js')
|
|
26
16
|
},
|
|
27
|
-
formats: ['es']
|
|
17
|
+
formats: ['es']
|
|
28
18
|
},
|
|
29
19
|
rollupOptions: {
|
|
30
|
-
// Externalize dependencies so they aren't bundled into the library
|
|
31
20
|
external: [
|
|
32
21
|
'vite',
|
|
33
22
|
'marked',
|
|
@@ -44,4 +33,16 @@ export default defineConfig({
|
|
|
44
33
|
}
|
|
45
34
|
},
|
|
46
35
|
},
|
|
36
|
+
plugins: [
|
|
37
|
+
{
|
|
38
|
+
name: 'copy-dts',
|
|
39
|
+
closeBundle() {
|
|
40
|
+
const src = path.resolve(__dirname, 'src/index.d.ts');
|
|
41
|
+
const dest = path.resolve(__dirname, 'dist/index.d.ts');
|
|
42
|
+
if (fs.existsSync(src)) {
|
|
43
|
+
fs.copyFileSync(src, dest);
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
]
|
|
47
48
|
});
|
package/index.html
DELETED
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
<!DOCTYPE html>
|
|
2
|
-
<html lang="en">
|
|
3
|
-
|
|
4
|
-
<head>
|
|
5
|
-
<meta charset="UTF-8">
|
|
6
|
-
<title>Round Vite Test</title>
|
|
7
|
-
</head>
|
|
8
|
-
|
|
9
|
-
<body>
|
|
10
|
-
<div id="app"></div>
|
|
11
|
-
<script type="module">
|
|
12
|
-
import { render } from '/index.js';
|
|
13
|
-
import TestApp from 'start_exmpl/TestApp.round';
|
|
14
|
-
|
|
15
|
-
render(TestApp, document.getElementById('app'));
|
|
16
|
-
</script>
|
|
17
|
-
</body>
|
|
18
|
-
|
|
19
|
-
</html>
|