Home / Class/ Spring Class — svelte Architecture

Spring Class — svelte Architecture

Architecture documentation for the Spring class in public.d.ts from the svelte codebase.

Entity Profile

Dependency Diagram

graph TD
  7d3f67e7_55ba_e151_bb80_517480adf36f["Spring"]
  9a4c629d_1cfd_8602_0675_d0dd3a38ce22["public.d.ts"]
  7d3f67e7_55ba_e151_bb80_517480adf36f -->|defined in| 9a4c629d_1cfd_8602_0675_d0dd3a38ce22
  2449df17_af68_a685_9124_2eaf54109901["constructor()"]
  7d3f67e7_55ba_e151_bb80_517480adf36f -->|method| 2449df17_af68_a685_9124_2eaf54109901
  cccc022e_a1ed_6704_8af4_44139ad670a4["of()"]
  7d3f67e7_55ba_e151_bb80_517480adf36f -->|method| cccc022e_a1ed_6704_8af4_44139ad670a4
  8cebec67_db1e_e302_30ba_b19cddfedf97["set()"]
  7d3f67e7_55ba_e151_bb80_517480adf36f -->|method| 8cebec67_db1e_e302_30ba_b19cddfedf97
  2626ac08_f079_0474_f26e_cfd1e2ef7bf3["current()"]
  7d3f67e7_55ba_e151_bb80_517480adf36f -->|method| 2626ac08_f079_0474_f26e_cfd1e2ef7bf3

Relationship Graph

Source Code

packages/svelte/src/motion/public.d.ts lines 39–81

export class Spring<T> {
	constructor(value: T, options?: SpringOpts);

	/**
	 * Create a spring whose value is bound to the return value of `fn`. This must be called
	 * inside an effect root (for example, during component initialisation).
	 *
	 * ```svelte
	 * <script>
	 * 	import { Spring } from 'svelte/motion';
	 *
	 * 	let { number } = $props();
	 *
	 * 	const spring = Spring.of(() => number);
	 * </script>
	 * ```
	 */
	static of<U>(fn: () => U, options?: SpringOpts): Spring<U>;

	/**
	 * Sets `spring.target` to `value` and returns a `Promise` that resolves if and when `spring.current` catches up to it.
	 *
	 * If `options.instant` is `true`, `spring.current` immediately matches `spring.target`.
	 *
	 * If `options.preserveMomentum` is provided, the spring will continue on its current trajectory for
	 * the specified number of milliseconds. This is useful for things like 'fling' gestures.
	 */
	set(value: T, options?: SpringUpdateOpts): Promise<void>;

	damping: number;
	precision: number;
	stiffness: number;
	/**
	 * The end value of the spring.
	 * This property only exists on the `Spring` class, not the legacy `spring` store.
	 */
	target: T;
	/**
	 * The current value of the spring.
	 * This property only exists on the `Spring` class, not the legacy `spring` store.
	 */
	get current(): T;
}

Frequently Asked Questions

What is the Spring class?
Spring is a class in the svelte codebase, defined in packages/svelte/src/motion/public.d.ts.
Where is Spring defined?
Spring is defined in packages/svelte/src/motion/public.d.ts at line 39.

Analyze Your Own Codebase

Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.

Try Supermodel Free