11/**
22 * Bunch of useful filters for angularJS(with no external dependencies!)
3- * @version v0.5.0 - 2014-11-12 * @link https://github.com/a8m/angular-filter
3+ * @version v0.5.1 - 2014-11-12 * @link https://github.com/a8m/angular-filter
44 * @author Ariel Mashraki <[email protected] > 55 * @license MIT License, http://www.opensource.org/licenses/MIT
66 */
@@ -853,11 +853,6 @@ angular.module('a8m.group-by', [ 'a8m.filter-watcher' ])
853853
854854 var getterFn = $parse ( property ) ;
855855
856- // If it's called outside the DOM
857- if ( ! isScope ( this ) ) {
858- return _groupBy ( collection , getterFn ) ;
859- }
860- // Return the memoized|| memozie the result
861856 return filterWatcher . isMemoized ( 'groupBy' , arguments ) ||
862857 filterWatcher . memoize ( 'groupBy' , arguments , this ,
863858 _groupBy ( collection , getterFn ) ) ;
@@ -1975,7 +1970,7 @@ angular.module('a8m.wrap', [])
19751970angular . module ( 'a8m.filter-watcher' , [ ] )
19761971 . provider ( 'filterWatcher' , function ( ) {
19771972
1978- this . $get = [ function ( ) {
1973+ this . $get = [ '$window' , '$rootScope' , function ( $window , $rootScope ) {
19791974
19801975 /**
19811976 * Cache storing
@@ -1991,6 +1986,12 @@ angular.module('a8m.filter-watcher', [])
19911986 */
19921987 var $$listeners = { } ;
19931988
1989+ /**
1990+ * $timeout without triggering the digest cycle
1991+ * @type {function }
1992+ */
1993+ var $$timeout = $window . setTimeout ;
1994+
19941995 /**
19951996 * @description
19961997 * get `HashKey` string based on the given arguments.
@@ -2019,6 +2020,18 @@ angular.module('a8m.filter-watcher', [])
20192020 delete $$listeners [ id ] ;
20202021 }
20212022
2023+ /**
2024+ * @description
2025+ * for angular version that greater than v.1.3.0
2026+ * if clear cache when the digest cycle end.
2027+ */
2028+ function cleanStateless ( ) {
2029+ $$timeout ( function ( ) {
2030+ if ( ! $rootScope . $$phase )
2031+ $$cache = { } ;
2032+ } ) ;
2033+ }
2034+
20222035 /**
20232036 * @description
20242037 * Store hashKeys in $$listeners container
@@ -2062,8 +2075,13 @@ angular.module('a8m.filter-watcher', [])
20622075 var hashKey = getHashKey ( filterName , args ) ;
20632076 //store result in `$$cache` container
20642077 $$cache [ hashKey ] = result ;
2065- //add `$destroy` listener
2066- addListener ( scope , hashKey ) ;
2078+ // for angular versions that less than 1.3
2079+ // add to `$destroy` listener, a cleaner callback
2080+ if ( isScope ( scope ) ) {
2081+ addListener ( scope , hashKey ) ;
2082+ } else {
2083+ cleanStateless ( ) ;
2084+ }
20672085 return result ;
20682086 }
20692087
0 commit comments