setNext
Appends a handler to the end of the event bus chain so it receives every dispatched action after the built-in handlers run. RestDataProvider uses this method to connect to the kanban: it registers its REST handlers as the "next" link in the chain and forwards card mutations to the backend.
Usage
setNext(handler: any): any;
The handler is typically an object with its own action-handling methods (like the one returned by RestDataProvider). Returns the passed handler.
Every dispatched action passes through the chain in this order:
- The store applies the action.
- The
EventBusRoutercalls the matching hoston{action}prop, such asonmovecard. - Handlers added with
setNextrun in the order they were added.
Adding a handler doesn't replace the on{action} props. They keep firing before the handler. If the store rejects an action, for example a move-card to an unknown column, the action isn't forwarded: neither the on{action} props nor the setNext handlers receive it.
Example
Attaching a REST data provider:
<script>
import { Kanban, RestDataProvider } from "@svar-ui/svelte-kanban";
const url = "https://api.example.com";
const provider = new RestDataProvider(url);
let cards = $state([]);
async function init(api) {
api.setNext(provider);
cards = await provider.getData();
}
</script>
<Kanban {cards} {columns} {init} />
Related
- Working with server - REST persistence and dynamic loading
- RestDataProvider - the built-in REST provider wired via setNext
- init - callback where setNext is typically called