From a5326a67e37d9f1aee740f7b3d46345f3bcda419 Mon Sep 17 00:00:00 2001 From: Owen Jacobson Date: Wed, 9 Jul 2025 23:29:06 -0400 Subject: 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. --- ui/lib/swatch/derive.js | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) (limited to 'ui/lib/swatch/derive.js') 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); -- cgit v1.2.3