Created
March 11, 2024 13:41
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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