|
1 | 1 | /** |
2 | 2 | * Bunch of useful filters for angularJS(with no external dependencies!) |
3 | | - * @version v0.5.5 - 2015-08-07 * @link https://github.com/a8m/angular-filter |
| 3 | + * @version v0.5.6 - 2015-09-23 * @link https://github.com/a8m/angular-filter |
4 | 4 | * @author Ariel Mashraki <ariel@mashraki.co.il> |
5 | 5 | * @license MIT License, http://www.opensource.org/licenses/MIT |
6 | 6 | */ |
@@ -416,32 +416,38 @@ angular.module('a8m.before', []) |
416 | 416 | * Collect data into fixed-length chunks or blocks |
417 | 417 | */ |
418 | 418 |
|
419 | | -angular.module('a8m.chunk-by', []) |
420 | | - .filter('chunkBy', [function () { |
421 | | - /** |
422 | | - * @description |
423 | | - * Get array with size `n` in `val` inside it. |
424 | | - * @param n |
425 | | - * @param val |
426 | | - * @returns {Array} |
427 | | - */ |
428 | | - function fill(n, val) { |
429 | | - var ret = []; |
430 | | - while(n--) ret[n] = val; |
431 | | - return ret; |
432 | | - } |
| 419 | +angular.module('a8m.chunk-by', ['a8m.filter-watcher']) |
| 420 | + .filter('chunkBy', ['filterWatcher', function (filterWatcher) { |
| 421 | + return function (array, n, fillVal) { |
| 422 | + |
| 423 | + return filterWatcher.isMemoized('chunkBy', arguments) || |
| 424 | + filterWatcher.memoize('chunkBy', arguments, this, |
| 425 | + _chunkBy(array, n, fillVal)); |
| 426 | + /** |
| 427 | + * @description |
| 428 | + * Get array with size `n` in `val` inside it. |
| 429 | + * @param n |
| 430 | + * @param val |
| 431 | + * @returns {Array} |
| 432 | + */ |
| 433 | + function fill(n, val) { |
| 434 | + var ret = []; |
| 435 | + while (n--) ret[n] = val; |
| 436 | + return ret; |
| 437 | + } |
433 | 438 |
|
434 | | - return function (array, n, fillVal) { |
435 | | - if (!isArray(array)) return array; |
436 | | - return array.map(function(el, i, self) { |
437 | | - i = i * n; |
438 | | - el = self.slice(i, i + n); |
439 | | - return !isUndefined(fillVal) && el.length < n |
440 | | - ? el.concat(fill(n - el.length, fillVal)) |
441 | | - : el; |
442 | | - }).slice(0, Math.ceil(array.length / n)); |
443 | | - } |
444 | | - }]); |
| 439 | + function _chunkBy(array, n, fillVal) { |
| 440 | + if (!isArray(array)) return array; |
| 441 | + return array.map(function (el, i, self) { |
| 442 | + i = i * n; |
| 443 | + el = self.slice(i, i + n); |
| 444 | + return !isUndefined(fillVal) && el.length < n |
| 445 | + ? el.concat(fill(n - el.length, fillVal)) |
| 446 | + : el; |
| 447 | + }).slice(0, Math.ceil(array.length / n)); |
| 448 | + } |
| 449 | + } |
| 450 | + }]); |
445 | 451 |
|
446 | 452 | /** |
447 | 453 | * @ngdoc filter |
@@ -850,11 +856,9 @@ angular.module('a8m.group-by', [ 'a8m.filter-watcher' ]) |
850 | 856 | return collection; |
851 | 857 | } |
852 | 858 |
|
853 | | - var getterFn = $parse(property); |
854 | | - |
855 | 859 | return filterWatcher.isMemoized('groupBy', arguments) || |
856 | 860 | filterWatcher.memoize('groupBy', arguments, this, |
857 | | - _groupBy(collection, getterFn)); |
| 861 | + _groupBy(collection, $parse(property))); |
858 | 862 |
|
859 | 863 | /** |
860 | 864 | * groupBy function |
@@ -2126,7 +2130,7 @@ angular.module('a8m.filter-watcher', []) |
2126 | 2130 | $$timeout(function() { |
2127 | 2131 | if(!$rootScope.$$phase) |
2128 | 2132 | $$cache = {}; |
2129 | | - }); |
| 2133 | + }, 2000); |
2130 | 2134 | } |
2131 | 2135 |
|
2132 | 2136 | /** |
|
0 commit comments