Naively make m.route.set return a Promise

This commit is contained in:
Pat Cavit 2016-12-05 16:22:33 -08:00
parent 624c0d5fa1
commit 05e888958d

View file

@ -1,5 +1,6 @@
"use strict" "use strict"
var Promise = require("../promise/promise")
var buildQueryString = require("../querystring/build") var buildQueryString = require("../querystring/build")
var parseQueryString = require("../querystring/parse") var parseQueryString = require("../querystring/parse")
@ -19,12 +20,13 @@ module.exports = function($window) {
var asyncId var asyncId
function debounceAsync(f) { function debounceAsync(f) {
return function() { return function() {
if (asyncId != null) return return new Promise(function(resolve, reject) {
asyncId = callAsync(function() { if (asyncId != null) return reject()
asyncId = null asyncId = callAsync(function() {
f() asyncId = null
}) resolve(f())
})
});
} }
} }
@ -73,9 +75,12 @@ module.exports = function($window) {
if (supportsPushState) { if (supportsPushState) {
if (options && options.replace) $window.history.replaceState(null, null, prefix + path) if (options && options.replace) $window.history.replaceState(null, null, prefix + path)
else $window.history.pushState(null, null, prefix + path) else $window.history.pushState(null, null, prefix + path)
$window.onpopstate(true) return $window.onpopstate()
}
else {
$window.location.href = prefix + path
return Promise.resolve(prefix + path)
} }
else $window.location.href = prefix + path
} }
function defineRoutes(routes, resolve, reject) { function defineRoutes(routes, resolve, reject) {
@ -116,7 +121,7 @@ module.exports = function($window) {
e.redraw = false e.redraw = false
var href = this.getAttribute("href") var href = this.getAttribute("href")
if (href.indexOf(prefix) === 0) href = href.slice(prefix.length) if (href.indexOf(prefix) === 0) href = href.slice(prefix.length)
setPath(href, undefined, undefined) return setPath(href, undefined, undefined)
} }
} }