<commit_before># [ngResourceCollection](http://mgcrea.github.com/angular-resource-collection) [![Build Status](https://secure.travis-ci.org/mgcrea/angular-resource-collection.png?branch=master)](http://travis-ci.org/#!/mgcrea/angular-resource-collection)

ngResourceCollection is a thin wrapper over the official 1.2.0+ [ngCollection](https://github.com/angular/angular.js/blob/master/src/ngResource/resource.js).
It adds a few useful methods to work with your `$resource` data, along every underscore/lodash method available:

``` javascript
var methods = ['forEach', 'each', 'map', 'collect', 'reduce', 'foldl',
        'inject', 'reduceRight', 'foldr', 'find', 'detect', 'filter', 'select',
        'reject', 'every', 'all', 'some', 'any', 'include', 'contains', 'invoke',
        'max', 'min', 'toArray', 'size', 'first', 'head', 'take', 'initial', 'rest',
        'tail', 'drop', 'last', 'without', 'indexOf', 'shuffle', 'lastIndexOf',
        'isEmpty'];
```



## Quick start

+ Install the module with [bower](http://bower.io/)

``` bash
$ bower install angular-resource-collection --save
```

+ Include the required libraries (cdn/local):

>
``` html
<script src="components/angular-resource-master/angular-resource.min.js"></script>
<script src="//cdnjs.cloudflare.com/ajax/libs/lodash.js/1.3.1/lodash.min.js"></script>
<!-- or "//cdnjs.cloudflare.com/ajax/libs/underscore.js/1.4.4/underscore-min.js" -->
```

+ Inject the `resourceCollection` module into your app:

>
``` javascript
var app = angular.module('myApp', ['mgcrea.resourceCollection']);
```



## Examples

The main use case it to be able to do:

``` javascript
'use strict';

angular.module('myApp')

  .factory('User', function($collection) {
    return $collection(REMOTE_URL + '/users/:userId?login=pocus');
  })

  .controller('NetworkCtrl', function($scope, User) {
    $scope.users = User.query().$promise;
  })

  .controller('NetworkUserCtrl', function($scope, User) {
    $scope.user = User.getById($routeParams.userId); // will used existing data previously fetch by `query()`
    // longer equivalent
    $scope.user = User.find(function(user) {
       return user._id = $routeParams.userId;
    });
  });
```



## Contributing
<commit_msg>chore(readme): explain module purpose<commit_after># [ngResourceCollection](http://mgcrea.github.com/angular-resource-collection) [![Build Status](https://secure.travis-ci.org/mgcrea/angular-resource-collection.png?branch=master)](http://travis-ci.org/#!/mgcrea/angular-resource-collection)

ngResourceCollection is a thin wrapper over the official 1.2.0+ [ngCollection](https://github.com/angular/angular.js/blob/master/src/ngResource/resource.js).

Its main purpose is to provide an efficient global caching system over `$resource.query()` that is not reset between each client-side route-navigation (no view flickering). You can also leverage 1.2.0+ `track by` attribute for the `ngRepeat` directive to minimize DOM manipulation on collection refresh.

It also adds a few useful methods to work with your `$resource` data, along every underscore/lodash method available:

``` javascript
var methods = ['forEach', 'each', 'map', 'collect', 'reduce', 'foldl',
        'inject', 'reduceRight', 'foldr', 'find', 'detect', 'filter', 'select',
        'reject', 'every', 'all', 'some', 'any', 'include', 'contains', 'invoke',
        'max', 'min', 'toArray', 'size', 'first', 'head', 'take', 'initial', 'rest',
        'tail', 'drop', 'last', 'without', 'indexOf', 'shuffle', 'lastIndexOf',
        'isEmpty'];
```



## Quick start

+ Install the module with [bower](http://bower.io/)

``` bash
$ bower install angular-resource-collection --save
```

+ Include the required libraries (cdn/local):

>
``` html
<script src="components/angular-resource-master/angular-resource.min.js"></script>
<script src="//cdnjs.cloudflare.com/ajax/libs/lodash.js/1.3.1/lodash.min.js"></script>
<!-- or "//cdnjs.cloudflare.com/ajax/libs/underscore.js/1.4.4/underscore-min.js" -->
```

+ Inject the `resourceCollection` module into your app:

>
``` javascript
var app = angular.module('myApp', ['mgcrea.resourceCollection']);
```



## Examples

The main use case it to be able to do:

``` javascript
'use strict';

angular.module('myApp')

  .factory('User', function($collection) {
    return $collection(REMOTE_URL + '/users/:userId?login=pocus');
  })

  .controller('NetworkCtrl', function($scope, User) {
    $scope.users = User.query().$promise; // will leverage existing data before reloading with `query()`
  })

  .controller('NetworkUserCtrl', function($scope, User) {
    $scope.user = User.getById($routeParams.userId); // will use existing data previously fetched by `query()` in another route
    // longer equivalent
    $scope.user = User.find(function(user) {
       return user._id = $routeParams.userId;
    });
  });
```



## Contributing

{'fraction_non_alphanumeric': 0.18159408381265407, 'fraction_numerical': 0.004313886606409203, 'mean_word_length': 4.4402234636871505, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 17, 'https://': 4, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3765165', 'n_tokens_mistral': 1579, 'n_tokens_neox': 1495, 'n_words': 366}