All files / src/internal/client/dev inspect.js

100% Statements 37/37
100% Branches 6/6
100% Functions 1/1
100% Lines 34/34

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 352x 2x 2x 2x 2x 2x 2x 2x 2x 2x 40x 40x 40x 40x 40x 80x 80x 80x 80x 80x 80x 80x 80x 80x 4x 4x 80x 80x 76x 76x 80x 80x 40x 40x  
import { UNINITIALIZED } from '../../../constants.js';
import { snapshot } from '../../shared/clone.js';
import { inspect_effect, validate_effect } from '../reactivity/effects.js';
 
/**
 * @param {() => any[]} get_value
 * @param {Function} [inspector]
 */
// eslint-disable-next-line no-console
export function inspect(get_value, inspector = console.log) {
	validate_effect('$inspect');
 
	let initial = true;
 
	inspect_effect(() => {
		/** @type {any} */
		var value = UNINITIALIZED;
 
		// Capturing the value might result in an exception due to the inspect effect being
		// sync and thus operating on stale data. In the case we encounter an exception we
		// can bail-out of reporting the value
		try {
			value = get_value();
		} catch {
			// NO-OP
		}
 
		if (value !== UNINITIALIZED) {
			inspector(initial ? 'init' : 'update', ...snapshot(value, true));
		}
 
		initial = false;
	});
}