Skip to content

Commit fe4652a

Browse files
author
Timothy Johnson
committed
Flash attributes when they change
1 parent 2c6fa39 commit fe4652a

File tree

2 files changed

+28
-7
lines changed

2 files changed

+28
-7
lines changed

src/nodes/Element.svelte

Lines changed: 25 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,23 @@
1010
export let attributes = []
1111
export let listeners = []
1212
export let collapsed
13+
14+
let _attributes
15+
let cache = {}
16+
$: {
17+
let localCache = {}
18+
_attributes = attributes.map(o => {
19+
const value = JSON.stringify(o.value)
20+
localCache[o.key] = value
21+
22+
return {
23+
...o,
24+
value,
25+
flash: !!_attributes && value != cache[o.key]
26+
}
27+
})
28+
cache = localCache
29+
}
1330
</script>
1431

1532
<style>
@@ -38,14 +55,16 @@
3855
</style>
3956

4057
<!--block attributes-->
41-
{#each attributes as { key, value, isBound } (key)}
58+
{#each _attributes as { key, value, isBound, flash } (key)}
4259
&nbsp;
43-
<span class="attr-name">
44-
{#if isBound}bind:{/if}
45-
{key}
60+
<span class:flash>
61+
<span class="attr-name">
62+
{#if isBound}bind:{/if}
63+
{key}
64+
</span>
65+
=
66+
<span class="attr-value">{value}</span>
4667
</span>
47-
=
48-
<span class="attr-value">{JSON.stringify(value)}</span>
4968
{/each}
5069

5170
{#each listeners as { type, handler, options } (type)}

src/nodes/Node.svelte

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,9 @@
4949
}
5050
5151
li.flash :global(> :first-child),
52-
li.flash :global(> :first-child *) {
52+
li.flash :global(> :first-child *),
53+
li :global(.flash),
54+
li :global(.flash *) {
5355
animation: flash 0.8s ease-in-out;
5456
}
5557

0 commit comments

Comments
 (0)