Deduplicate m.route and m.redraw logic (#2453)

- Remove appropriate route change subcriptions when a root is removed
  via `m.mount(root, null)`.
- Don't pollute `onpopstate` and friends - use standard event listeners
  instead.
- Simplify and streamline subscriptions, in preparation of adding a
  `remove` parameter to `m.mount`.
- Change the redraw internals to redraw immediately, with ability to
  cancel via returning a sentinel.
- Change `"bleeding-edge"` for `m.version` in `next` to instead just be
  the latest `m.version`. (If you're using `next`, you should know what
  you're in for.)
- Update tests to be aware of these changes. (Some were failing for
  subtle reasons.)
- Drive-by: remove some uses of `string.charAt(n)` and use `string[n]`
  instead.
This commit is contained in:
Isiah Meadows 2019-07-05 18:52:06 -04:00 committed by GitHub
parent 6c562d2b9b
commit 90bcff0fa7
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
18 changed files with 397 additions and 192 deletions

View file

@ -224,8 +224,16 @@ module.exports = function(options) {
return string.replace(/-\D/g, function(match) {return match[1].toUpperCase()})
}
var activeElement
var delay = 16, last = 0
var $window = {
DOMParser: DOMParser,
requestAnimationFrame: function(callback) {
var elapsed = Date.now() - last
return setTimeout(function() {
callback()
last = Date.now()
}, delay - elapsed)
},
document: {
createElement: function(tag) {
var cssText = ""

View file

@ -187,5 +187,13 @@ module.exports = function(options) {
$window.onhashchange = null,
$window.onunload = null
$window.addEventListener = function (name, handler) {
$window["on" + name] = handler
}
$window.removeEventListener = function (name, handler) {
$window["on" + name] = handler
}
return $window
}