Chapbook 2.0.0

I’ve released version 2.0.0 of Chapbook. Consider it a technical preview. If you’re using Chapbook in a project now, there isn’t much reason to upgrade. The release notes talk about what exactly has changed, but I expect that in most cases, the same code that worked in Chapbook 1.x will work in version 2.

The same isn’t true for people who have extended Chapbook, which is why I wanted to post a notice about it. Quite a lot has changed in terms of implementation—see the release notes. The good news, I hope, is that there’s now published API documentation that might help explain the internals better.

Chapbook 2 will get bundled with Twine once it grows more features that’ll be useful for authors. In the meantime, it can be added to Twine using the URL on the home page.

10 Likes

@klembot
re: the data-cb-go simulation JavaScript code example

window.addEventListener('click', ({target}) => {  
  const goable = target.closest('[data-cb-go]');
  
  if (goable) {
    window.go(goable.dataset.cbGo);
  }
});

I’m curious why you advise adding the ‘click’ event handler to the window object, instead of the document object.

document.addEventListener('click', ({target}) => {  
  const goable = target.closest('[data-cb-go]');
  
  if (goable) {
    window.go(goable.dataset.cbGo);
  }
});
1 Like

Are there cases where it matters (other than IE8 support, but I’m guessing Chapbook likely doesn’t run on IE8 anyway…)?

I’m guessing it’s just for consistency, since the very next bullet point says:

Instead of managing its own event bus, Chapbook now dispatches custom events on window. The names of these events have changed. See the API documentation for more details.

2 Likes

This is great news, Chris! I really liked being able to extend Chapbook, but it had a few quirks. I’m looking forward to seeing the changes you’ve made. Chapbook is a great story format.

I just love the simplicity and how the code never seems to get too crazy… and if you need a crazy thing, you can extend Chapbook and your passage code always looks clean and understandable again.

Glad to see Chapbook getting some more love! :slight_smile:

@Greyelf This Stack Overflow top answer seems to explain your question quite well. I never really considered the implication of document versus window when both seem to work with the same events.

https://stackoverflow.com/questions/12045440/difference-between-document-addeventlistener-and-window-addeventlistener