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:
parent
6c562d2b9b
commit
90bcff0fa7
18 changed files with 397 additions and 192 deletions
|
|
@ -5,12 +5,16 @@ var browserMock = require("../test-utils/browserMock")
|
|||
var components = require("../test-utils/components")
|
||||
|
||||
o.spec("api", function() {
|
||||
var m
|
||||
var FRAME_BUDGET = Math.floor(1000 / 60)
|
||||
o.beforeEach(function() {
|
||||
var mock = browserMock()
|
||||
if (typeof global !== "undefined") global.window = mock
|
||||
m = require("../mithril") // eslint-disable-line global-require
|
||||
var mock = browserMock(), root
|
||||
if (typeof global !== "undefined") {
|
||||
global.window = mock
|
||||
global.requestAnimationFrame = mock.requestAnimationFrame
|
||||
}
|
||||
var m = require("..") // eslint-disable-line global-require
|
||||
|
||||
o.afterEach(function() {
|
||||
if (root) m.mount(root, null)
|
||||
})
|
||||
|
||||
o.spec("m", function() {
|
||||
|
|
@ -71,7 +75,7 @@ o.spec("api", function() {
|
|||
})
|
||||
o.spec("m.render", function() {
|
||||
o("works", function() {
|
||||
var root = window.document.createElement("div")
|
||||
root = window.document.createElement("div")
|
||||
m.render(root, m("div"))
|
||||
|
||||
o(root.childNodes.length).equals(1)
|
||||
|
|
@ -84,7 +88,7 @@ o.spec("api", function() {
|
|||
|
||||
o.spec("m.mount", function() {
|
||||
o("works", function() {
|
||||
var root = window.document.createElement("div")
|
||||
root = window.document.createElement("div")
|
||||
m.mount(root, createComponent({view: function() {return m("div")}}))
|
||||
|
||||
o(root.childNodes.length).equals(1)
|
||||
|
|
@ -93,7 +97,7 @@ o.spec("api", function() {
|
|||
})
|
||||
o.spec("m.route", function() {
|
||||
o("works", function(done) {
|
||||
var root = window.document.createElement("div")
|
||||
root = window.document.createElement("div")
|
||||
m.route(root, "/a", {
|
||||
"/a": createComponent({view: function() {return m("div")}})
|
||||
})
|
||||
|
|
@ -106,7 +110,7 @@ o.spec("api", function() {
|
|||
}, FRAME_BUDGET)
|
||||
})
|
||||
o("m.route.prefix", function(done) {
|
||||
var root = window.document.createElement("div")
|
||||
root = window.document.createElement("div")
|
||||
m.route.prefix("#")
|
||||
m.route(root, "/a", {
|
||||
"/a": createComponent({view: function() {return m("div")}})
|
||||
|
|
@ -120,7 +124,7 @@ o.spec("api", function() {
|
|||
}, FRAME_BUDGET)
|
||||
})
|
||||
o("m.route.get", function(done) {
|
||||
var root = window.document.createElement("div")
|
||||
root = window.document.createElement("div")
|
||||
m.route(root, "/a", {
|
||||
"/a": createComponent({view: function() {return m("div")}})
|
||||
})
|
||||
|
|
@ -133,7 +137,7 @@ o.spec("api", function() {
|
|||
})
|
||||
o("m.route.set", function(done, timeout) {
|
||||
timeout(100)
|
||||
var root = window.document.createElement("div")
|
||||
root = window.document.createElement("div")
|
||||
m.route(root, "/a", {
|
||||
"/:id": createComponent({view: function() {return m("div")}})
|
||||
})
|
||||
|
|
@ -151,7 +155,7 @@ o.spec("api", function() {
|
|||
o.spec("m.redraw", function() {
|
||||
o("works", function(done) {
|
||||
var count = 0
|
||||
var root = window.document.createElement("div")
|
||||
root = window.document.createElement("div")
|
||||
m.mount(root, createComponent({view: function() {count++}}))
|
||||
o(count).equals(1)
|
||||
m.redraw()
|
||||
|
|
@ -164,7 +168,7 @@ o.spec("api", function() {
|
|||
}, FRAME_BUDGET)
|
||||
})
|
||||
o("sync", function() {
|
||||
var root = window.document.createElement("div")
|
||||
root = window.document.createElement("div")
|
||||
var view = o.spy()
|
||||
m.mount(root, createComponent({view: view}))
|
||||
o(view.callCount).equals(1)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue