Permit undefined values to flow through
This commit is contained in:
parent
d8d94d1df0
commit
397fea5720
1 changed files with 14 additions and 18 deletions
|
@ -66,23 +66,15 @@ 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);
|
|
||||||
}
|
|
||||||
finally {
|
|
||||||
mapValueCallbackRecursionCount--;
|
|
||||||
}
|
|
||||||
if (u === undefined) {
|
|
||||||
throw new Error("MapValue yielded no result");
|
|
||||||
}
|
|
||||||
|
|
||||||
|
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 this is another computed, we need to wire up to its resolution; else just store the value.
|
||||||
if (u instanceof Promise) {
|
if (u && u instanceof Promise) {
|
||||||
u.then((v: U) => { result.setOutput(v, true, false); });
|
u.then((v: U) => { result.setOutput(v, true, false); });
|
||||||
}
|
}
|
||||||
else if ((u as Computed<U>).mapValue) {
|
else if (u && (u as Computed<U>).mapValue) {
|
||||||
(u as Computed<U>).mapValue((v: U) => {
|
(u as Computed<U>).mapValue((v: U) => {
|
||||||
result.setOutput(v, true, false);
|
result.setOutput(v, true, false);
|
||||||
});
|
});
|
||||||
|
@ -91,6 +83,10 @@ export class Property<T> implements Computed<T> {
|
||||||
result.setOutput(<U>u, true, false);
|
result.setOutput(<U>u, true, false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
finally {
|
||||||
|
mapValueCallbackRecursionCount--;
|
||||||
|
}
|
||||||
|
}
|
||||||
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}`);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue