From 42723cbeb613b45ea3db7db837cfe2f3722878aa Mon Sep 17 00:00:00 2001 From: impinball Date: Thu, 26 Nov 2015 07:44:19 -0500 Subject: [PATCH] Fully isolate m.prop(), make m.prop().then return current value Note that this does *not* memoize `then`, another deviation from spec, but it's unlikely this will actually cause very many bugs. It's also a breaking change. --- mithril.js | 29 +++++++++++++++++++++-------- 1 file changed, 21 insertions(+), 8 deletions(-) diff --git a/mithril.js b/mithril.js index 0d265c55..2b832a7c 100644 --- a/mithril.js +++ b/mithril.js @@ -1198,24 +1198,37 @@ void (function (global, factory) { // eslint-disable-line isFunction(object.then) } + function simpleResolve(p, callback) { + if (p.then) { + return p.then(callback) + } else { + return callback() + } + } + function propify(promise) { var prop = m.prop() promise.then(prop) - prop.then = promise.then.bind(promise) - prop.catch = promise.then.bind(promise, undefined) + prop.then = function (fufill, reject) { + return promise.then(function () { + return prop() + }).then(fufill, reject) + } + + prop.catch = function (reject) { + return promise.then(function () { + return prop() + }, reject) + } prop.finally = function (callback) { - function _callback() { - return m.deferred().resolve(callback()).promise - } - return promise.then(function (value) { - return _callback().then(function () { + return simpleResolve(callback(), function () { return value }) }, function (reason) { - return _callback().then(function () { + return simpleResolve(callback(), function () { throw reason }) })