Home / Function/ constructor() — svelte Function Reference

constructor() — svelte Function Reference

Architecture documentation for the constructor() function in legacy-client.js from the svelte codebase.

Entity Profile

Dependency Diagram

graph TD
  b72b8566_6fe5_6e9f_7848_f28f37253eff["constructor()"]
  4a6dd8eb_d702_b5bf_74e8_1b0f596492ee["Svelte4Component"]
  b72b8566_6fe5_6e9f_7848_f28f37253eff -->|defined in| 4a6dd8eb_d702_b5bf_74e8_1b0f596492ee
  0ce0b17f_0fc7_b361_b518_73a5de3f2e7a["create_custom_element()"]
  0ce0b17f_0fc7_b361_b518_73a5de3f2e7a -->|calls| b72b8566_6fe5_6e9f_7848_f28f37253eff
  75ae9027_9abc_8e62_0404_f3531b219452["asClassComponent()"]
  75ae9027_9abc_8e62_0404_f3531b219452 -->|calls| b72b8566_6fe5_6e9f_7848_f28f37253eff
  03788141_01d2_5299_6e22_4211e661afe4["mutable_source()"]
  b72b8566_6fe5_6e9f_7848_f28f37253eff -->|calls| 03788141_01d2_5299_6e22_4211e661afe4
  63ee8247_ada4_9f1d_e139_0c1167cd5b1c["set()"]
  b72b8566_6fe5_6e9f_7848_f28f37253eff -->|calls| 63ee8247_ada4_9f1d_e139_0c1167cd5b1c
  a08b6cc5_af73_1be4_d02f_3113cf8a8305["get()"]
  b72b8566_6fe5_6e9f_7848_f28f37253eff -->|calls| a08b6cc5_af73_1be4_d02f_3113cf8a8305
  5bc3c950_96f7_e454_6cb7_65ffc2179811["flushSync()"]
  b72b8566_6fe5_6e9f_7848_f28f37253eff -->|calls| 5bc3c950_96f7_e454_6cb7_65ffc2179811
  06f2307f_37db_1e25_c26b_19978071ccc7["unmount()"]
  b72b8566_6fe5_6e9f_7848_f28f37253eff -->|calls| 06f2307f_37db_1e25_c26b_19978071ccc7
  style b72b8566_6fe5_6e9f_7848_f28f37253eff fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

packages/svelte/src/legacy/legacy-client.js lines 80–154

	constructor(options) {
		var sources = new Map();

		/**
		 * @param {string | symbol} key
		 * @param {unknown} value
		 */
		var add_source = (key, value) => {
			var s = mutable_source(value, false, false);
			sources.set(key, s);
			return s;
		};

		// Replicate coarse-grained props through a proxy that has a version source for
		// each property, which is incremented on updates to the property itself. Do not
		// use our $state proxy because that one has fine-grained reactivity.
		const props = new Proxy(
			{ ...(options.props || {}), $$events: {} },
			{
				get(target, prop) {
					return get(sources.get(prop) ?? add_source(prop, Reflect.get(target, prop)));
				},
				has(target, prop) {
					// Necessary to not throw "invalid binding" validation errors on the component side
					if (prop === LEGACY_PROPS) return true;

					get(sources.get(prop) ?? add_source(prop, Reflect.get(target, prop)));
					return Reflect.has(target, prop);
				},
				set(target, prop, value) {
					set(sources.get(prop) ?? add_source(prop, value), value);
					return Reflect.set(target, prop, value);
				}
			}
		);

		this.#instance = (options.hydrate ? hydrate : mount)(options.component, {
			target: options.target,
			anchor: options.anchor,
			props,
			context: options.context,
			intro: options.intro ?? false,
			recover: options.recover
		});

		// We don't flushSync for custom element wrappers or if the user doesn't want it,
		// or if we're in async mode since `flushSync()` will fail
		if (!async_mode_flag && (!options?.props?.$$host || options.sync === false)) {
			flushSync();
		}

		this.#events = props.$$events;

		for (const key of Object.keys(this.#instance)) {
			if (key === '$set' || key === '$destroy' || key === '$on') continue;
			define_property(this, key, {
				get() {
					return this.#instance[key];
				},
				/** @param {any} value */
				set(value) {
					this.#instance[key] = value;
				},
				enumerable: true
			});
		}

		this.#instance.$set = /** @param {Record<string, any>} next */ (next) => {
			Object.assign(props, next);
		};

		this.#instance.$destroy = () => {
			unmount(this.#instance);
		};
	}

Subdomains

Frequently Asked Questions

What does constructor() do?
constructor() is a function in the svelte codebase, defined in packages/svelte/src/legacy/legacy-client.js.
Where is constructor() defined?
constructor() is defined in packages/svelte/src/legacy/legacy-client.js at line 80.
What does constructor() call?
constructor() calls 5 function(s): flushSync, get, mutable_source, set, unmount.
What calls constructor()?
constructor() is called by 2 function(s): asClassComponent, create_custom_element.

Analyze Your Own Codebase

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

Try Supermodel Free