-
Notifications
You must be signed in to change notification settings - Fork 30
/
angular-collection.min.js
8 lines (7 loc) · 2.64 KB
/
angular-collection.min.js
1
2
3
4
5
6
7
8
/**
* Angular Collection - The Collection module for AngularJS
* @version v0.5.3 - 2018-06-18
* @author Tomasz Kuklis
* @license MIT License, http://www.opensource.org/licenses/MIT
*/
!function(t,u){"use strict";u.module("ngCollection",[]).factory("$collection",["$filter","$parse",function(r,s){function a(){return Math.floor(65536*(1+Math.random())).toString(16).substring(1)}function h(t,r){return r(t)}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){var i,n,e,o;return r||(r={}),n=!1!==r.sort,o=void 0!==r.index?r.index:this.array.length,t[this.idAttribute]||(t[this.idAttribute]=a()+a()+"-"+a()+"-"+a()+"-"+a()+"-"+a()+a()+a()),(e=this.get(t))?u.extend(e,t):(i=t[this.idAttribute],this.hash[i]=t,this.array.splice(o,0,t),this.length+=1),n&&this.sort(),this},addAll:function(t,r){r||(r={});for(var i=!1!==r.sort,n=0;n<t.length;n++){var e=t[n];this.add(e,u.extend(r,{sort:!1}))}return i&&this.sort(),this},sort:function(t){return(t=t||this.comparator)&&(this.array=r("orderBy")(this.array,t)),this},get:function(t){if(null!=t)return this.hash[t[this.idAttribute]||t]},find:function(t,r,i){var n=t;if("string"==typeof t){var e=s(t);(n=function(t){return i?e(t)==r:e(t)===r}).prototype.value=r,n.prototype.deepCompare=i}for(var o=0;o<this.array.length;o++)if(h(this.array[o],n))return this.array[o]},where:function(t,r,i){var n=[],e=t;if("string"==typeof t){var o=s(t);(e=function(t){return o(t)===r}).prototype.value=r,e.prototype.deepCompare=i}for(var a=0;a<this.array.length;a++)h(this.array[a],e)&&n.push(this.array[a]);return n},update:function(t){var r;return(r=this.get(t))&&u.extend(r,t),r||this.add(t),this},remove:function(t){var r;return-1===(r=this.array.indexOf(t))||(delete this.hash[t[this.idAttribute]],this.array.splice(r,1),this.length--),this},removeAll:function(){for(var t=this.array.length-1;0<=t;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&&u.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}])}(window,window.angular);