Deservicify core (#2458)

* De-servicify router (mostly)

Still uses the redraw service, but it no longer has an intermediate
service of its own.

Also, did a *lot* of test deduplication in this. About 30-40% of the
router service tests were already tested on the main router API instance
itself.

Bundle size decreased from 9560 to 9548 bytes min+gzip.

* Merge `m.mount` + `m.redraw`, update router

Simplifies the router and redraw mechanism, and makes it much easier to
keep predictable.

Bundle size down to 9433 bytes min+gzip, docs updated accordingly.

* Make `mithril/render` just return the `m.render` function directly.

* Deservicify `m.render`, revise `m.route`

- You now have to use `mithril/render/render` directly if you want an
  implicit redraw function. (This will likely be going away in v3.)
- Revise `m.route` to only `key` components

* Add `redraw` to `m.render`, deservicify requests

* Test error logging

* Update docs + changelog [skip ci]
This commit is contained in:
Isiah Meadows 2019-07-07 18:28:43 -04:00 committed by GitHub
parent db277217f8
commit 1f4b2cf49a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
60 changed files with 1212 additions and 1393 deletions

View file

@ -2,9 +2,8 @@
var buildPathname = require("../pathname/build")
module.exports = function($window, Promise) {
module.exports = function($window, Promise, oncompletion) {
var callbackCount = 0
var oncompletion
function PromiseProxy(executor) {
return new Promise(executor)
@ -191,8 +190,5 @@ module.exports = function($window, Promise) {
encodeURIComponent(callbackName)
$window.document.documentElement.appendChild(script)
}),
setCompletionCallback: function(callback) {
oncompletion = callback
},
}
}

View file

@ -3,17 +3,15 @@
var o = require("../../ospec/ospec")
var xhrMock = require("../../test-utils/xhrMock")
var Request = require("../../request/request")
var Promise = require("../../promise/promise")
var PromisePolyfill = require("../../promise/promise")
var parseQueryString = require("../../querystring/parse")
o.spec("jsonp", function() {
var mock, jsonp, complete
o.beforeEach(function() {
mock = xhrMock()
var requestService = Request(mock, Promise)
jsonp = requestService.jsonp
complete = o.spy()
requestService.setCompletionCallback(complete)
jsonp = Request(mock, PromisePolyfill, complete).jsonp
})
o("works", function(done) {

View file

@ -10,10 +10,8 @@ o.spec("request", function() {
var mock, request, complete
o.beforeEach(function() {
mock = xhrMock()
var requestService = Request(mock, PromisePolyfill)
request = requestService.request
complete = o.spy()
requestService.setCompletionCallback(complete)
request = Request(mock, PromisePolyfill, complete).request
})
o.spec("success", function() {
@ -835,10 +833,7 @@ o.spec("request", function() {
// if you use the polyfill, as it's based on `setImmediate` (falling
// back to `setTimeout`), and promise microtasks are run at higher
// priority than either of those.
var requestService = Request(mock, Promise)
request = requestService.request
complete = o.spy()
requestService.setCompletionCallback(complete)
request = Request(mock, Promise, complete).request
mock.$defineRoutes({
"GET /item": function() {
return {status: 200, responseText: "[]"}