@ -34,6 +34,7 @@ interface T$$ {
on_mount : any [ ] ;
on_mount : any [ ] ;
on_destroy : any [ ] ;
on_destroy : any [ ] ;
skip_bound : boolean ;
skip_bound : boolean ;
on_disconnect : any [ ] ;
}
}
export function bind ( component , name , callback ) {
export function bind ( component , name , callback ) {
@ -52,13 +53,15 @@ export function claim_component(block, parent_nodes) {
block && block . l ( parent_nodes ) ;
block && block . l ( parent_nodes ) ;
}
}
export function mount_component ( component , target , anchor ) {
export function mount_component ( component , target , anchor , customElement ) {
const { fragment , on_mount , on_destroy , after_update } = component . $ $ ;
const { fragment , on_mount , on_destroy , after_update } = component . $ $ ;
fragment && fragment . m ( target , anchor ) ;
fragment && fragment . m ( target , anchor ) ;
if ( ! customElement ) {
// onMount happens before the initial afterUpdate
// onMount happens before the initial afterUpdate
add_render_callback ( ( ) = > {
add_render_callback ( ( ) = > {
const new_on_destroy = on_mount . map ( run ) . filter ( is_function ) ;
const new_on_destroy = on_mount . map ( run ) . filter ( is_function ) ;
if ( on_destroy ) {
if ( on_destroy ) {
on_destroy . push ( . . . new_on_destroy ) ;
on_destroy . push ( . . . new_on_destroy ) ;
@ -69,6 +72,7 @@ export function mount_component(component, target, anchor) {
}
}
component . $ $ . on_mount = [ ] ;
component . $ $ . on_mount = [ ] ;
} ) ;
} ) ;
}
after_update . forEach ( add_render_callback ) ;
after_update . forEach ( add_render_callback ) ;
}
}
@ -113,6 +117,7 @@ export function init(component, options, instance, create_fragment, not_equal, p
// lifecycle
// lifecycle
on_mount : [ ] ,
on_mount : [ ] ,
on_destroy : [ ] ,
on_destroy : [ ] ,
on_disconnect : [ ] ,
before_update : [ ] ,
before_update : [ ] ,
after_update : [ ] ,
after_update : [ ] ,
context : new Map ( parent_component ? parent_component . $ $ . context : [ ] ) ,
context : new Map ( parent_component ? parent_component . $ $ . context : [ ] ) ,
@ -155,7 +160,7 @@ export function init(component, options, instance, create_fragment, not_equal, p
}
}
if ( options . intro ) transition_in ( component . $ $ . fragment ) ;
if ( options . intro ) transition_in ( component . $ $ . fragment ) ;
mount_component ( component , options . target , options . anchor );
mount_component ( component , options . target , options . anchor , options . customElement );
flush ( ) ;
flush ( ) ;
}
}
@ -173,6 +178,9 @@ if (typeof HTMLElement === 'function') {
}
}
connectedCallback() {
connectedCallback() {
const { on_mount } = this . $ $ ;
this . $ $ . on_disconnect = on_mount . map ( run ) . filter ( is_function ) ;
// @ts-ignore todo: improve typings
// @ts-ignore todo: improve typings
for ( const key in this . $ $ . slotted ) {
for ( const key in this . $ $ . slotted ) {
// @ts-ignore todo: improve typings
// @ts-ignore todo: improve typings
@ -184,6 +192,10 @@ if (typeof HTMLElement === 'function') {
this [ attr ] = newValue ;
this [ attr ] = newValue ;
}
}
disconnectedCallback() {
run_all ( this . $ $ . on_disconnect ) ;
}
$destroy() {
$destroy() {
destroy_component ( this , 1 ) ;
destroy_component ( this , 1 ) ;
this . $destroy = noop ;
this . $destroy = noop ;