LegacyAsyncFunction

LegacyAsyncFunction: ((this: LegacyPluginThis, done: ((result: LegacyValue) => void)) => void) | ((this: LegacyPluginThis, arg1: LegacyValue, done: LegacyAsyncFunctionDone) => void) | ((this: LegacyPluginThis, arg1: LegacyValue, arg2: LegacyValue, done: LegacyAsyncFunctionDone) => void) | ((this: LegacyPluginThis, arg1: LegacyValue, arg2: LegacyValue, arg3: LegacyValue, done: LegacyAsyncFunctionDone) => void) | ((this: LegacyPluginThis, arg1: LegacyValue, arg2: LegacyValue, arg3: LegacyValue, arg4: LegacyValue, done: LegacyAsyncFunctionDone) => void) | ((this: LegacyPluginThis, arg1: LegacyValue, arg2: LegacyValue, arg3: LegacyValue, arg4: LegacyValue, arg5: LegacyValue, done: LegacyAsyncFunctionDone) => void) | ((this: LegacyPluginThis, arg1: LegacyValue, arg2: LegacyValue, arg3: LegacyValue, arg4: LegacyValue, arg5: LegacyValue, arg6: LegacyValue, done: LegacyAsyncFunctionDone) => void) | ((this: LegacyPluginThis, args: [LegacyValue[], LegacyAsyncFunctionDone]) => void)

Ein asynchroner Callback, der eine benutzerdefinierte Sass-Funktion implementiert. Dies kann an functions übergeben werden, jedoch nur für render.

Eine asynchrone Funktion muss undefined zurückgeben. Ihr letztes Argument ist immer ein Callback, den sie mit dem Ergebnis der Funktion aufrufen sollte, sobald sie abgeschlossen ist.

Wenn dies einen Fehler auslöst, wird Sass dies als Fehler der Funktion mit dieser Fehlermeldung behandeln.

sass.render({
file: 'style.scss',
functions: {
"sum($arg1, $arg2)": (arg1, arg2, done) => {
if (!(arg1 instanceof sass.types.Number)) {
throw new Error("$arg1: Expected a number");
} else if (!(arg2 instanceof sass.types.Number)) {
throw new Error("$arg2: Expected a number");
}
done(new sass.types.Number(arg1.getValue() + arg2.getValue()));
}
}
}, (result, error) => {
// ...
});

Dies erhält ein Argument für jedes Argument, das in der an functions übergebenen Signatur deklariert ist. Wenn die Signatur beliebige Argumente annimmt, werden diese als einzelne Argumentliste im letzten Argument vor dem Callback übergeben.

Veraltet

Dies funktioniert nur mit den alten render und renderSync APIs. Verwenden Sie stattdessen CustomFunction mit compile, compileString, compileAsync und compileStringAsync stattdessen.