added spread operator event bindings

pull/6875/head
Tom Shaw 5 years ago
parent b8efbb4cca
commit 8e8e8dabaf

@ -444,7 +444,7 @@ export default function dom(
unknown_props_check = b` unknown_props_check = b`
const writable_props = [${writable_props.map(prop => x`'${prop.export_name}'`)}]; const writable_props = [${writable_props.map(prop => x`'${prop.export_name}'`)}];
@_Object.keys($$props).forEach(key => { @_Object.keys($$props).forEach(key => {
if (!~writable_props.indexOf(key) && key.slice(0, 2) !== '$$' && key !== 'slot') @_console.warn(\`<${component.tag}> was created with unknown prop '\${key}'\`); if (!~writable_props.indexOf(key) && key.slice(0, 2) !== '$$' && key !== 'slot' && key !== 'event:bindings') @_console.warn(\`<${component.tag}> was created with unknown prop '\${key}'\`);
}); });
`; `;
} }

@ -237,6 +237,13 @@ if (typeof HTMLElement === 'function') {
export class SvelteComponent { export class SvelteComponent {
$$: T$$; $$: T$$;
$$set?: ($$props: any) => void; $$set?: ($$props: any) => void;
eventBindings: any;
constructor(props) {
if (props && props.props && Object.prototype.hasOwnProperty.call(props.props, 'event:bindings')) {
this.eventBindings = props.props['event:bindings'];
}
}
$destroy() { $destroy() {
destroy_component(this, 1); destroy_component(this, 1);

@ -155,7 +155,7 @@ export class SvelteComponentDev extends SvelteComponent {
throw new Error("'target' is a required option"); throw new Error("'target' is a required option");
} }
super(); super(options);
} }
$destroy() { $destroy() {

@ -34,6 +34,7 @@ export function createEventDispatcher<
return (type: string, detail?: any) => { return (type: string, detail?: any) => {
const callbacks = component.$$.callbacks[type]; const callbacks = component.$$.callbacks[type];
const eventBinding = component.eventBindings && component.eventBindings.hasOwnProperty(type) ? component.eventBindings[type] : undefined;
if (callbacks) { if (callbacks) {
// TODO are there situations where events could be dispatched // TODO are there situations where events could be dispatched
@ -43,6 +44,12 @@ export function createEventDispatcher<
fn.call(component, event); fn.call(component, event);
}); });
} }
if (eventBinding) {
// in a server (non-DOM) environment?
const event = custom_event(type, detail);
eventBinding.call(component, event);
}
}; };
} }

Loading…
Cancel
Save