In-browser JavaScript+Syndicate, round two

Since last time, I’ve managed to shrink the boilerplate for experimenting with Syndicate in the browser a little further.

Save the following in an HTML file, and open it:

1
2
3
4
5
6
7
8
9
10
<!DOCTYPE html>
<script src="https://cdn.jsdelivr.net/npm/@syndicate-lang/browser-stdenv"></script>
<script type="syndicate">
  spawn named 'clicker' {
    field counter = 0;
    const b = new SyndicateHtml2.Widget(t => t`<button>clicks: ${counter.value}</button>`)
          .setParent('body')
          .on('click', () => counter.value++);
  }
</script>

You should be greeted with a click-counter button.

Here’s the same as a codepen:

See the Pen Untitled by Tony Garnock-Jones (@leastfixedpoint) on CodePen.