@@ -16,6 +16,26 @@ var KeysAnd = andOrNot.KeysAnd,
16
16
// TYPES FOR PAGINATION
17
17
var RecordRange = makeRealNumberRangeInclusive ( 0 , Infinity ) ;
18
18
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
+
19
39
// WILL MAKE A TYPE FOR SORTING
20
40
function makeSort ( schemaKeys , hydrateAndValue ) {
21
41
// Makes gt and lt functions that `helpers.sorter` can use
@@ -30,21 +50,57 @@ function makeSort(schemaKeys, hydrateAndValue) {
30
50
if ( valueA == null || valueB == null ) {
31
51
return helpers . typeCompare . $gt ( valueA , valueB ) ;
32
52
}
53
+ // The following can certainly be done faster
33
54
var $gt = hydrateAndValue ( {
34
55
$gt : valueB
35
56
} , key , schemaProp ,
36
57
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]);*/
38
71
} ,
39
72
$lt : function ( valueA , valueB ) {
40
73
if ( valueA == null || valueB == null ) {
41
74
return helpers . typeCompare . $lt ( valueA , valueB ) ;
42
75
}
76
+
77
+
43
78
var $lt = hydrateAndValue ( {
44
79
$lt : valueB
45
80
} , key , schemaProp ,
46
81
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]); */
48
104
}
49
105
} ;
50
106
} ) ;
0 commit comments