-
-
Notifications
You must be signed in to change notification settings - Fork 4.5k
feat: allow $inspect reactivity map, set, date #11164
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
trueadm
merged 5 commits into
sveltejs:main
from
tanhauhau:tanhauhau/fix/inspect-reactive
Apr 18, 2024
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
e01556c
feat: allow $inspect reactivity map, set, date
tanhauhau 784af9f
feat: inspect map without adding new data source
tanhauhau d38f89e
feat: add inspect
tanhauhau a531999
feat: define inspect on dev mode only
tanhauhau 9d68231
fix: lint error
tanhauhau File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
"svelte": patch | ||
--- | ||
|
||
feat: allow inspect reactivity map, set, date |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
81 changes: 81 additions & 0 deletions
81
packages/svelte/tests/runtime-runes/samples/inspect-reactivity/_config.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
import { test } from '../../test'; | ||
import { flushSync } from 'svelte'; | ||
import { log } from './log'; | ||
|
||
export default test({ | ||
compileOptions: { | ||
dev: true | ||
}, | ||
before_test() { | ||
log.length = 0; | ||
}, | ||
async test({ assert, target }) { | ||
const [in1, in2] = target.querySelectorAll('input'); | ||
const [b1, b2, b3] = target.querySelectorAll('button'); | ||
|
||
assert.deepEqual(log, [ | ||
{ label: 'map', type: 'init', values: [] }, | ||
{ label: 'set', type: 'init', values: [] }, | ||
{ label: 'date', type: 'init', values: 1712966400000 } | ||
]); | ||
log.length = 0; | ||
|
||
flushSync(() => b1.click()); // map.set('key', 'value') | ||
|
||
in1.value = 'name'; | ||
in2.value = 'Svelte'; | ||
in1.dispatchEvent(new window.Event('input', { bubbles: true })); | ||
in2.dispatchEvent(new window.Event('input', { bubbles: true })); | ||
flushSync(() => b1.click()); // map.set('name', 'Svelte') | ||
|
||
in2.value = 'World'; | ||
in2.dispatchEvent(new window.Event('input', { bubbles: true })); | ||
flushSync(() => b1.click()); // map.set('name', 'World') | ||
flushSync(() => b1.click()); // map.set('name', 'World') | ||
|
||
assert.deepEqual(log, [ | ||
{ label: 'map', type: 'update', values: [['key', 'value']] }, | ||
{ | ||
label: 'map', | ||
type: 'update', | ||
values: [ | ||
['key', 'value'], | ||
['name', 'Svelte'] | ||
] | ||
}, | ||
{ | ||
label: 'map', | ||
type: 'update', | ||
values: [ | ||
['key', 'value'], | ||
['name', 'World'] | ||
] | ||
} | ||
]); | ||
log.length = 0; | ||
|
||
flushSync(() => b2.click()); // set.add('name'); | ||
|
||
in1.value = 'Svelte'; | ||
in1.dispatchEvent(new window.Event('input', { bubbles: true })); | ||
flushSync(() => b2.click()); // set.add('Svelte'); | ||
|
||
flushSync(() => b2.click()); // set.add('Svelte'); | ||
|
||
assert.deepEqual(log, [ | ||
{ label: 'set', type: 'update', values: ['name'] }, | ||
{ label: 'set', type: 'update', values: ['name', 'Svelte'] } | ||
]); | ||
log.length = 0; | ||
|
||
flushSync(() => b3.click()); // date.minutes++ | ||
flushSync(() => b3.click()); // date.minutes++ | ||
flushSync(() => b3.click()); // date.minutes++ | ||
|
||
assert.deepEqual(log, [ | ||
{ label: 'date', type: 'update', values: 1712966460000 }, | ||
{ label: 'date', type: 'update', values: 1712966520000 }, | ||
{ label: 'date', type: 'update', values: 1712966580000 } | ||
]); | ||
} | ||
}); |
2 changes: 2 additions & 0 deletions
2
packages/svelte/tests/runtime-runes/samples/inspect-reactivity/log.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
/** @type {any[]} */ | ||
export const log = []; |
27 changes: 27 additions & 0 deletions
27
packages/svelte/tests/runtime-runes/samples/inspect-reactivity/main.svelte
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
<script> | ||
import { Map, Set, Date } from 'svelte/reactivity'; | ||
import { log } from './log'; | ||
|
||
const map = new Map(); | ||
const set = new Set(); | ||
const date = new Date('2024-04-13 00:00:00+0000'); | ||
let key = $state('key'); | ||
let value = $state('value'); | ||
|
||
$inspect(map).with((type, map) => { | ||
log.push({ label: 'map', type, values: [...map] }); | ||
}); | ||
$inspect(set).with((type, set) => { | ||
log.push({ label: 'set', type, values: [...set] }); | ||
}); | ||
$inspect(date).with((type, date) => { | ||
log.push({ label: 'date', type, values: date.getTime() }); | ||
}); | ||
</script> | ||
|
||
<input bind:value={key} /> | ||
<input bind:value={value} /> | ||
|
||
<button on:click={() => map.set(key, value)}>map</button> | ||
<button on:click={() => set.add(key)}>set</button> | ||
<button on:click={() => date.setMinutes(date.getMinutes() + 1)}>date</button> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.