callNotifiedElement()function

callNotifiedElement(el: EventTarget | undefined, callback: NoticeCallback<A>, ...args: A): boolean | Promise<boolean>
ParamType
elEventTarget
Element to dispatch the notice event on (defaults to window when undefined).
callbackNoticeCallback<A>
The callback to run, whose return/throw drives the notice. required
argsA
Arguments forwarded to the callback. required
Return
boolean | Promise<boolean>
true if the callback succeeded, false if it threw (a Promise of the same when async).

Run a callback and dispatch a success or error notice to a specific element based on its return or throw.

  • A returned truthy value becomes a "success" notice; a thrown value becomes an "error" notice via notifyThrown().
  • Resolves asynchronously when the callback returns a promise.

Examples

callNotifiedElement(formEl, () => save());