MCPcopy
hub / github.com/sveltejs/svelte / handlers

Function handlers

packages/svelte/src/legacy/legacy-client.js:213–244  ·  view source on GitHub ↗
(...handlers)

Source from the content-addressed store, hash-verified

211 * @returns {EventListener}
212 */
213export 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.

Callers

nothing calls this directly

Calls 1

pushMethod · 0.80

Tested by

no test coverage detected