Skip to content

{@debug foo} #1635

@Rich-Harris

Description

@Rich-Harris

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:

screen shot 2018-08-05 at 9 19 13 am

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?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions