-
Notifications
You must be signed in to change notification settings - Fork 15
/
Copy pathhoodie.angularjs.min.js
1 lines (1 loc) · 2.73 KB
/
hoodie.angularjs.min.js
1
angular.module("hoodie",[]),angular.module("hoodie").factory("hoodieAccount",["$rootScope","hoodie","$q",function(n,e,o){var t={};return angular.forEach(e.account,function(n,a){t[a]=angular.isFunction(n)?function(){return o.when(e.account[a].apply(e.account,arguments))}:e.account[a]}),angular.forEach(["signup","signin","signout","authenticated","unauthenticated"],function(o){e.account.on(o,function(e){n.$apply(function(){t.username=e}),n.$emit("hoodie:"+o,arguments)})}),t.username=e.account.username,t}]),angular.module("hoodie").factory("hoodieArray",["hoodieStore",function(n){function e(n,e){for(var o={},t=0;t<n.length;t++)o[n[t][e]]=n[t];return o}function o(n,o,t){var a,r={added:[],deleted:[],changed:[]},i=e(n,"id"),u=e(o,"id");for(a in i)u.hasOwnProperty(a)?t(u[a],i[a])||r.changed.push(u[a]):r.deleted.push(i[a]);for(var d in o)o[d].id||r.added.push(o[d]);return r}var t={};return t.bind=function(e,t,a){a=a||t,e[t]=e[t]||[],n.findAll(a).then(function(n){e[t]=n}),e.$watch(t,function(e,t){if(e!==t&&angular.isArray(e)&&angular.isArray(t)){var r,i,u=o(t,e,angular.equals);for(i in u.added)r=u.added[i],n.add(a,r);for(i in u.changed)r=u.changed[i],n.update(a,r.id,r);for(i in u.deleted)r=u.deleted[i],r.id&&n.remove(a,r.id)}else;},!0),n.on("change:"+a,function(){n.findAll(a).then(function(n){e[t]=n})})},{bind:t.bind}}]),angular.module("hoodie").factory("hoodieObject",["hoodieStore","$rootScope",function(n,e){function o(n,e){return angular.forEach(n,function(o,t){e.hasOwnProperty(t)||delete n[t]}),angular.extend(n,e),n}var t={};return t.bind=function(t,a){if(angular.isUndefined(t))throw new Error("[hoodie-angular-plugin(HoodieObjects.bind)]: A store must be given");var r,i={};return r=angular.isUndefined(a)?n.add(t,i).then(function(n){a=n.id,o(i,n)}):n.find(t,a).then(function(n){angular.extend(i,n)}),e.$watch(function(){return i},function(e){n.update(t,a,e)},!0),r.then(function(){e.$on("change:"+a+":"+t,function(n,e){o(i,e)})}),i},{bind:t.bind}}]),angular.module("hoodie").provider("hoodie",function(){var n;this.url=function(e){return arguments.length&&(n=e),e},this.$get=["$location",function(e){return n||(n=e.absUrl().replace("/#"+e.path(),"")),new Hoodie(n)}]}),angular.module("hoodie").factory("hoodieStore",["$rootScope","$q","hoodie",function(n,e,o){var t={};return angular.forEach(o.store,function(n,a){t[a]=angular.isFunction(n)?function(){return e.when(o.store[a].apply(o.store,arguments))}:o.store[a]}),t.findAll().then(function(n){n.forEach(function(n){var e=n.type;t[e]=t[e]||[],t[e].push(n)})}),o.store.on("change",function(e,o){n.$evalAsync(function(){var a=o.type,r=o.id;n.$emit(e,o),n.$emit("change",e,o),n.$emit(e+":"+a,o),n.$emit("change:"+a,e,o),n.$emit(e+":"+a+":"+r,o),n.$emit("change:"+a+":"+r,e,o),t.findAll(a).then(function(n){t[a]=n})})}),t}]);