by AlexErrant · 2w ago · 0 comments
Contrast that with React, where hooks are colored functions. You thought that hooks were just functions? Nope, if you have a hook, it MUST be called in a hook/component... exactly like async. Did you want to load this TTS player conditionally? Hahah, you can't. Have fun allocating memory for every TTS provider your app supports, even if the user uses only 1 player. https://news.ycombinator.com/item?id=45257413
"Thanks to async in the graph we can detect waterfalls, poorly constructed effect loops, poorly scaling graph shapes like wide graph fanouts and fan-ins." Incredibly cool. Apparently Tanstack Query has a waterfall detector https://github.com/bamlab/tanstack-query-detect-waterfall so the other frameworks have something similar, but it won't work with their state graphs.
TC39 EcmaScript spec editors adddd `async`/`await` in JavaScript as a feature to make it visually clear (to humans, and now agents) what is async or not, unlike (e.g.) Java with synchronous-looking calls everywhere and no hint at what is async (or multi-threaded) or not.
In Solid 1.0, at least an undefined or null value would need to be checked to make async values a little more explicit, but maybe even that is not as good as a some hypothetical feature we have yet to invent to make this clear in signals world. (Well, there are some generator prototypes for Solid 2.0 using `yield` syntax, which are ultra clear, but also very verbose).
So I'm curious how the race to battle race conditions is gonna turn out. It might be too magical right now.
We'll see!
That needs to emphasized more. Pretty sure React's Suspense suffers from waterfalls if memory serves.
Um, you can? Just change this:
if (tts) useState(() => loadTTS(tts))
to this: useState(() => tts && loadTTS(tts))That does not work because `loadTTS` is actually a hook, so its `useLoadTTS`, and hooks must be top level. I encourage you to look at the pastebin in my link, repeated here https://pastebin.com/sjc3vXTd
So, I must have
let provider = useGetUserPreference()
let a = useLoadTTS_A()
let b = useLoadTTS_B()
let c = useLoadTTS_C()
useEffect(() => {
if (provider=="a") a()
if (provider=="b") b()
if (provider=="c") c()
})
Oh hey, what's that? I have to allocate memory for b and c even though only a is used? THANKS REACT. const players = {
sherpa: SherpaPlayer,
local: LocalPlayer,
gemini: GeminiPlayer,
} satisfies Record<VoiceProvider, React.ComponentType>;
function PlayerSwitcher() {
const provider = useAppStore.use.voiceProvider();
const Player = players[provider];
return <Player />;
}
function useRegisterPlayer(player: Player, shortPlayer: Player) {
const { setPlayer, setShortPlayer } = useAppActions();
useEffect(() => {
setPlayer(player);
setShortPlayer(shortPlayer);
}, [player, shortPlayer, setPlayer, setShortPlayer]);
}
function LocalPlayer() {
useRegisterPlayer(useLocalPlayer(), useShortLocalPlayer());
return null;
}
function GeminiPlayer() {
useRegisterPlayer(useGeminiPlayer(), useShortGeminiPlayer());
return null;
}
function SherpaPlayer() {
useRegisterPlayer(useSherpaPlayer(), useShortSherpaPlayer());
return null;
}Trust me, I hate hooks. I don't use them unless I must.