summaryrefslogtreecommitdiff
path: root/ui/lib/swatch/derive.js
diff options
context:
space:
mode:
authorOwen Jacobson <owen@grimoire.ca>2025-07-09 23:29:06 -0400
committerOwen Jacobson <owen@grimoire.ca>2025-08-21 19:42:09 -0400
commita5326a67e37d9f1aee740f7b3d46345f3bcda419 (patch)
tree18a1eff075e12c60e2bc2400703b9ad2cc67e7d4 /ui/lib/swatch/derive.js
parent4624f4dbebf5dd1ed4dc5168573537459b9a115e (diff)
Factor data-to-JSON-string construction out of stitches.
This is a recurring and nameable operation; let's give it a name before we use it further.
Diffstat (limited to 'ui/lib/swatch/derive.js')
-rw-r--r--ui/lib/swatch/derive.js6
1 files changed, 1 insertions, 5 deletions
diff --git a/ui/lib/swatch/derive.js b/ui/lib/swatch/derive.js
index 85547e8..22ceb13 100644
--- a/ui/lib/swatch/derive.js
+++ b/ui/lib/swatch/derive.js
@@ -5,16 +5,12 @@ function tryDerive(args, func, fallback) {
try {
return func(...args);
} catch (e) {
- console.debug('deriver threw exception', e, func, args);
return fallback;
}
}
// A "deriver" is a function that never raises; if the underlying function would raise, the
// corresponding deriver instead returns a fallback value (or `undefined`).
-export function makeDeriver(func, fallback) {
+export function makeDeriver(func, fallback = undefined) {
return (...args) => tryDerive(args, func, fallback);
}
-
-// Some widely-used derivers, for convenience.
-export const json = makeDeriver(JSON.parse);