Permit undefined values to flow through

This commit is contained in:
joeduffy 2017-09-06 09:39:16 -07:00
parent d8d94d1df0
commit 397fea5720

View file

@ -66,30 +66,26 @@ export class Property<T> implements Computed<T> {
else { else {
try { try {
// There's a callback; invoke it. // There's a callback; invoke it.
let u: MaybeComputed<U> | undefined;
try { try {
mapValueCallbackRecursionCount++; mapValueCallbackRecursionCount++;
u = callback(value);
let u: MaybeComputed<U> = callback(value);
// If this is another computed, we need to wire up to its resolution; else just store the value.
if (u && u instanceof Promise) {
u.then((v: U) => { result.setOutput(v, true, false); });
}
else if (u && (u as Computed<U>).mapValue) {
(u as Computed<U>).mapValue((v: U) => {
result.setOutput(v, true, false);
});
}
else {
result.setOutput(<U>u, true, false);
}
} }
finally { finally {
mapValueCallbackRecursionCount--; mapValueCallbackRecursionCount--;
} }
if (u === undefined) {
throw new Error("MapValue yielded no result");
}
// If this is another computed, we need to wire up to its resolution; else just store the value.
if (u instanceof Promise) {
u.then((v: U) => { result.setOutput(v, true, false); });
}
else if ((u as Computed<U>).mapValue) {
(u as Computed<U>).mapValue((v: U) => {
result.setOutput(v, true, false);
});
}
else {
result.setOutput(<U>u, true, false);
}
} }
catch (err) { catch (err) {
Log.error(`MapValue of a Computed yielded an unhandled error: ${err}`); Log.error(`MapValue of a Computed yielded an unhandled error: ${err}`);