pull/8356/head
adiguba 4 years ago
parent 402ef4d503
commit c2d91137cd

@ -402,6 +402,10 @@ export default class InlineComponentWrapper extends Wrapper {
if (this.node.handlers.length > 0) {
const target = x`${name}`;
if (component.compile_options.dev) {
/* Hook for restoring handlers on components after HMR */
munged_bindings.push(b`@fix_callbacks_hmr_dev(${target})`);
}
for (const handler of this.node.handlers) {
new EventHandler(handler, this)
.render(block, target, true);

@ -1,7 +1,7 @@
import { custom_event, append, append_hydration, insert, insert_hydration, detach, listen, attr, prevent_default, stop_propagation, trusted, self, stop_immediate_propagation } from './dom';
import { SvelteComponent } from './Component';
import { is_void } from '../../shared/utils/names';
import { bubble, listen_comp } from './lifecycle';
import { bubble, listen_comp, restart_all_callback } from './lifecycle';
export function dispatch_dev<T=any>(type: string, detail?: T) {
document.dispatchEvent(custom_event(type, { version: '__VERSION__', ...detail }, { bubbles: true }));
@ -94,6 +94,13 @@ export function listen_comp_dev(comp: SvelteComponent, event: string, handler: E
};
}
/* Hook for restarting callbacks after HMR */
export function fix_callbacks_hmr_dev(comp: any) {
comp.$$.on_hmr && comp.$$.on_hmr.push( (_: any) => {
return (c: SvelteComponent) => restart_all_callback(c);
});
}
export function attr_dev(node: Element, attribute: string, value?: string) {
attr(node, attribute, value);

Loading…
Cancel
Save