Add resource SSR primitive, restore live demos in Examples section

- sx_primitives.ml: register resource as SSR stub returning signal
  {loading: true} — server renders loading state, client hydrates fetch
- reactive-islands/index.sx: Examples section with all 15 demo islands
  rendered inline alongside highlighted source code

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-03-31 10:28:26 +00:00
parent c55f6f9c4b
commit b423ebcea9
2 changed files with 28 additions and 1 deletions

View File

@@ -686,6 +686,18 @@ let () =
| None -> raise (Eval_error ("Store not found: " ^ name)))
| _ -> raise (Eval_error "use-store: expected (name)"));
register "clear-stores" (fun _args -> Hashtbl.clear store_registry; Nil);
(* resource — SSR stub: return signal with {loading: true}, client hydrates real fetch *)
register "resource" (fun _args ->
let state = Hashtbl.create 8 in
Hashtbl.replace state "loading" (Bool true);
Hashtbl.replace state "data" Nil;
Hashtbl.replace state "error" Nil;
let sig_d = Hashtbl.create 8 in
Hashtbl.replace sig_d "__signal" (Bool true);
Hashtbl.replace sig_d "value" (Dict state);
Hashtbl.replace sig_d "subscribers" (List []);
Hashtbl.replace sig_d "deps" (List []);
Dict sig_d);
register "apply" (fun args ->
let call f a =
match f with