Skip to content

Commit

Permalink
chore: tweak Map/Set for better inspect output (#12013)
Browse files Browse the repository at this point in the history
* chore: tweak Map/Set for better inspect output

* chore: tweak Map/Set for better inspect output

* chore: tweak Map/Set for better inspect output

* chore: tweak Map/Set for better inspect output

* chore: tweak Map/Set for better inspect output

* changeset

---------

Co-authored-by: Rich Harris <rich.harris@vercel.com>
  • Loading branch information
trueadm and Rich-Harris authored Jun 13, 2024
1 parent 50fd94f commit 4cdc371
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 19 deletions.
5 changes: 5 additions & 0 deletions .changeset/eleven-hounds-pump.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"svelte": patch
---

chore: clear `Map`/`Set` before triggering `$inspect` callbacks
19 changes: 10 additions & 9 deletions packages/svelte/src/reactivity/map.js
Original file line number Diff line number Diff line change
Expand Up @@ -122,17 +122,18 @@ export class ReactiveMap extends Map {
}

clear() {
var sources = this.#sources;

if (super.size !== 0) {
set(this.#size, 0);
for (var s of sources.values()) {
set(s, -1);
}
increment(this.#version);
sources.clear();
if (super.size === 0) {
return;
}
// Clear first, so we get nice console.log outputs with $inspect
super.clear();
var sources = this.#sources;
set(this.#size, 0);
for (var s of sources.values()) {
set(s, -1);
}
increment(this.#version);
sources.clear();
}

#read_all() {
Expand Down
21 changes: 11 additions & 10 deletions packages/svelte/src/reactivity/set.js
Original file line number Diff line number Diff line change
Expand Up @@ -117,19 +117,20 @@ export class ReactiveSet extends Set {
}

clear() {
if (super.size !== 0) {
var sources = this.#sources;

for (var s of sources.values()) {
set(s, false);
}
if (super.size === 0) {
return;
}
// Clear first, so we get nice console.log outputs with $inspect
super.clear();
var sources = this.#sources;

sources.clear();
set(this.#size, 0);
increment(this.#version);
for (var s of sources.values()) {
set(s, false);
}

super.clear();
sources.clear();
set(this.#size, 0);
increment(this.#version);
}

keys() {
Expand Down

0 comments on commit 4cdc371

Please sign in to comment.