-
-
Notifications
You must be signed in to change notification settings - Fork 4.6k
Description
Whenever @arackaf wants to talk about the perceived superiority of the React programming model, he asks if your template language can use debugger
statements to pause rendering:
And the answer in Svelte's case is 'well, no... because you're not writing code that executes top-to-bottom — it's a different mental model'. The absence of a render()
function is a feature, and one of the reasons Svelte is so much faster and more memory-efficient.
Of course, you can trigger the debugger when particular values change easily enough. Here's one approach:
<label>
enter your name
<input bind:value=name>
</label>
{debug(name)}
<h1>Hello {name}!</h1>
<script>
export default {
helpers: {
debug(value) {
debugger;
return '';
}
}
};
</script>
Using this approach you can also see that Svelte efficiently avoids updating parts of a component that are unchanged.
Including the helper is a slight nuisance though, if you want to just quickly track something down. What if we introduced a {@debug ...}
tag? The above example would become this:
<label>
enter your name
<input bind:value=name>
</label>
{@debug name}
<h1>Hello {name}!</h1>
It could take multiple arguments ({@debug foo, bar, baz}
), and it would probably only get emitted when dev: true
. The compiler could turn it into this:
if (changed.foo || changed.bar || changed.baz) {
const { foo, bar, baz } = ctx;
debugger;
}
Thoughts?