UNPKG

@soleil-se/app-util

Version:

Utility functions for WebApps, RESTApps and Widgets in Sitevision.

31 lines (29 loc) 1.06 kB
import { setAppProps } from '../../../common'; /** @typedef {import('svelte').SvelteComponent} Component */ /** * Renders a client side Svelte application. * @param {Component} App Svelte app root component. * @param {object} [settings={}] Settings object. * @param {HTMLElement} [settings.target] Target where app should be mounted. * @param {object} [settings.props] Root component props. * @param {boolean} [settings.hydrate=target.hasChildNodes()] Instructs Svelte to upgrade existing * DOM (usually from server-side rendering) rather than creating new elements. By default the app * will hydrate when the target has any child nodes. * @param {boolean} [settings.intro=false] If true, will play transitions on initial render, * rather than waiting for subsequent state changes. * @return {Component} Initialized Svelte component. */ export function render(App, { target, props, intro = false, hydrate = target.hasChildNodes(), } = {}) { setAppProps(props); return new App({ hydrate, target, props, intro, }); }