[PoC] Fix context API for web components

When nesting web components, the parent component link is currently not set up correctly. With this change, every parent node will be checked for having the SvelteElement constructor in its prototype chain. This can likely be optimized further by checking for the $$ component first.
pull/7069/head
Joerg Sonnenberger 5 years ago committed by GitHub
parent 99a04c464d
commit d4ad191adb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -104,8 +104,24 @@ function make_dirty(component, i) {
component.$$.dirty[(i / 31) | 0] |= (1 << (i % 31));
}
export function init(component, options, instance, create_fragment, not_equal, props, append_styles, dirty = [-1]) {
const parent_component = current_component;
function is_svelte_element(component) {
while (component) {
if (component.constructor === SvelteElement)
return true;
component = Object.getPrototypeOf(component);
}
return false;
}
function find_containing_component(component) {
while (component && !is_svelte_element(component)) {
component = component.parentNode;
}
return component;
}
function init(component, options, instance, create_fragment, not_equal, props, append_styles, dirty = [-1]) {
const parent_component = options.customElement ? find_containing_component(component.parentNode) : current_component;
set_current_component(component);
const $$: T$$ = component.$$ = {

Loading…
Cancel
Save