Skip to content

Commit 0ee0ca7

Browse files
committed
dont go or unless you need to
1 parent ad3ac21 commit 0ee0ca7

File tree

4 files changed

+38
-7
lines changed

4 files changed

+38
-7
lines changed

src/serializers/basic-query.js

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -224,11 +224,15 @@ module.exports = function(schema) {
224224
}
225225
});
226226
if(ors.length) {
227-
return {
228-
$or: ors.map(function(orPart){
229-
return canReflect.assign( canReflect.serialize(result), orPart);
230-
})
231-
};
227+
if(ors.length === 1 ) {
228+
return ors[0];
229+
} else {
230+
return {
231+
$or: ors.map(function(orPart){
232+
return canReflect.assign( canReflect.serialize(result), orPart);
233+
})
234+
};
235+
}
232236
} else {
233237
return result;
234238
}

src/types/make-maybe-test.js

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -411,7 +411,22 @@ QUnit.test("can make a maybe type from a ComparisonSetType", function() {
411411
});
412412

413413

414+
QUnit.test("orValues", function() {
415+
var res = new MaybeDateStringSet({
416+
range: new is.In([3]),
417+
enum: set.EMPTY
418+
});
419+
420+
QUnit.deepEqual(res.orValues(),[new is.In([3])] ,"only got range");
414421

422+
res = new MaybeDateStringSet({
423+
range: set.EMPTY,
424+
enum: new is.In([null])
425+
});
426+
427+
QUnit.deepEqual(res.orValues(),[new is.In([null])] ,"only got enum");
428+
429+
});
415430

416431
/*
417432
QUnit.test("intersection", function(){
@@ -453,4 +468,4 @@ QUnit.test("difference", function(){
453468
QUnit.deepEqual(res,);
454469
455470
});
456-
*/
471+
*/

src/types/make-maybe.js

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,14 @@ function makeMaybe(inValues, makeChildType) {
9797
}
9898
}
9999
Maybe.prototype.orValues = function() {
100-
return [this.range, this.enum]
100+
var values = [];
101+
if( this.range !== set.EMPTY ) {
102+
values.push(this.range);
103+
}
104+
if( this.enum !== set.EMPTY ) {
105+
values.push(this.enum);
106+
}
107+
return values;
101108
};
102109
Maybe.prototype[isMemberSymbol] = function isMember() {
103110
var rangeIsMember = this.range[isMemberSymbol] || this.range.isMember,

test/maybe-type-test.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,11 @@ QUnit.test("basics", function(){
4343
]},
4444
"difference works");
4545

46+
var query = todoQueryLogic.hydrate({filter: {age: 21}});
47+
48+
var serialized = todoQueryLogic.serialize(query);
49+
QUnit.deepEqual( serialized, {filter: {age: 21}}, "can serialize back to what was provided" );
50+
4651
});
4752

4853

0 commit comments

Comments
 (0)