# All files / src filter.js

100% Statements 21/21
100% Branches 8/8
100% Functions 2/2
100% Lines 19/19

Press n or j to go to the next uncovered block, b, p or k for the previous block.

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    2917x

    90x
    90x

    90x
    69x
    69x
    69x
    69x
    47x

    22x
    22x
    22x
    122x
    122x
    70x

    52x

    69x
    69x
    69x

     module.exports = function (list) {
      // Add handlers
      list.handlers.filterStart = list.handlers.filterStart || []
      list.handlers.filterComplete = list.handlers.filterComplete || []

      return function (filterFunction) {
        list.trigger('filterStart')
        list.i = 1 // Reset paging
        list.reset.filter()
        if (filterFunction === undefined) {
          list.filtered = false
        } else {
          list.filtered = true
          var is = list.items
          for (var i = 0, il = is.length; i < il; i++) {
            var item = is[i]
            if (filterFunction(item)) {
              item.filtered = true
            } else {
              item.filtered = false
            }
          }
        }
        list.update()
        list.trigger('filterComplete')
        return list.visibleItems
      }
    }