Skip to content

Instantly share code, notes, and snippets.

@amb26
Created March 11, 2024 13:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save amb26/a10e197883d8249438fdf8e3e4cb22de to your computer and use it in GitHub Desktop.
Save amb26/a10e197883d8249438fdf8e3e4cb22de to your computer and use it in GitHub Desktop.
Spitball implementation of fluid.effect which delays notification until all referenced signals have moved away from undefined
fluid.effect = function (func, ...args) {
return effect( () => {
let undefinedSignals = false;
const designalArgs = [];
for (const arg of args) {
if (arg instanceof preactSignalsCore.Signal) {
const value = arg.value;
designalArgs.push(arg.value);
if (value === undefined) {
undefinedSignals = true;
}
} else {
designalArgs.push(arg);
}
}
// const designalArgs = args.map(arg => arg instanceof preactSignalsCore.Signal ? arg.value : arg);
if (!undefinedSignals) {
return typeof(func) === "string" ? fluid.invokeGlobalFunction(func, designalArgs) : func.apply(null, designalArgs);
}
});
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment