Skip to content

Commit 6e5523c

Browse files
committed
Revert "fix handler in-place"
This reverts commit 6ebf46a.
1 parent e585ccf commit 6e5523c

File tree

3 files changed

+10
-18
lines changed

3 files changed

+10
-18
lines changed

src/generators/nodes/Element.ts

+8-8
Original file line numberDiff line numberDiff line change
@@ -516,16 +516,16 @@ export default class Element extends Node {
516516
});
517517
`);
518518

519-
520-
block.builders.hydrate.addBlock(deindent`
521-
if (${handlerName}.teardown) {
522-
${handlerName}.destroy = ${handlerName}.teardown;
523-
${generator.options.dev && `console.warn("Return 'destroy()' from custom event handlers. Returning 'teardown()' has been deprecated and will be unsupported in Svelte 2");`}
524-
}
525-
`);
519+
if (generator.options.dev) {
520+
block.builders.hydrate.addBlock(deindent`
521+
if (${handlerName}.teardown) {
522+
console.warn("Return 'destroy()' from custom event handlers. Returning 'teardown()' has been deprecated and will be unsupported in Svelte 2");
523+
}
524+
`);
525+
}
526526

527527
block.builders.destroy.addLine(deindent`
528-
${handlerName}.destroy();
528+
${handlerName}[${handlerName}.destroy ? 'destroy' : 'teardown']();
529529
`);
530530
} else {
531531
const handler = deindent`

test/js/samples/event-handlers-custom/expected-bundle.js

+1-5
Original file line numberDiff line numberDiff line change
@@ -199,10 +199,6 @@ function create_main_fragment(component, state) {
199199
var state = component.get();
200200
component.foo( state.bar );
201201
});
202-
203-
if (foo_handler.teardown) {
204-
foo_handler.destroy = foo_handler.teardown;
205-
}
206202
},
207203

208204
m: function mount(target, anchor) {
@@ -216,7 +212,7 @@ function create_main_fragment(component, state) {
216212
},
217213

218214
d: function destroy$$1() {
219-
foo_handler.destroy();
215+
foo_handler[foo_handler.destroy ? 'destroy' : 'teardown']();
220216
}
221217
};
222218
}

test/js/samples/event-handlers-custom/expected.js

+1-5
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,6 @@ function create_main_fragment(component, state) {
2626
var state = component.get();
2727
component.foo( state.bar );
2828
});
29-
30-
if (foo_handler.teardown) {
31-
foo_handler.destroy = foo_handler.teardown;
32-
}
3329
},
3430

3531
m: function mount(target, anchor) {
@@ -43,7 +39,7 @@ function create_main_fragment(component, state) {
4339
},
4440

4541
d: function destroy() {
46-
foo_handler.destroy();
42+
foo_handler[foo_handler.destroy ? 'destroy' : 'teardown']();
4743
}
4844
};
4945
}

0 commit comments

Comments
 (0)