diff --git a/src/compiler/compile/render_dom/wrappers/shared/add_actions.ts b/src/compiler/compile/render_dom/wrappers/shared/add_actions.ts index 9b5ce7a147..3d8c4fbbc0 100644 --- a/src/compiler/compile/render_dom/wrappers/shared/add_actions.ts +++ b/src/compiler/compile/render_dom/wrappers/shared/add_actions.ts @@ -29,7 +29,7 @@ export function add_action(block: Block, target: string, action: Action) { const fn = block.renderer.reference(action.name); block.event_listeners.push( - x`@destroy_action(${id} = ${fn}.call(null, ${target}, ${snippet}))` + x`@action_destroyer(${id} = ${fn}.call(null, ${target}, ${snippet}))` ); if (dependencies && dependencies.length > 0) { diff --git a/src/runtime/internal/utils.ts b/src/runtime/internal/utils.ts index 227454039c..c94a135869 100644 --- a/src/runtime/internal/utils.ts +++ b/src/runtime/internal/utils.ts @@ -122,10 +122,6 @@ export function set_store_value(store, ret, value = ret) { export const has_prop = (obj, prop) => Object.prototype.hasOwnProperty.call(obj, prop); -export function destroy_action(action_result) { - return () => { - if (action_result && is_function(action_result.destroy)) { - return action_result.destroy(); - } - }; +export function action_destroyer(action_result) { + return action_result && is_function(action_result.destroy) ? action_result.destroy : noop; } \ No newline at end of file diff --git a/test/js/samples/action-custom-event-handler/expected.js b/test/js/samples/action-custom-event-handler/expected.js index 0f5d85804c..da42603895 100644 --- a/test/js/samples/action-custom-event-handler/expected.js +++ b/test/js/samples/action-custom-event-handler/expected.js @@ -1,7 +1,7 @@ /* generated by Svelte vX.Y.Z */ import { SvelteComponent, - destroy_action, + action_destroyer, detach, element, init, @@ -20,7 +20,7 @@ function create_fragment(ctx) { c() { button = element("button"); button.textContent = "foo"; - dispose = destroy_action(foo_action = foo.call(null, button, /*foo_function*/ ctx[1])); + dispose = action_destroyer(foo_action = foo.call(null, button, /*foo_function*/ ctx[1])); }, m(target, anchor) { insert(target, button, anchor); @@ -42,7 +42,7 @@ function handleFoo(bar) { } function foo(node, callback) { - + } function instance($$self, $$props, $$invalidate) { diff --git a/test/js/samples/action/expected.js b/test/js/samples/action/expected.js index fe5d0824a0..dc3ebb5cf8 100644 --- a/test/js/samples/action/expected.js +++ b/test/js/samples/action/expected.js @@ -1,8 +1,8 @@ /* generated by Svelte vX.Y.Z */ import { SvelteComponent, + action_destroyer, attr, - destroy_action, detach, element, init, @@ -21,7 +21,7 @@ function create_fragment(ctx) { a = element("a"); a.textContent = "Test"; attr(a, "href", "#"); - dispose = destroy_action(link_action = link.call(null, a)); + dispose = action_destroyer(link_action = link.call(null, a)); }, m(target, anchor) { insert(target, a, anchor);