// Copyright: Ankitects Pty Ltd and contributors // License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html import { truthy } from "../lib/functional"; interface ActionReturn

{ destroy?(): void; update?(params: P): void; } type Action = ( element: E, params: P, ) => ActionReturn

| void; /** * A helper function for treating a list of Svelte actions as a single Svelte action * and use it with a single `use:` directive */ function actionList(actions: Action[]): Action { return function action(element: E, params: P): ActionReturn

| void { const results = actions.map((action) => action(element, params)).filter(truthy); return { update(params: P) { for (const { update } of results) { update?.(params); } }, destroy() { for (const { destroy } of results) { destroy?.(); } }, }; }; } export default actionList;