From 05e888958dd1ecd3f5d1c117704c5c69997eed3e Mon Sep 17 00:00:00 2001 From: Pat Cavit Date: Mon, 5 Dec 2016 16:22:33 -0800 Subject: [PATCH] Naively make m.route.set return a Promise --- router/router.js | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/router/router.js b/router/router.js index 6a3ac597..7d12831b 100644 --- a/router/router.js +++ b/router/router.js @@ -1,5 +1,6 @@ "use strict" +var Promise = require("../promise/promise") var buildQueryString = require("../querystring/build") var parseQueryString = require("../querystring/parse") @@ -19,12 +20,13 @@ module.exports = function($window) { var asyncId function debounceAsync(f) { return function() { - if (asyncId != null) return - asyncId = callAsync(function() { - asyncId = null - f() - }) - + return new Promise(function(resolve, reject) { + if (asyncId != null) return reject() + asyncId = callAsync(function() { + asyncId = null + resolve(f()) + }) + }); } } @@ -73,9 +75,12 @@ module.exports = function($window) { if (supportsPushState) { if (options && options.replace) $window.history.replaceState(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) { @@ -116,7 +121,7 @@ module.exports = function($window) { e.redraw = false var href = this.getAttribute("href") if (href.indexOf(prefix) === 0) href = href.slice(prefix.length) - setPath(href, undefined, undefined) + return setPath(href, undefined, undefined) } }