Add docs, type signatures, use standard coding style.

This PR is here more for discussion than anything else.

I think this is a really neat library, but unfortunately I was unable to get it to work. Is it supposed to work right now?

I would like this library to be part of a set of bindings to standard HTML5 APIs, but I think it would need a little simplification before being added to core, for example. I've made a bit of a start on some things in this PR, but I have some other suggestions if you're willing to accept this.

This makes some pretty big changes, so I think it needs some discussion.

Also, can we provide an interface to the `popstate` event without using the `Reactive` library?