forked from tomkuk/angular-collection
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathangular-collection.min.js
More file actions
7 lines (7 loc) · 2.57 KB
/
angular-collection.min.js
File metadata and controls
7 lines (7 loc) · 2.57 KB
1
2
3
4
5
6
7
/**
* Angular Collection - The Collection module for AngularJS
* @version v0.2.0 - 2013-05-02
* @author Tomasz Kuklis
* @license MIT License, http://www.opensource.org/licenses/MIT
*/
"use strict";angular.module("ngCollection",[]).factory("$collection",["$filter","$parse",function(t,r){function i(){return Math.floor(65536*(1+Math.random())).toString(16).substring(1)}function n(){return i()+i()+"-"+i()+"-"+i()+"-"+i()+"-"+i()+i()+i()}function e(t){t||(t={}),void 0!==t.comparator&&(this.comparator=t.comparator),this.idAttribute=t.idAttribute||this.idAttribute,this.current=null,this._reset(),this.initialize.apply(this,arguments)}return e.prototype={idAttribute:"id",initialize:function(){},add:function(t,r){r||(r={});var i,e,a,s,o;return e=this.comparator&&r.sort!==!1,a=angular.isString(this.comparator)?this.comparator:null,e&&!s&&(s=!0),t[this.idAttribute]||(t[this.idAttribute]=n()),(o=this.get(t))?angular.extend(o,t):(i=t[this.idAttribute],this.hash[i]=t,this.array.push(t),this.length+=1),s&&this.sort(),this},addAll:function(t,r){for(var i=0;t.length>i;i++){var n=t[i];this.add(n,r)}return this},sort:function(){return angular.isString(this.comparator)&&(this.array=t("orderBy")(this.array,this.comparator)),this},get:function(t){return null==t?void 0:(this._idAttr||(this._idAttr=this.idAttribute),this.hash[t.id||t[this._idAttr]||t])},find:function(t,i){if("string"!=typeof t)throw Error("The key must be a string!");for(var n=r(t),e=0;this.array.length>e;e++)if(n(this.array[e])===i)return this.array[e];return void 0},findAll:function(t,i){var n=[];if("string"!=typeof t)throw Error("The key must be a string!");for(var e=r(t),a=0;this.array.length>a;a++)e(this.array[a])===i&&n.push(this.array[a]);return n},update:function(t){var r;return r=this.get(t),r&&angular.extend(r,t),r||this.add(t),this},remove:function(t){var r;return delete this.hash[t.id],r=this.array.indexOf(t),this.array.splice(r,1),this.length--,this},removeAll:function(){for(var t=this.array.length-1;t>=0;t--)this.remove(this.at(t));return this},last:function(){return this.array[this.length-1]},at:function(t){return this.array[t]},size:function(){return this.array.length},all:function(){return this.array},_reset:function(){this.length=0,this.hash={},this.array=[]}},e.extend=function(t){var r,i=this;r=t&&t.hasOwnProperty("constructor")?t.constructor:function(){return i.apply(this,arguments)};var n=function(){this.constructor=r};return n.prototype=i.prototype,r.prototype=new n,t&&angular.extend(r.prototype,t),r.extend=i.extend,r.getInstance=e.getInstance,r._super=i.prototype,r},e.getInstance=function(t){return new this(t)},e}]);