@@ -16,6 +16,26 @@ var KeysAnd = andOrNot.KeysAnd,
1616// TYPES FOR PAGINATION
1717var RecordRange = makeRealNumberRangeInclusive ( 0 , Infinity ) ;
1818
19+
20+ // ## makeSort
21+ // Takes:
22+ // - `schemaKeys` - a schema
23+ // - `hydrateAndValue` - Useful to create something like `new GreaterThan( new MaybeDate("10-20-82") )`
24+ //
25+ // Makes a `new Sort(key)` constructor function. This constructor function is used like:
26+ //
27+ // ```
28+ // new Sort("dueDate")
29+ // ```
30+ //
31+ // That constructor function has all the comparison methods (union, intersection, difference)
32+ // built to compare against the `key` value.
33+ //
34+ // Instances of `Sort` have a `compare` method that will
35+ // return a function that can be passed to `Array.prototype.sort`.
36+ //
37+ // That compare function will read the right property and return `-1` or `1`
38+
1939// WILL MAKE A TYPE FOR SORTING
2040function makeSort ( schemaKeys , hydrateAndValue ) {
2141 // Makes gt and lt functions that `helpers.sorter` can use
@@ -30,21 +50,57 @@ function makeSort(schemaKeys, hydrateAndValue) {
3050 if ( valueA == null || valueB == null ) {
3151 return helpers . typeCompare . $gt ( valueA , valueB ) ;
3252 }
53+ // The following can certainly be done faster
3354 var $gt = hydrateAndValue ( {
3455 $gt : valueB
3556 } , key , schemaProp ,
3657 helpers . valueHydrator ) ;
37- return $gt [ isMemberSymbol ] ( valueA ) ;
58+
59+ var $eq = hydrateAndValue ( {
60+ $eq : valueA
61+ } , key , schemaProp ,
62+ helpers . valueHydrator ) ;
63+
64+ return set . isEqual ( set . union ( $gt , $eq ) , $gt ) ;
65+ /*
66+ var hydratedIn = hydrateAndValue({
67+ $eq: valueA
68+ }, key, schemaProp,
69+ helpers.valueHydrator);
70+ return $gt[isMemberSymbol](hydratedIn.values[0]);*/
3871 } ,
3972 $lt : function ( valueA , valueB ) {
4073 if ( valueA == null || valueB == null ) {
4174 return helpers . typeCompare . $lt ( valueA , valueB ) ;
4275 }
76+
77+
4378 var $lt = hydrateAndValue ( {
4479 $lt : valueB
4580 } , key , schemaProp ,
4681 helpers . valueHydrator ) ;
47- return $lt [ isMemberSymbol ] ( valueA ) ;
82+
83+ var $eq = hydrateAndValue ( {
84+ $eq : valueA
85+ } , key , schemaProp ,
86+ helpers . valueHydrator ) ;
87+
88+ return set . isEqual ( set . union ( $lt , $eq ) , $lt ) ;
89+ /*
90+ // This doesn't work because it will try to create new SetType(new In([]))
91+ var hydratedValue = hydrateAndValue({
92+ $eq: valueA
93+ }, key, schemaProp,
94+ helpers.valueHydrator);
95+ return $lt[isMemberSymbol](hydratedValue);*/
96+
97+ /*
98+ // This doesn't work because of maybe types.
99+ var hydratedIn = hydrateAndValue({
100+ $eq: valueA
101+ }, key, schemaProp,
102+ helpers.valueHydrator);
103+ return $lt[isMemberSymbol](hydratedIn.values[0]); */
48104 }
49105 } ;
50106 } ) ;
0 commit comments