Show /r/reactjs Treflex demo – live hot-swap between React and Solid
https://youtu.be/vCTUfypEsi8Live 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.
8
u/Honey-Entire 7d ago
So you reinvented RxJS / Redux Saga because AI made it easy instead of just using an existing library? Do you even know why this type of programming fell out of favor in web development?
2
u/TheRealSeeThruHead 6d ago
I mean we are beyond this already
Use fold kit or something else that is far more opinionated than solid or react.
I created a version of solid that fully integrates with effect. Stores all changes Ina log agents can query and does fully distributed tracing of every component all the from the frontend to the db.
I think we’ve blown past the agent friend state manager for react but maybe everyone needs to catch up
1
u/Jazzlike-Web-3695 7d ago
how does state survive the swap? like if a fish is mid-animation when you switch to solid, does it continue from the same position or restart