callNotifiedElement()function
callNotifiedElement(el: EventTarget | undefined, callback: NoticeCallback<A>, ...args: A): boolean | Promise<boolean>
| Param | Type | |
|---|---|---|
el | EventTarget | Element to dispatch the notice event on (defaults to window when undefined). |
callback | NoticeCallback<A> | The callback to run, whose return/throw drives the notice. required |
args | A | 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 vianotifyThrown(). - Resolves asynchronously when the callback returns a promise.
Examples
callNotifiedElement(formEl, () => save());