Skip to content

Commit

Permalink
Revert "feat: allow $inspect reactivity map, set, date (#11164)" (#11223
Browse files Browse the repository at this point in the history
)

This reverts commit 43d13e9.
  • Loading branch information
Rich-Harris authored Apr 18, 2024
1 parent 42ce8d7 commit de2d8a0
Show file tree
Hide file tree
Showing 11 changed files with 2 additions and 197 deletions.
5 changes: 0 additions & 5 deletions .changeset/tiny-poems-doubt.md

This file was deleted.

1 change: 0 additions & 1 deletion packages/svelte/src/internal/client/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,3 @@ export const EFFECT_RAN = 1 << 13;
export const EFFECT_TRANSPARENT = 1 << 14;

export const STATE_SYMBOL = Symbol('$state');
export const INSPECT_SYMBOL = Symbol('$inspect');
23 changes: 2 additions & 21 deletions packages/svelte/src/internal/client/runtime.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,7 @@ import {
BRANCH_EFFECT,
STATE_SYMBOL,
BLOCK_EFFECT,
ROOT_EFFECT,
INSPECT_SYMBOL
ROOT_EFFECT
} from './constants.js';
import { flush_tasks } from './dom/task.js';
import { add_owner } from './dev/ownership.js';
Expand Down Expand Up @@ -1118,24 +1117,6 @@ export function pop(component) {
return component || /** @type {T} */ ({});
}

/**
*
* This is called from the inspect.
* Deeply traverse every item in the array with `deep_read` to register for inspect callback
* If the item implements INSPECT_SYMBOL, will use that instead
* @param {Array<any>} value
* @returns {void}
*/
function deep_read_inpect(value) {
for (const item of value) {
if (item && typeof item[INSPECT_SYMBOL] === 'function') {
item[INSPECT_SYMBOL]();
} else {
deep_read(item);
}
}
}

/**
* Possibly traverse an object and read all its properties so that they're all reactive in case this is `$state`.
* Does only check first level of an object for performance reasons (heuristic should be good for 99% of all cases).
Expand Down Expand Up @@ -1266,7 +1247,7 @@ export function inspect(get_value, inspect = console.log) {

inspect_fn = fn;
const value = get_value();
deep_read_inpect(value);
deep_read(value);
inspect_fn = null;

const signals = inspect_captured_signals.slice();
Expand Down
9 changes: 0 additions & 9 deletions packages/svelte/src/reactivity/date.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import { DEV } from 'esm-env';
import { INSPECT_SYMBOL } from '../internal/client/constants.js';
import { source, set } from '../internal/client/reactivity/sources.js';
import { get } from '../internal/client/runtime.js';

Expand Down Expand Up @@ -90,13 +88,6 @@ export class ReactiveDate extends Date {
return v;
};
}

if (DEV) {
// @ts-ignore
proto[INSPECT_SYMBOL] = function () {
get(this.#raw_time);
};
}
}
}

Expand Down
19 changes: 0 additions & 19 deletions packages/svelte/src/reactivity/map.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,6 @@ import { source, set } from '../internal/client/reactivity/sources.js';
import { get } from '../internal/client/runtime.js';
import { UNINITIALIZED } from '../constants.js';
import { map } from './utils.js';
import { INSPECT_SYMBOL } from '../internal/client/constants.js';

var inited = false;

/**
* @template K
Expand All @@ -23,22 +20,6 @@ export class ReactiveMap extends Map {
constructor(value) {
super();

if (DEV) {
if (!inited) {
inited = true;
// @ts-ignore
ReactiveMap.prototype[INSPECT_SYMBOL] = function () {
// changes could either introduced by
// - modifying the value, or
// - add / remove entries to the map
for (const [, source] of this.#sources) {
get(source);
}
get(this.#size);
};
}
}

// If the value is invalid then the native exception will fire here
if (DEV) new Map(value);

Expand Down
8 changes: 0 additions & 8 deletions packages/svelte/src/reactivity/set.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import { DEV } from 'esm-env';
import { source, set } from '../internal/client/reactivity/sources.js';
import { get } from '../internal/client/runtime.js';
import { map } from './utils.js';
import { INSPECT_SYMBOL } from '../internal/client/constants.js';

var read_methods = ['forEach', 'isDisjointFrom', 'isSubsetOf', 'isSupersetOf'];
var set_like_methods = ['difference', 'intersection', 'symmetricDifference', 'union'];
Expand Down Expand Up @@ -66,13 +65,6 @@ export class ReactiveSet extends Set {
return new ReactiveSet(set);
};
}

if (DEV) {
// @ts-ignore
proto[INSPECT_SYMBOL] = function () {
get(this.#version);
};
}
}

#increment_version() {
Expand Down
23 changes: 0 additions & 23 deletions packages/svelte/src/reactivity/url.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,7 @@
import { DEV } from 'esm-env';
import { INSPECT_SYMBOL } from '../internal/client/constants.js';
import { source, set } from '../internal/client/reactivity/sources.js';
import { get } from '../internal/client/runtime.js';

const REPLACE = Symbol();
var inited_url = false;
var inited_search_params = false;

export class ReactiveURL extends URL {
#protocol = source(super.protocol);
Expand All @@ -25,14 +21,6 @@ export class ReactiveURL extends URL {
url = new URL(url, base);
super(url);
this.#searchParams[REPLACE](url.searchParams);

if (DEV && !inited_url) {
inited_url = true;
// @ts-ignore
ReactiveURL.prototype[INSPECT_SYMBOL] = function () {
this.href;
};
}
}

get hash() {
Expand Down Expand Up @@ -171,17 +159,6 @@ export class ReactiveURLSearchParams extends URLSearchParams {
set(this.#version, this.#version.v + 1);
}

constructor() {
super();
if (DEV && !inited_search_params) {
inited_search_params = true;
// @ts-ignore
ReactiveURLSearchParams.prototype[INSPECT_SYMBOL] = function () {
get(this.#version);
};
}
}

/**
* @param {URLSearchParams} params
*/
Expand Down

This file was deleted.

This file was deleted.

This file was deleted.

1 change: 0 additions & 1 deletion packages/svelte/types/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2021,7 +2021,6 @@ declare module 'svelte/reactivity' {
#private;
}
class ReactiveURLSearchParams extends URLSearchParams {
constructor();

[REPLACE](params: URLSearchParams): void;
#private;
Expand Down

0 comments on commit de2d8a0

Please sign in to comment.