File tree Expand file tree Collapse file tree 4 files changed +26
-12
lines changed
documentation/docs/06-runtime Expand file tree Collapse file tree 4 files changed +26
-12
lines changed Original file line number Diff line number Diff line change @@ -47,6 +47,8 @@ const app = mount(App, { target: document.body });
4747unmount (app, { outro: true });
4848```
4949
50+ Returns a ` Promise ` that resolves after transitions have completed if ` options.outro ` is true, or immediately otherwise.
51+
5052## ` render `
5153
5254Only available on the server and when compiling with the ` server ` option. Takes a component and returns an object with ` body ` and ` head ` properties on it, which you can use to populate the HTML when server-rendering your app:
Original file line number Diff line number Diff line change @@ -257,19 +257,23 @@ export function effect_root(fn) {
257257/**
258258 * An effect root whose children can transition out
259259 * @param {() => void } fn
260- * @returns {(options?: { outro?: boolean }) => void }
260+ * @returns {(options?: { outro?: boolean }) => Promise< void> }
261261 */
262262export function component_root ( fn ) {
263263 const effect = create_effect ( ROOT_EFFECT , fn , true ) ;
264264
265265 return ( options = { } ) => {
266- if ( options . outro ) {
267- pause_effect ( effect , ( ) => {
266+ return new Promise ( ( fulfil ) => {
267+ if ( options . outro ) {
268+ pause_effect ( effect , ( ) => {
269+ destroy_effect ( effect ) ;
270+ fulfil ( undefined ) ;
271+ } ) ;
272+ } else {
268273 destroy_effect ( effect ) ;
269- } ) ;
270- } else {
271- destroy_effect ( effect ) ;
272- }
274+ fulfil ( undefined ) ;
275+ }
276+ } ) ;
273277 } ;
274278}
275279
Original file line number Diff line number Diff line change @@ -274,6 +274,8 @@ let mounted_components = new WeakMap();
274274 *
275275 * If `options.outro` is `true`, [transitions](https://svelte.dev/docs/svelte/transition) will play before the component is removed from the DOM.
276276 *
277+ * Returns a `Promise` that resolves after transitions have completed if `options.outro` is true, or immediately otherwise.
278+ *
277279 * ```js
278280 * import { mount, unmount } from 'svelte';
279281 * import App from './App.svelte';
@@ -285,13 +287,18 @@ let mounted_components = new WeakMap();
285287 * ```
286288 * @param {Record<string, any> } component
287289 * @param {{ outro?: boolean } } [options]
290+ * @returns {Promise<void> }
288291 */
289292export function unmount ( component , options ) {
290293 const fn = mounted_components . get ( component ) ;
291294
292295 if ( fn ) {
293- fn ( options ) ;
294- } else if ( DEV ) {
296+ return fn ( options ) ;
297+ }
298+
299+ if ( DEV ) {
295300 w . lifecycle_double_unmount ( ) ;
296301 }
302+
303+ return Promise . resolve ( ) ;
297304}
Original file line number Diff line number Diff line change @@ -451,6 +451,8 @@ declare module 'svelte' {
451451 *
452452 * If `options.outro` is `true`, [transitions](https://svelte.dev/docs/svelte/transition) will play before the component is removed from the DOM.
453453 *
454+ * Returns a `Promise` that resolves after transitions have completed if `options.outro` is true, or immediately otherwise.
455+ *
454456 * ```js
455457 * import { mount, unmount } from 'svelte';
456458 * import App from './App.svelte';
@@ -460,11 +462,10 @@ declare module 'svelte' {
460462 * // later...
461463 * unmount(app, { outro: true });
462464 * ```
463- *
464- */
465+ * */
465466 export function unmount ( component : Record < string , any > , options ?: {
466467 outro ?: boolean ;
467- } | undefined ) : void ;
468+ } | undefined ) : Promise < void > ;
468469 /**
469470 * Returns a promise that resolves once any pending state changes have been applied.
470471 * */
You can’t perform that action at this time.
0 commit comments