From ef61f83f74b5d019d575102b208146e1faf2df0d Mon Sep 17 00:00:00 2001 From: PM <12273891+n33pm@users.noreply.github.com> Date: Wed, 4 May 2022 16:50:33 +0200 Subject: [PATCH] feat(): promise optional success/error msg --- src/core/toast.ts | 28 ++++++++++++++++------------ 1 file changed, 16 insertions(+), 12 deletions(-) diff --git a/src/core/toast.ts b/src/core/toast.ts index ec04865..a8c2262 100644 --- a/src/core/toast.ts +++ b/src/core/toast.ts @@ -63,8 +63,8 @@ toast.promise = ( promise: Promise, msgs: { loading: Renderable; - success: ValueOrFunction; - error: ValueOrFunction; + success?: ValueOrFunction; + error?: ValueOrFunction; }, opts?: DefaultToastOptions ) => { @@ -72,19 +72,23 @@ toast.promise = ( promise .then((p) => { - toast.success(resolveValue(msgs.success, p), { - id, - ...opts, - ...opts?.success, - }); + if (msgs.success) + toast.success(resolveValue(msgs.success, p), { + id, + ...opts, + ...opts?.success, + }); + else toast.remove(id); return p; }) .catch((e) => { - toast.error(resolveValue(msgs.error, e), { - id, - ...opts, - ...opts?.error, - }); + if (msgs.error) + toast.error(resolveValue(msgs.error, e), { + id, + ...opts, + ...opts?.error, + }); + else toast.remove(id); }); return promise;