If I understand it correctly, you take the set filter, strip it into its args and body, replaces the "return true" with statements that add the row to the list of rows to be shown and "return false" with continue statements, and then basically create a new "compiled" filter version that is suited to work with the dataView object stuff. so for for filter I would:
1. instead of setFilter that sets a single filter I would create addFilter(filterName, filterHandler), and removeFilter(filterName). Under the hood instead of one single filter variable I would have a map filterMap :: {filterName:filterHandler}
1a. if we dont care about each filter then instead of creating new methods we can just update the existing one to accept as many params as you want (Java equivalent of varargs) and just use "arguments" property to iterate through all filters and put them into filterMap
2. Same for filterArgs
3. compiling methods (with and without cache) would then be changed as:
1. create filterInfo for each filter in the filterMap. would put it into an array.
2. for each of them would create an anonimous function call string and replace all the $item and $args, just like it is done right now for one filter
3. would create a single string that calls those anonymous functions one by one.
4. at the place where you create your own filter you have a line of new code that calls the filter: "$filter$" which is replaces with the body of the set filter - this would be changed with that string that calls those anonymous functions. Just like before anyone of them can call "continue _coreloop" so we will not be calling ALL of the filters all the time. So no worries there
4 In case of allowing unlimited nubmer fo filters - it would invoke the filtering just like it is rignt now, and in case of add/remove methods - we would need to have a method something like "dataView.filterItems() that would invoke this brilliance! :)))
and that should do it i think. in the end these methods will return just one single function like it does rignt now, but it would call all the filters added, instead just one.
With sorting, i think it is a little bit easier. Though it has a different approach since unlike with filter you dont store it anywhere, just sorting items and done. So
1. Either go with filter option 1a to allow multiple comparer (the order of params would have to change though. instead of sort(comparaer, asc) now it would be sort(asc, comparer1[ ,comparere2..comparerN]). But it might be a bit painful for current users...
1a. or I would have as with filters option 1 and create addSortComaprator removeSortComparator and have the map to store it. Though usually the order of sort algorithms is important, so array might be a better solution to preserve the order of comperer
2. Create a new "compiled" comparer from the chain of eaich of the coparers where each of them is is calling next one it it returns 0 (if -1 or 1 is returned the job is done)
3. Apply the compiled comparer to the items: items.sort(myNewShinyComparer);
4. Same with invoking the sorting as with filters.
How does that sound? :)
On Thursday, January 10, 2013 11:30:51 AM UTC-8, Tin wrote:
What would you propose?