@fluixi/core 1.0.0-alpha.76 → 1.0.0-alpha.78

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 CHANGED
@@ -4,7 +4,7 @@
4
4
 
5
5
  # @fluixi/core
6
6
 
7
- **A modern, reactive UI framework with fine-grained reactivity, routing and SSR.**
7
+ **A compiler-native reactive framework. The compiler knows what's reactive, so you write ordinary TypeScript.**
8
8
 
9
9
  [![License: MIT](https://img.shields.io/badge/License-MIT-22c55e.svg)](./LICENSE)
10
10
  ![TypeScript](https://img.shields.io/badge/TypeScript-strict-3178c6?logo=typescript&logoColor=white)
@@ -12,18 +12,20 @@
12
12
 
13
13
  ---
14
14
 
15
- A modern, reactive UI framework with JSX, fine-grained reactivity, routing and SSR. Components compile to direct DOM operationsno virtual DOM, surgical updates.
15
+ Most reactive frameworks ask you to keep a model in your head that the language doesn't share: which reads are tracked, what you may not destructure, where a value has to stay a function. The compiler can't help, because it doesn't know what your values are so the burden is yours, and the failures are quiet ones.
16
+
17
+ Fluixi's compiler knows. It resolves a reactive primitive by the binding it came from, not by how the name reads, and carries that through JSX and `` html`` `` templates, the DOM it generates, SSR, hydration and routing as one model.
16
18
 
17
19
  ## Features
18
20
 
19
- - 🚀 **Fine-grained Reactivity** - Signals and memos drive surgical DOM updates, no virtual DOM
20
- - 🧩 **JSX** - Compiled to direct DOM instructions via `@fluixi/vite-plugin`
21
- - 🔄 **Control Flow Components** - Show, For, Switch, Portal, and Dynamic
22
- - 🛣️ **Built-in Router** - Client-side routing with nested routes and lazy loading
23
- - 📡 **Resource Management** - Async data fetching with automatic loading states + Suspense
24
- - 🎭 **Context API** - Share state across component trees without prop drilling
25
- - 🖥️ **SSR + Hydration** - Server rendering with flash-free hydration (via `@fluixi/start`)
26
- - 🏗️ **TypeScript First** - Full type safety and excellent IDE support
21
+ - 🧠 **The compiler understands reactivity** - resolves primitives by binding, not by name; an alias is recognised, a same-named local function is not
22
+ - ✂️ **Destructure your props** - `function Card({ title })` keeps updating; `...rest` becomes the `splitProps` call you'd have written
23
+ - ✍️ **Two syntaxes, one model** - JSX and `` html`` `` templates compile to the same reactive representation
24
+ - 🚀 **Direct DOM** - a change runs the binding that depends on it; no component re-render, no diff, no virtual tree
25
+ - **Load strategies** - `load:visible`, `load:idle`, `load:interaction`, `load:media` split a component into its own chunk
26
+ - 🛣️ **Router, SSR and hydration** - the same reactive graph end to end, not agreed at the edges
27
+ - 📡 **Resources + Suspense** - async data with loading/error state, awaited and seeded during SSR
28
+ - 🏗️ **TypeScript first** - full types, and a language-service plugin for `` html`` `` templates
27
29
 
28
30
  ## Installation
29
31
 
@@ -47,17 +49,17 @@ npm create fluixi my-app
47
49
  ### Basic Example
48
50
 
49
51
  ```tsx
50
- import { createSignal, render } from '@fluixi/core';
52
+ import { render } from '@fluixi/core';
51
53
 
52
54
  const Counter = () => {
53
- const [count, setCount] = createSignal(0);
55
+ const count = $signal(0);
54
56
 
55
57
  return (
56
58
  <div>
57
59
  <h1>Count: {count()}</h1>
58
- <button onClick={() => setCount(count() + 1)}>Increment</button>
59
- <button onClick={() => setCount(count() - 1)}>Decrement</button>
60
- <button onClick={() => setCount(0)}>Reset</button>
60
+ <button onClick={() => count.set(count() + 1)}>Increment</button>
61
+ <button onClick={() => count.set(count() - 1)}>Decrement</button>
62
+ <button onClick={() => count.set(0)}>Reset</button>
61
63
  </div>
62
64
  );
63
65
  };
@@ -65,6 +67,8 @@ const Counter = () => {
65
67
  render(() => <Counter />, document.getElementById('app')!);
66
68
  ```
67
69
 
70
+ `$signal` needs no import — the compiler resolves it and adds what it needs. `signal(0)` from `@fluixi/reactive/signal` is the same primitive when you'd rather import it, and works in a package that never runs this compiler.
71
+
68
72
  > JSX is compiled by `@fluixi/vite-plugin`. Scaffold a ready-to-run app with `npm create fluixi`.
69
73
 
70
74
  ## Core Concepts
@@ -74,31 +78,49 @@ render(() => <Counter />, document.getElementById('app')!);
74
78
  Signals are reactive state. Reading one inside an effect or JSX subscribes to it; setting it updates only what depends on it.
75
79
 
76
80
  ```tsx
77
- import { createSignal, createEffect } from '@fluixi/core';
78
-
79
- const [count, setCount] = createSignal(0);
80
- const [name, setName] = createSignal('Alice');
81
+ const count = $signal(0);
82
+ const name = $signal('Alice');
81
83
 
82
- createEffect(() => {
84
+ $effect(() => {
83
85
  console.log(`${name()} counted to ${count()}`);
84
86
  });
85
87
 
86
- setCount(5); // "Alice counted to 5"
87
- setName('Bob'); // "Bob counted to 5"
88
+ count.set(5); // "Alice counted to 5"
89
+ name.set('Bob'); // "Bob counted to 5"
88
90
  ```
89
91
 
92
+ Call it to read, `.set()` to write. `$memo` derives, `$store` holds an object you read
93
+ properties off, `$resource` wraps async data. Each has an importable twin — `signal`,
94
+ `memo`, `effect`, `store`, `resource` from `@fluixi/reactive/signal` — and they are the
95
+ same primitives, so the two spellings mix freely in one file.
96
+
97
+ `createSignal` and its `[read, write]` pair are unchanged, and plenty of code is written
98
+ against them.
99
+
90
100
  ### Components
91
101
 
92
- Components are plain functions that return JSX. Props are reactive read them where you use them.
102
+ Components are plain functions that return JSX. A component runs **once**; props are live
103
+ reads rather than values handed over at call time.
93
104
 
94
105
  ```tsx
95
106
  function Greeting(props: { name: string }) {
96
107
  return <h1>Hello, {props.name}!</h1>;
97
108
  }
109
+ ```
98
110
 
99
- // <Greeting name="World" />
111
+ Destructuring them is fine — the compiler rewrites the bindings into reads, so they keep
112
+ updating, and `...rest` becomes the `splitProps` call you would have written:
113
+
114
+ ```tsx
115
+ function Card({ title, tone = 'calm', ...rest }) {
116
+ return <article data-tone={tone} {...rest}><h2>{title}</h2></article>;
117
+ }
100
118
  ```
101
119
 
120
+ Where it can't prove a rewrite is safe — a reassigned binding, a computed key, a default
121
+ it would have to re-run on every read — it leaves your code exactly as written and says
122
+ why at build time.
123
+
102
124
  ### Control Flow
103
125
 
104
126
  Use control-flow components instead of ternaries and `.map()` so updates stay fine-grained.
@@ -126,16 +148,51 @@ import { Show, For, Switch, Match } from '@fluixi/core';
126
148
 
127
149
  `Portal`, `Dynamic`, `Index`, and `ErrorBoundary` are also exported.
128
150
 
151
+ ### Load strategies
152
+
153
+ A `load:` directive decides *when* a component's module is fetched, and moves it into its
154
+ own chunk:
155
+
156
+ ```tsx
157
+ import { RevenueChart } from './RevenueChart';
158
+
159
+ <RevenueChart load:visible="200px" /> // when it scrolls near the viewport
160
+ <ExportDialog load:interaction /> // on first pointer, focus or key
161
+ <AuditLog load:media="(min-width: 1024px)" />
162
+ <Panel load:idle />
163
+ ```
164
+
165
+ Deferring replaces your static import with a dynamic one, so it applies when the name is
166
+ used only as a tag. Reference it as a value too and the import stays — the build says so
167
+ rather than silently shipping the chunk eagerly.
168
+
169
+ ### `` html`` `` templates
170
+
171
+ The same reactive model without configuring JSX — useful in a library, a script, or a
172
+ plain-TypeScript codebase:
173
+
174
+ ```ts
175
+ import { html } from '@fluixi/core';
176
+
177
+ function Counter() {
178
+ const n = $signal(0);
179
+ return html`<button @click=${() => n.set(n() + 1)}>${n()}</button>`;
180
+ }
181
+ ```
182
+
183
+ Both syntaxes compile to the same representation; `@fluixi/ts-plugin` gives templates
184
+ hover, completion and type-checking in the editor.
185
+
129
186
  ### Resources & Suspense
130
187
 
131
188
  `createResource` fetches async data and tracks loading/error. `<Suspense>` shows a fallback while it's pending (works on the client and during SSR).
132
189
 
133
190
  ```tsx
134
- import { createSignal, createResource, Suspense } from '@fluixi/core';
191
+ import { Suspense } from '@fluixi/core';
135
192
 
136
193
  function UserCard() {
137
- const [id] = createSignal(1);
138
- const [user] = createResource(id, (id) =>
194
+ const id = $signal(1);
195
+ const user = $resource(id, (id) =>
139
196
  fetch(`/api/users/${id}`).then((r) => r.json())
140
197
  );
141
198
 
@@ -203,10 +260,10 @@ render(() => <Router routes={routes} />, document.getElementById('app')!);
203
260
  import { onMount, onCleanup } from '@fluixi/core';
204
261
 
205
262
  function Clock() {
206
- const [now, setNow] = createSignal(Date.now());
263
+ const now = $signal(Date.now());
207
264
 
208
265
  onMount(() => {
209
- const id = setInterval(() => setNow(Date.now()), 1000);
266
+ const id = setInterval(() => now.set(Date.now()), 1000);
210
267
  onCleanup(() => clearInterval(id));
211
268
  });
212
269
 
@@ -217,18 +274,18 @@ function Clock() {
217
274
  ## Derived State & Batching
218
275
 
219
276
  ```tsx
220
- import { createSignal, createMemo, batch } from '@fluixi/core';
277
+ import { batch } from '@fluixi/core';
221
278
 
222
- const [first, setFirst] = createSignal('Ada');
223
- const [last, setLast] = createSignal('Lovelace');
279
+ const first = $signal('Ada');
280
+ const last = $signal('Lovelace');
224
281
 
225
282
  // Memo — cached, recomputes only when a dependency changes
226
- const fullName = createMemo(() => `${first()} ${last()}`);
283
+ const fullName = $memo(() => `${first()} ${last()}`);
227
284
 
228
285
  // Batch — coalesce multiple writes into one update
229
286
  batch(() => {
230
- setFirst('Grace');
231
- setLast('Hopper');
287
+ first.set('Grace');
288
+ last.set('Hopper');
232
289
  });
233
290
  ```
234
291
 
@@ -254,11 +311,19 @@ Fluixi is written in TypeScript and ships full types. Configure JSX in your `tsc
254
311
  | Package | Purpose |
255
312
  | --- | --- |
256
313
  | `@fluixi/core` | Framework façade — components, control flow, router, render |
257
- | `@fluixi/reactive` | Signals, memos, effects, store |
314
+ | `@fluixi/reactive` | Signals, memos, effects, store — usable on its own |
258
315
  | `@fluixi/dom` | The DOM rendering runtime |
259
- | `@fluixi/start` | SSR, hydration, file routing, dev/build |
260
- | `@fluixi/vite-plugin` | JSX compile (Vite) |
261
- | `create-fluixi` | App scaffolder (`npm create fluixi`) |
316
+ | `@fluixi/compiler` | JSX and `` html`` `` → IR → direct DOM calls |
317
+ | `@fluixi/vite-plugin` | The compiler as a Vite plugin (rollup, esbuild and webpack adapters too) |
318
+ | `@fluixi/start` | SSR, streaming, SSG, file routing, server functions, deploy adapters |
319
+ | `@fluixi/router` | The routing core |
320
+ | `@fluixi/server` | Server rendering |
321
+ | `@fluixi/head` | Document head and SEO |
322
+ | `@fluixi/ts-plugin` | Editor support for `` html`` `` templates |
323
+ | `@fluixi/template-parser` | The `` html`` `` parser, standalone |
324
+ | `@fluixi/auth` · `@fluixi/session` | Auth bindings and sessions |
325
+ | `@fluixi/testing` · `@fluixi/devtools` | Test helpers, reactive-graph devtools |
326
+ | `@fluixi/cli` · `create-fluixi` | Generators and the app scaffolder |
262
327
 
263
328
  ## License
264
329