Fix QuerySubscription: null is a valid query result, should be emitted

This commit is contained in:
Ben Gotow 2017-07-11 22:10:06 -07:00
parent e4a2568829
commit 7171513053
2 changed files with 4 additions and 4 deletions

View file

@ -10,7 +10,7 @@ export default class QuerySubscription {
this._set = null;
this._callbacks = [];
this._lastResult = null;
this._lastResult = undefined; // null is a valid result!
this._updateInFlight = false;
this._queuedChangeRecords = [];
this._queryVersion = 1;
@ -44,8 +44,7 @@ export default class QuerySubscription {
throw new Error(`QuerySubscription:addCallback - expects a function, received ${callback}`);
}
this._callbacks.push(callback);
if (this._lastResult) {
if (this._lastResult !== undefined) {
callback(this._lastResult);
}
}

View file

@ -320,7 +320,8 @@ export default class ModelQuery {
formatResult(inflated) {
if (this._returnOne) {
return inflated[0];
// be careful not to return "undefined" if no items returned
return inflated.length > 0 ? inflated[0] : null;
}
if (this._count) {
return inflated;