Commit ea18decb authored by Randall Leeds's avatar Randall Leeds

Use 'match' instead of 'hits'.

The threadFilter only needs to be tracking the single message in
the container. It is the deepCount that aggregates the results.
There's no longer any reason to cache a __filterResult.
parent b8a81eb4
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
# @ngdoc type # @ngdoc type
# @name threadFilter.ThreadFilterController # @name threadFilter.ThreadFilterController
# #
# @property {Object} hits The number of messages that match the filters. # @property {boolean} match True if the last checked message was a match.
# #
# @description # @description
# `ThreadFilterController` provides an API for maintaining filtering over # `ThreadFilterController` provides an API for maintaining filtering over
...@@ -11,7 +11,7 @@ ...@@ -11,7 +11,7 @@
ThreadFilterController = [ ThreadFilterController = [
'viewFilter' 'viewFilter'
(viewFilter) -> (viewFilter) ->
@hits = 0 @match = false
@_active = false @_active = false
@_children = [] @_children = []
...@@ -86,18 +86,14 @@ ThreadFilterController = [ ...@@ -86,18 +86,14 @@ ThreadFilterController = [
# @description # @description
# Check whether a message container carries a message matching the # Check whether a message container carries a message matching the
# configured filters. If filtering is not active then the result is # configured filters. If filtering is not active then the result is
# always `true`. Updates the `hits` property to reflect changes in match # always `true`. Updates the `match` property to reflect the result.
# status of the container by caching the result is the `__filterResult`
# property of the container.
### ###
this.check = (container) -> this.check = (container) ->
unless container?.message then return false unless container?.message then return false
if this.active() if this.active()
match = !!viewFilter.filter([container.message], @_filters).length @match = !!viewFilter.filter([container.message], @_filters).length
else else
match = true @match = true
@hits += (match - !!container.__filterResult)
container.__filterResult = match
###* ###*
# @ngdoc method # @ngdoc method
...@@ -141,19 +137,22 @@ ThreadFilterController = [ ...@@ -141,19 +137,22 @@ ThreadFilterController = [
# The threadFilter directive utilizes the {@link searchfilter searchfilter} # The threadFilter directive utilizes the {@link searchfilter searchfilter}
# service to parse the expression passed in the directive attribute as a # service to parse the expression passed in the directive attribute as a
# faceted search query and configures its controller with the resulting # faceted search query and configures its controller with the resulting
# filters. It watches the `hits` property of the controller and updates # filters. It watches the `match` property of the controller and updates
# its thread's message count under the 'filter' key. # its thread's message count under the 'filter' key.
### ###
threadFilter = [ threadFilter = [
'$parse', 'searchfilter' '$parse', 'searchfilter'
($parse, searchfilter) -> ($parse, searchfilter) ->
linkFn = (scope, elem, attrs, [ctrl, thread, counter]) -> linkFn = (scope, elem, attrs, [ctrl, thread, counter]) ->
scope.$watch (-> ctrl.hits), (newValue=0, oldValue=0) -> if counter?
counter?.count 'match', newValue - oldValue scope.$watch (-> ctrl.match), (match, old) ->
if match and not old
counter.count 'match', 1
else if old
counter.count 'match', -1
scope.$on '$destroy', -> scope.$on '$destroy', ->
if thread.container then delete thread.container.__filterResult if ctrl.match then counter.count 'match', -1
counter?.count 'match', -ctrl.hits
if parentCtrl = elem.parent().controller('threadFilter') if parentCtrl = elem.parent().controller('threadFilter')
ctrl.filters parentCtrl.filters() ctrl.filters parentCtrl.filters()
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment