@ -10,7 +10,7 @@ import {
} from './dom/operations.js' ;
import { HYDRATION _END , HYDRATION _ERROR , HYDRATION _START } from '../../constants.js' ;
import { push , pop , component _context , active _effect } from './runtime.js' ;
import { effec t_root , branch } from './reactivity/effects.js' ;
import { componen t_root , branch } from './reactivity/effects.js' ;
import {
hydrate _next ,
hydrate _node ,
@ -204,7 +204,7 @@ function _mount(Component, { target, anchor, props = {}, events, context, intro
// @ts-expect-error will be defined because the render effect runs synchronously
var component = undefined ;
var unmount = effec t_root ( ( ) => {
var unmount = componen t_root ( ( ) => {
var anchor _node = anchor ? ? target . appendChild ( create _text ( ) ) ;
branch ( ( ) => {
@ -252,7 +252,7 @@ function _mount(Component, { target, anchor, props = {}, events, context, intro
}
root _event _handles . delete ( event _handle ) ;
mounted _components . delete ( component ) ;
if ( anchor _node !== anchor ) {
anchor _node . parentNode ? . removeChild ( anchor _node ) ;
}
@ -271,14 +271,35 @@ let mounted_components = new WeakMap();
/ * *
* Unmounts a component that was previously mounted using ` mount ` or ` hydrate ` .
*
* If ` options.outro ` is ` true ` , [ transitions ] ( https : //svelte.dev/docs/svelte/transition) will play before the component is removed from the DOM.
*
* Returns a ` Promise ` that resolves after transitions have completed if ` options.outro ` is true , or immediately otherwise .
*
* ` ` ` js
* import { mount , unmount } from 'svelte' ;
* import App from './App.svelte' ;
*
* const app = mount ( App , { target : document . body } ) ;
*
* // later...
* unmount ( app , { outro : true } ) ;
* ` ` `
* @ param { Record < string , any > } component
* @ param { { outro ? : boolean } } [ options ]
* @ returns { Promise < void > }
* /
export function unmount ( component ) {
export function unmount ( component , options ) {
const fn = mounted _components . get ( component ) ;
if ( fn ) {
fn ( ) ;
} else if ( DEV ) {
mounted _components . delete ( component ) ;
return fn ( options ) ;
}
if ( DEV ) {
w . lifecycle _double _unmount ( ) ;
}
return Promise . resolve ( ) ;
}