Skip to content

Commit d4a5cc2

Browse files
authored
refactor: simplify invalidate logic (#143)
1 parent a39f95c commit d4a5cc2

File tree

2 files changed

+4
-16
lines changed

2 files changed

+4
-16
lines changed

src/lib/nodes/Node.svelte

Lines changed: 3 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -11,25 +11,14 @@
1111
export let node: NonNullable<typeof $selected>;
1212
export let depth = 1;
1313
14-
let _timeout: null | NodeJS.Timeout;
15-
node.invalidate = () => {
16-
if (_timeout) return;
17-
18-
_timeout = setTimeout(() => {
19-
_timeout = null;
20-
node = node;
21-
}, 100);
22-
};
14+
node.invalidate = () => (node = node);
2315
2416
let lastLength = node.children.length;
2517
let flash = false;
2618
$: {
2719
flash = flash || node.children.length !== lastLength;
2820
lastLength = node.children.length;
2921
}
30-
31-
// TODO: report, something really weird with the language server
32-
const iterate = () => node.children;
3322
</script>
3423

3524
{#if $visibility[node.type]}
@@ -125,8 +114,8 @@
125114
{/if}
126115
</li>
127116
{:else}
128-
{#each iterate() as node (node.id)}
129-
<svelte:self {node} {depth} />
117+
{#each node.children as child (child.id)}
118+
<svelte:self node={child} {depth} />
130119
{/each}
131120
{/if}
132121

src/routes/+layout.svelte

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,7 @@
3939

4040
<svelte:window
4141
on:keydown={({ target, key }) => {
42-
if (target !== document.body) return;
43-
if (!$selected?.invalidate) return;
42+
if (target !== document.body || !$selected) return;
4443

4544
if (key === 'Enter') {
4645
$selected.expanded = !$selected.expanded;

0 commit comments

Comments
 (0)