@ -8,14 +8,6 @@ The `svelte` package exposes [lifecycle functions](/tutorial/onmount) and the [c
> EXPORT_SNIPPET: svelte#onMount
```js
onMount(callback: () => void)
```
```js
onMount(callback: () => () => void)
```
The `onMount` function schedules a callback to run as soon as the component has been mounted to the DOM. It must be called during the component's initialisation (but doesn't need to live _inside_ the component; it can be called from an external module).
`onMount` does not run inside a [server-side component](/docs/server-side-component-api).
@ -52,10 +44,6 @@ If a function is returned from `onMount`, it will be called when the component i
> EXPORT_SNIPPET: svelte#beforeUpdate
```js
beforeUpdate(callback: () => void)
```
Schedules a callback to run immediately before the component is updated after any state change.
> The first time the callback runs will be before the initial `onMount`
@ -74,10 +62,6 @@ Schedules a callback to run immediately before the component is updated after an
> EXPORT_SNIPPET: svelte#afterUpdate
```js
afterUpdate(callback: () => void)
```
Schedules a callback to run immediately after the component has been updated.
> The first time the callback runs will be after the initial `onMount`
@ -96,10 +80,6 @@ Schedules a callback to run immediately after the component has been updated.
> EXPORT_SNIPPET: svelte#onDestroy
```js
onDestroy(callback: () => void)
```
Schedules a callback to run immediately before the component is unmounted.
Out of `onMount`, `beforeUpdate`, `afterUpdate` and `onDestroy`, this is the only one that runs inside a server-side component.
@ -118,10 +98,6 @@ Out of `onMount`, `beforeUpdate`, `afterUpdate` and `onDestroy`, this is the onl
> EXPORT_SNIPPET: svelte#tick
```js
promise = tick();
```
Returns a promise that resolves once any pending state changes have been applied, or in the next microtask if there are none.
```svelte
@ -140,12 +116,6 @@ Returns a promise that resolves once any pending state changes have been applied
> EXPORT_SNIPPET: svelte#setContext
<!-- TODO: Better typing information -->
```js
setContext(key: any, context: any)
```
Associates an arbitrary `context` object with the current component and the specified `key` and returns that object. The context is then available to children of the component (including slotted content) with `getContext`.
Like lifecycle functions, this must be called during component initialisation.
@ -164,10 +134,6 @@ Like lifecycle functions, this must be called during component initialisation.
> EXPORT_SNIPPET: svelte#getContext
```js
context: any = getContext(key: any)
```
Retrieves the context that belongs to the closest parent component with the specified `key`. Must be called during component initialisation.
```svelte
@ -182,10 +148,6 @@ Retrieves the context that belongs to the closest parent component with the spec
> EXPORT_SNIPPET: svelte#hasContext
```js
hasContext = hasContext(key: any)
```
Checks whether a given `key` has been set in the context of a parent component. Must be called during component initialisation.
```svelte
@ -202,10 +164,6 @@ Checks whether a given `key` has been set in the context of a parent component.
> EXPORT_SNIPPET: svelte#getAllContexts
```js
contexts: Map<any,any> = getAllContexts()
```
Retrieves the whole context map that belongs to the closest parent component. Must be called during component initialisation. Useful, for example, if you programmatically create a component and want to pass the existing context to it.
```svelte
@ -220,10 +178,6 @@ Retrieves the whole context map that belongs to the closest parent component. Mu
Creates an event dispatcher that can be used to dispatch [component events](/docs/component-directives#on-eventname). Event dispatchers are functions that can take two arguments: `name` and `detail`.
Component events created with `createEventDispatcher` create a [CustomEvent](https://developer.mozilla.org/en-US/docs/Web/API/CustomEvent). These events do not [bubble](https://developer.mozilla.org/en-US/docs/Learn/JavaScript/Building_blocks/Events#Event_bubbling_and_capture). The `detail` argument corresponds to the [CustomEvent.detail](https://developer.mozilla.org/en-US/docs/Web/API/CustomEvent/detail) property and can contain any type of data.
Function that creates a store which has values that can be set from 'outside' components. It gets created as an object with additional `set` and `update` methods.
`set` is a method that takes one argument which is the value to be set. The store value gets set to the value of the argument if the store value is not already equal to it.
@ -65,10 +57,6 @@ Note that the value of a `writable` is lost when it is destroyed, for example wh
Creates a store whose value cannot be set from 'outside', the first argument is the store's initial value, and the second argument to `readable` is the same as the second argument to `writable`.
Derives a store from one or more other stores. The callback runs initially when the first subscriber subscribes and then whenever the store dependencies change.
In the simplest version, `derived` takes a single store, and the callback returns a derived value.
This simple helper function makes a store readonly. You can still subscribe to the changes from the original one using this new readable store.
```js
@ -191,7 +159,7 @@ readableStore.set(2); // ERROR
> EXPORT_SNIPPET: svelte/store#get
```js
value: any = get(store);
declare function get<T>(store: Readable<T>): T;
```
Generally, you should read the value of a store by subscribing to it and using the value as it changes over time. Occasionally, you may need to retrieve the value of a store to which you're not subscribed. `get` allows you to do so.
@ -8,10 +8,6 @@ The `svelte/motion` module exports two functions, `tweened` and `spring`, for cr
> EXPORT_SNIPPET: svelte/motion#tweened
```js
store = tweened(value: any, options)
```
Tweened stores update their values over a fixed duration. The following options are available:
- `delay` (`number`, default 0) — milliseconds before starting
@ -85,10 +81,6 @@ The `interpolate` option allows you to tween between _any_ arbitrary values. It
> EXPORT_SNIPPET: svelte/motion#spring
```js
store = spring(value: any, options)
```
A `spring` store gradually changes to its target value based on its `stiffness` and `damping` parameters. Whereas `tweened` stores change their values over a fixed duration, `spring` stores change over a duration that is determined by their existing velocity, allowing for more natural-seeming motion in many situations. The following options are available:
- `stiffness` (`number`, default `0.15`) — a value between 0 and 1 where higher means a 'tighter' spring