| 211 | * @returns {EventListener} |
| 212 | */ |
| 213 | export function handlers(...handlers) { |
| 214 | return function (event) { |
| 215 | const { stopImmediatePropagation } = event; |
| 216 | let stopped = false; |
| 217 | |
| 218 | event.stopImmediatePropagation = () => { |
| 219 | stopped = true; |
| 220 | stopImmediatePropagation.call(event); |
| 221 | }; |
| 222 | |
| 223 | const errors = []; |
| 224 | |
| 225 | for (const handler of handlers) { |
| 226 | try { |
| 227 | // @ts-expect-error `this` is not typed |
| 228 | handler?.call(this, event); |
| 229 | } catch (e) { |
| 230 | errors.push(e); |
| 231 | } |
| 232 | |
| 233 | if (stopped) { |
| 234 | break; |
| 235 | } |
| 236 | } |
| 237 | |
| 238 | for (let error of errors) { |
| 239 | queueMicrotask(() => { |
| 240 | throw error; |
| 241 | }); |
| 242 | } |
| 243 | }; |
| 244 | } |
| 245 | |
| 246 | /** |
| 247 | * Function to create a `bubble` function that mimic the behavior of `on:click` without handler available in svelte 4. |