Home / File/ inspect.js — svelte Source File

inspect.js — svelte Source File

Architecture documentation for inspect.js, a javascript file in the svelte codebase. 11 imports, 0 dependents.

File javascript ClientRuntime Hydration 11 imports 1 functions

Entity Profile

Dependency Diagram

graph LR
  2ee049d6_d6d3_ee9b_a2e1_010085c52b2c["inspect.js"]
  73865c3c_2786_c9ac_d34f_b51d28b3a29e["constants.js"]
  2ee049d6_d6d3_ee9b_a2e1_010085c52b2c --> 73865c3c_2786_c9ac_d34f_b51d28b3a29e
  258b696c_d923_7010_457a_b58908a057b0["clone.js"]
  2ee049d6_d6d3_ee9b_a2e1_010085c52b2c --> 258b696c_d923_7010_457a_b58908a057b0
  532a740d_d410_0fd6_983a_933cb13808e7["snapshot"]
  2ee049d6_d6d3_ee9b_a2e1_010085c52b2c --> 532a740d_d410_0fd6_983a_933cb13808e7
  1ae6fa4e_16ee_acdf_5e28_17eb0819fddb["effects.js"]
  2ee049d6_d6d3_ee9b_a2e1_010085c52b2c --> 1ae6fa4e_16ee_acdf_5e28_17eb0819fddb
  80b95503_e5bc_4965_f8d9_a5ec40e8e1c2["eager_effect"]
  2ee049d6_d6d3_ee9b_a2e1_010085c52b2c --> 80b95503_e5bc_4965_f8d9_a5ec40e8e1c2
  7494b934_a3b8_689e_91b6_8435e26461c5["render_effect"]
  2ee049d6_d6d3_ee9b_a2e1_010085c52b2c --> 7494b934_a3b8_689e_91b6_8435e26461c5
  b78cad2e_34cc_9fa8_80d7_78a1f69d3539["validate_effect"]
  2ee049d6_d6d3_ee9b_a2e1_010085c52b2c --> b78cad2e_34cc_9fa8_80d7_78a1f69d3539
  bde4209f_8ffc_1594_4024_b1835a44bcf6["runtime.js"]
  2ee049d6_d6d3_ee9b_a2e1_010085c52b2c --> bde4209f_8ffc_1594_4024_b1835a44bcf6
  a814b193_e12a_4037_c3c8_dfd45f3bd0bb["untrack"]
  2ee049d6_d6d3_ee9b_a2e1_010085c52b2c --> a814b193_e12a_4037_c3c8_dfd45f3bd0bb
  66d86b00_6f66_4791_e665_59e2cf45dc7f["dev.js"]
  2ee049d6_d6d3_ee9b_a2e1_010085c52b2c --> 66d86b00_6f66_4791_e665_59e2cf45dc7f
  cc46feba_170d_5970_a6be_f512f15aa0ee["get_error"]
  2ee049d6_d6d3_ee9b_a2e1_010085c52b2c --> cc46feba_170d_5970_a6be_f512f15aa0ee
  style 2ee049d6_d6d3_ee9b_a2e1_010085c52b2c fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

import { UNINITIALIZED } from '../../../constants.js';
import { snapshot } from '../../shared/clone.js';
import { eager_effect, render_effect, validate_effect } from '../reactivity/effects.js';
import { untrack } from '../runtime.js';
import { get_error } from '../../shared/dev.js';

/**
 * @param {() => any[]} get_value
 * @param {Function} inspector
 * @param {boolean} show_stack
 */
export function inspect(get_value, inspector, show_stack = false) {
	validate_effect('$inspect');

	let initial = true;
	let error = /** @type {any} */ (UNINITIALIZED);

	// Inspect effects runs synchronously so that we can capture useful
	// stack traces. As a consequence, reading the value might result
	// in an error (an `$inspect(object.property)` will run before the
	// `{#if object}...{/if}` that contains it)
	eager_effect(() => {
		try {
			var value = get_value();
		} catch (e) {
			error = e;
			return;
		}

		var snap = snapshot(value, true, true);
		untrack(() => {
			if (show_stack) {
				inspector(...snap);

				if (!initial) {
					const stack = get_error('$inspect(...)');
					if (stack) {
						// eslint-disable-next-line no-console
						console.groupCollapsed('stack trace');
						// eslint-disable-next-line no-console
						console.log(stack);
						// eslint-disable-next-line no-console
						console.groupEnd();
					}
				}
			} else {
				inspector(initial ? 'init' : 'update', ...snap);
			}
		});

		initial = false;
	});

	// If an error occurs, we store it (along with its stack trace).
	// If the render effect subsequently runs, we log the error,
	// but if it doesn't run it's because the `$inspect` was
	// destroyed, meaning we don't need to bother
	render_effect(() => {
		try {
			// call `get_value` so that this runs alongside the inspect effect
			get_value();
		} catch {
			// ignore
		}

		if (error !== UNINITIALIZED) {
			// eslint-disable-next-line no-console
			console.error(error);
			error = UNINITIALIZED;
		}
	});
}

Domain

Subdomains

Functions

Frequently Asked Questions

What does inspect.js do?
inspect.js is a source file in the svelte codebase, written in javascript. It belongs to the ClientRuntime domain, Hydration subdomain.
What functions are defined in inspect.js?
inspect.js defines 1 function(s): inspect.
What does inspect.js depend on?
inspect.js imports 11 module(s): clone.js, constants.js, dev.js, eager_effect, effects.js, get_error, render_effect, runtime.js, and 3 more.
Where is inspect.js in the architecture?
inspect.js is located at packages/svelte/src/internal/client/dev/inspect.js (domain: ClientRuntime, subdomain: Hydration, directory: packages/svelte/src/internal/client/dev).

Analyze Your Own Codebase

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

Try Supermodel Free