Home / File/ utils.js — svelte Source File

utils.js — svelte Source File

Architecture documentation for utils.js, a javascript file in the svelte codebase. 3 imports, 3 dependents.

File javascript SharedInternal DOMUtils 3 imports 3 dependents 1 functions

Entity Profile

Dependency Diagram

graph LR
  dacfcaf1_66cb_9fe3_083b_4fee2b4eb64f["utils.js"]
  717fc8d5_bdb4_4b73_d6c5_c4a367a60cf2["index-client.js"]
  dacfcaf1_66cb_9fe3_083b_4fee2b4eb64f --> 717fc8d5_bdb4_4b73_d6c5_c4a367a60cf2
  cb946435_ce66_d1e8_6bee_287bdb07e7c5["utils.js"]
  dacfcaf1_66cb_9fe3_083b_4fee2b4eb64f --> cb946435_ce66_d1e8_6bee_287bdb07e7c5
  fa007f2b_f437_c5ef_5c2d_ea8b5902500f["noop"]
  dacfcaf1_66cb_9fe3_083b_4fee2b4eb64f --> fa007f2b_f437_c5ef_5c2d_ea8b5902500f
  49e6453b_f889_68d3_168f_19a644745ce8["store.js"]
  49e6453b_f889_68d3_168f_19a644745ce8 --> dacfcaf1_66cb_9fe3_083b_4fee2b4eb64f
  1c4bc493_24af_177e_7307_a999997aceac["index.js"]
  1c4bc493_24af_177e_7307_a999997aceac --> dacfcaf1_66cb_9fe3_083b_4fee2b4eb64f
  b874f390_a6ee_7d84_7151_b2b77f0388d5["index.js"]
  b874f390_a6ee_7d84_7151_b2b77f0388d5 --> dacfcaf1_66cb_9fe3_083b_4fee2b4eb64f
  style dacfcaf1_66cb_9fe3_083b_4fee2b4eb64f fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

/** @import { Readable } from './public' */
import { untrack } from '../index-client.js';
import { noop } from '../internal/shared/utils.js';

/**
 * @template T
 * @param {Readable<T> | null | undefined} store
 * @param {(value: T) => void} run
 * @param {(value: T) => void} [invalidate]
 * @returns {() => void}
 */
export function subscribe_to_store(store, run, invalidate) {
	if (store == null) {
		// @ts-expect-error
		run(undefined);

		// @ts-expect-error
		if (invalidate) invalidate(undefined);

		return noop;
	}

	// Svelte store takes a private second argument
	// StartStopNotifier could mutate state, and we want to silence the corresponding validation error
	const unsub = untrack(() =>
		store.subscribe(
			run,
			// @ts-expect-error
			invalidate
		)
	);

	// Also support RxJS
	// @ts-expect-error TODO fix this in the types?
	return unsub.unsubscribe ? () => unsub.unsubscribe() : unsub;
}

Subdomains

Frequently Asked Questions

What does utils.js do?
utils.js is a source file in the svelte codebase, written in javascript. It belongs to the SharedInternal domain, DOMUtils subdomain.
What functions are defined in utils.js?
utils.js defines 1 function(s): subscribe_to_store.
What does utils.js depend on?
utils.js imports 3 module(s): index-client.js, noop, utils.js.
What files import utils.js?
utils.js is imported by 3 file(s): index.js, index.js, store.js.
Where is utils.js in the architecture?
utils.js is located at packages/svelte/src/store/utils.js (domain: SharedInternal, subdomain: DOMUtils, directory: packages/svelte/src/store).

Analyze Your Own Codebase

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

Try Supermodel Free