bitovi / training

Bitovi's training material
MIT License
19 stars 5 forks source link

Explain how to create a custom Compare for can-set algebra #9

Open ilyavf opened 7 years ago

ilyavf commented 7 years ago

Related issue https://github.com/canjs/can-set/issues/38

E.g. we want a list of items which date is less or equal to a given one:

model.getList( { date: { "$lte": someDate } } );

new set.Algebra(
    set.comparators.id("_id"),
    {
        date: function(a, b, aParent, bParent, ... ){
            // a === { "$lte": someDate }
            // b === undefined
            // aParent === { date: { "$lte": someDate } }
            // bParent === {}

            return ...;
        }
    }