mirror of https://github.com/sveltejs/svelte
replace <svelte:document> with <svelte:body> (#1846)
parent
88b6a26a35
commit
f8d69e296f
@ -1,8 +1,8 @@
|
||||
import Node from './shared/Node';
|
||||
import EventHandler from './EventHandler';
|
||||
|
||||
export default class Document extends Node {
|
||||
type: 'Document';
|
||||
export default class Body extends Node {
|
||||
type: 'Body';
|
||||
handlers: EventHandler[];
|
||||
|
||||
constructor(component, parent, scope, info) {
|
@ -1,21 +1,21 @@
|
||||
import Block from '../Block';
|
||||
import Wrapper from './shared/Wrapper';
|
||||
import deindent from '../../../utils/deindent';
|
||||
import Document from '../../nodes/Document';
|
||||
import Body from '../../nodes/Body';
|
||||
|
||||
export default class DocumentWrapper extends Wrapper {
|
||||
node: Document;
|
||||
export default class BodyWrapper extends Wrapper {
|
||||
node: Body;
|
||||
|
||||
render(block: Block, parentNode: string, parentNodes: string) {
|
||||
this.node.handlers.forEach(handler => {
|
||||
const snippet = handler.render(block);
|
||||
|
||||
block.builders.init.addBlock(deindent`
|
||||
document.addEventListener("${handler.name}", ${snippet});
|
||||
document.body.addEventListener("${handler.name}", ${snippet});
|
||||
`);
|
||||
|
||||
block.builders.destroy.addBlock(deindent`
|
||||
document.removeEventListener("${handler.name}", ${snippet});
|
||||
document.body.removeEventListener("${handler.name}", ${snippet});
|
||||
`);
|
||||
});
|
||||
}
|
@ -1,13 +1,13 @@
|
||||
export default {
|
||||
test({ assert, component, target, window }) {
|
||||
test({ assert, component, window }) {
|
||||
assert.deepEqual(component.events, []);
|
||||
|
||||
const event1 = new window.Event('mouseenter');
|
||||
window.document.dispatchEvent(event1);
|
||||
window.document.body.dispatchEvent(event1);
|
||||
assert.deepEqual(component.events, ['enter']);
|
||||
|
||||
const event2 = new window.Event('mouseleave');
|
||||
window.document.dispatchEvent(event2);
|
||||
window.document.body.dispatchEvent(event2);
|
||||
assert.deepEqual(component.events, ['enter', 'leave']);
|
||||
},
|
||||
};
|
Loading…
Reference in new issue