Skip to main content

detach

Removes a handler or interceptor registered with a tag through api.on or api.intercept. Use it to clean up event subscriptions that are no longer needed.

Usage​

detach(tag: number | string | symbol): void;
ParameterTypeDescription
tagnumber | string | symbolThe tag assigned when registering the handler via the config parameter of on or intercept

Example​

Registering a handler with a tag and removing it later:

<script>
import { Kanban } from "@svar-ui/svelte-kanban";

let api;

function attach(a) {
api = a;
api.on(
"update-card",
ev => {
console.log("card updated", ev.id);
},
{ tag: "logger" }
);
}

function cleanup() {
api.detach("logger");
}
</script>

<Kanban {cards} {columns} init={attach} />
<button onclick={cleanup}>Remove logger</button>
  • on - register a handler with a tag for later detaching
  • intercept - register an interceptor with a tag