diff --git a/src/compiler/compile/nodes/InlineComponent.ts b/src/compiler/compile/nodes/InlineComponent.ts index a7bc986e9b..e969ab6e25 100644 --- a/src/compiler/compile/nodes/InlineComponent.ts +++ b/src/compiler/compile/nodes/InlineComponent.ts @@ -126,7 +126,7 @@ export default class InlineComponent extends Node { slot_template.attributes.push(attribute); } } - + children.push(slot_template); info.children.splice(i, 1); } diff --git a/src/compiler/compile/render_dom/index.ts b/src/compiler/compile/render_dom/index.ts index 89af0c297c..126222f803 100644 --- a/src/compiler/compile/render_dom/index.ts +++ b/src/compiler/compile/render_dom/index.ts @@ -444,7 +444,7 @@ export default function dom( unknown_props_check = b` const writable_props = [${writable_props.map(prop => x`'${prop.export_name}'`)}]; @_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}'\`); }); `; } diff --git a/src/runtime/internal/Component.ts b/src/runtime/internal/Component.ts index 3e48010547..c3aabdfbd0 100644 --- a/src/runtime/internal/Component.ts +++ b/src/runtime/internal/Component.ts @@ -237,6 +237,13 @@ if (typeof HTMLElement === 'function') { export class SvelteComponent { $$: T$$; $$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_component(this, 1); diff --git a/src/runtime/internal/dev.ts b/src/runtime/internal/dev.ts index 76d68086c8..c103bf4d25 100644 --- a/src/runtime/internal/dev.ts +++ b/src/runtime/internal/dev.ts @@ -155,7 +155,7 @@ export class SvelteComponentDev extends SvelteComponent { throw new Error("'target' is a required option"); } - super(); + super(options); } $destroy() { diff --git a/src/runtime/internal/lifecycle.ts b/src/runtime/internal/lifecycle.ts index bb3df3d295..a176ce7701 100644 --- a/src/runtime/internal/lifecycle.ts +++ b/src/runtime/internal/lifecycle.ts @@ -34,6 +34,7 @@ export function createEventDispatcher< return (type: string, detail?: any) => { const callbacks = component.$$.callbacks[type]; + const eventBinding = component.eventBindings && component.eventBindings.hasOwnProperty(type) ? component.eventBindings[type] : undefined; if (callbacks) { // TODO are there situations where events could be dispatched @@ -43,6 +44,12 @@ export function createEventDispatcher< fn.call(component, event); }); } + + if (eventBinding) { + // in a server (non-DOM) environment? + const event = custom_event(type, detail); + eventBinding.call(component, event); + } }; } @@ -59,7 +66,7 @@ export function getAllContexts = Map>(): T { } export function hasContext(key): boolean { - return get_current_component().$$.context.has(key); + return get_current_component().$$.context.has(key); } // TODO figure out if we still want to support