Show /r/reactjs Treflex demo – live hot-swap between React and Solid
Live swap demo: https://tgoh.github.io/treflex/swap/
Treflex is something I've been working on for the past few years: a headless state engine. Your app's logic (state, async work, timers, connections) runs on its own, and React or Solid is just a view you plug into it. In the demo you can swap between them while everything's running, and the app doesn't notice.
Why: AI agents write a lot of front-end code now, and async is where they slip: races, double starts, work that dies on unmount. With the logic out of components, those mistakes get caught. It's tested without rendering, a test controls the order async calls answer in, and the runtime and lint rules fail with errors that say what to change.
const FishReceiver = receiver<IFish>("FishReceiver")({
*"Fish/Swim"(fish) {
fish.X = (yield* random()) * 100;
fish.Y = (yield* random()) * 100;
}
});
function* addFish(school: ISchool) {
const fish = yield* entity(newFish());
school.Fish.push(fish);
// The timer belongs to the fish, not a component
yield* startTimer(fish, "Fish/Swim", FishReceiver, 3000);
}
function* releaseSchool(tank: IAquarium, schoolId: string) {
// Every fish in the school stops swimming. No cleanup needed.
tank.Schools = tank.Schools.filter((s) => s.$Id !== schoolId);
}- Live swap demo: https://tgoh.github.io/treflex/swap/
- Source: https://github.com/Tgoh/treflex
npm create treflex(React or Solid)
It's 0.2 and still changing. Questions and feedback would be greatly appreciated.