pull/3349/head
Maxim Matyunin 6 years ago
parent 4e004fdfa3
commit 73321465c1

@ -17,7 +17,7 @@ export default class EventHandler extends Node {
constructor(component: Component, parent, template_scope, info) { constructor(component: Component, parent, template_scope, info) {
super(component, parent, template_scope, info); super(component, parent, template_scope, info);
this.name = info.name; this.name = info.name !== '*' ? info.name : 'any';
this.modifiers = new Set(info.modifiers); this.modifiers = new Set(info.modifiers);
if (info.expression) { if (info.expression) {

@ -45,6 +45,7 @@ export default class Block {
}; };
event_listeners: string[] = []; event_listeners: string[] = [];
any_event_elements: string[] = [];
maintain_context: boolean; maintain_context: boolean;
has_animation: boolean; has_animation: boolean;
@ -325,6 +326,20 @@ export default class Block {
`); `);
} }
if (this.variables.size > 0) {
const listens = Array.from(this.variables.keys())
.filter(key => this.any_event_elements.includes(key))
.join(', ');
if (listens.length > 0) {
properties.add_block(deindent`
${method_name('bbl', 'bubble')}() {
return [listen, [${listens}]];
},
`);
}
}
if (this.has_intro_method || this.has_outro_method) { if (this.has_intro_method || this.has_outro_method) {
if (this.builders.intro.is_empty()) { if (this.builders.intro.is_empty()) {
properties.add_line(`i: @noop,`); properties.add_line(`i: @noop,`);

@ -21,6 +21,12 @@ export default function add_event_handlers(
block.event_listeners.push( block.event_listeners.push(
`@listen(${target}, "${handler.name}", ${snippet}, ${opts_string})` `@listen(${target}, "${handler.name}", ${snippet}, ${opts_string})`
); );
} else if (handler.name === 'any') {
block.any_event_elements.push(target);
// This isn't required but listen is treeshaken otherwise
block.event_listeners.push(
`@listen(${target}, "${handler.name}", ${snippet})`
);
} else { } else {
block.event_listeners.push( block.event_listeners.push(
`@listen(${target}, "${handler.name}", ${snippet})` `@listen(${target}, "${handler.name}", ${snippet})`

@ -43,6 +43,16 @@ export function mount_component(component, target, anchor) {
run_all(new_on_destroy); run_all(new_on_destroy);
} }
component.$$.on_mount = []; component.$$.on_mount = [];
if (fragment.bbl) {
Object.keys(component.$$.callbacks).forEach(type => {
if (!component.$$.ctx[`${type}_handler`]) {
const [listen, els] = fragment.bbl();
els.forEach(el => component.$$.callbacks[type].forEach(cb => listen(el, type, cb)));
}
});
}
}); });
after_update.forEach(add_render_callback); after_update.forEach(add_render_callback);

Loading…
Cancel
Save