MCPcopy
hub / github.com/sveltejs/svelte / $on

Method $on

packages/svelte/src/legacy/legacy-client.js:167–176  ·  view source on GitHub ↗

* @param {string} event * @param {(...args: any[]) => any} callback * @returns {any}

(event, callback)

Source from the content-addressed store, hash-verified

165 * @returns {any}
166 */
167 $on(event, callback) {
168 this.#events[event] = this.#events[event] || [];
169
170 /** @param {any[]} args */
171 const cb = (...args) => callback.call(this, ...args);
172 this.#events[event].push(cb);
173 return () => {
174 this.#events[event] = this.#events[event].filter(/** @param {any} fn */ (fn) => fn !== cb);
175 };
176 }
177
178 $destroy() {
179 this.#instance.$destroy();

Callers 12

addEventListenerMethod · 0.80
connectedCallbackMethod · 0.80
testFunction · 0.80
testFunction · 0.80
testFunction · 0.80
testFunction · 0.80
testFunction · 0.80
testFunction · 0.80
testFunction · 0.80
testFunction · 0.80
testFunction · 0.80
component.tsFile · 0.80

Calls 1

pushMethod · 0.80

Tested by 9

testFunction · 0.64
testFunction · 0.64
testFunction · 0.64
testFunction · 0.64
testFunction · 0.64
testFunction · 0.64
testFunction · 0.64
testFunction · 0.64
testFunction · 0.64