forked from tomchentw-deprecated/ng-fire-alarm
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathng-fire-alarm.min.js
5 lines (5 loc) · 4.12 KB
/
ng-fire-alarm.min.js
1
2
3
4
5
/*! ng-fire-alarm - v 0.4.2 - Sun Feb 09 2014 22:01:07 GMT+0800 (CST)
* https://github.com/tomchentw/ng-fire-alarm
* Copyright (c) 2014 [tomchentw](https://github.com/tomchentw/);
* Licensed [MIT](http://tomchentw.mit-license.org/)
*/(function(){function t(t,n){return o(n)&&(n.$name=t.name(),n.$priority=t.getPriority()),n}function n(n,i){var e;return e=n.val(),null===e?t(n,i):o(e)?(t(n,e),o(i)?angular.extend(i,e):e):e}function i(t){return function(n){n?t.reject(n):t.resolve()}}function e(t,n){function i(){}return i.prototype=(t.superclass=n).prototype,(t.prototype=new i).constructor=t,"function"==typeof n.extended&&n.extended(t),t}function r(t,n){var i={}.hasOwnProperty;for(var e in n)i.call(n,e)&&(t[e]=n[e]);return t}var o,s,a,h,u,c=[].slice;o=angular.isObject,s=function(){function t(t,n,i){var e=this;this._query=t,this._defer=n,this._isSingleton=!0===i.singlecton,this._singlecton=void 0,setTimeout(function(){e.startWatching()})}t.displayName="AlarmReceiver";var n=t.prototype,i=t;return t.create=function(t,n,i){var e;return new(e=!0===i.collection?h:a)(t,n,i)},n.update=function(t,n){var e;return e=this._query,e.on("value",angular.noop,angular.noop,i),this.stopWatching(),this._query=e[t](n),this.startWatching(),e.off("value",void 0,i)},n.notify=function(t){this._defer.notify(this._isSingleton?this._singlecton:t)},n.onError=function(t){this._defer.reject(t)},t}(),a=function(t){function i(){i.superclass.apply(this,arguments)}var o=e((r(i,t).displayName="Fireman",i),t).prototype;return o.startWatching=function(){this._query.on("value",this.onValue,this.onError,this)},o.stopWatching=function(){this._query.off("value",void 0,this)},o.onValue=function(t){var i;i=n(t,this._singlecton),this._isSingleton&&!this._singlecton&&(this._singlecton=i),this.notify(i)},i}(s),h=function(t){function i(){i.superclass.apply(this,arguments),this._isSingleton=!0,this._singlecton=[],this._names={}}var s=e((r(i,t).displayName="Firemen",i),t).prototype;return s.notify=function(){var n;(n=this._singlecton[0])&&(this._singlecton[0]=JSON.parse(JSON.stringify(n))),t.prototype.notify.call(this)},s.startWatching=function(){this._query.on("child_added",this.onChildChanged,this.onError,this),this._query.on("child_changed",this.onChildChanged,this.onError,this),this._query.on("child_moved",this.onChildChanged,this.onError,this),this._query.on("child_removed",this.onChildRemoved,this.onError,this)},s.stopWatching=function(){this._query.off("child_added",void 0,this),this._query.off("child_changed",void 0,this),this._query.off("child_moved",void 0,this),this._query.off("child_removed",void 0,this)},s.rebuildNameIndex=function(t,n){var i,e,r,s,a,h;for(i=this._singlecton,e=this._names,r=t,s=n||i.length;s>r;++r)a=r,h=i[a],o(h)&&(h.$index=e[h.$name]=a)},s.indexOf=function(t,n){var i,e;return i=this._names,t in i?(e=i[t],n&&delete i[t],e):-1},s.onChildChanged=function(t,i){var e,r,o,s,a;e=this._singlecton,r=t.name(),o=this.indexOf(r,!0),-1!==o&&(s=e.splice(o,1)[0]),a=this._names[r]=1+this.indexOf(i),e.splice(a,0,n(t,s)),this.rebuildNameIndex(a),this.notify()},s.onChildRemoved=function(t){var n;n=this.indexOf(t.name(),!0),this._singlecton.splice(n,1),this.rebuildNameIndex(n),this.notify()},i}(s),u=function(){function t(t,n){this.$promise=t,this._ar=function(){return n}}t.displayName="FireAlarm";var n,e,r=t.prototype,o=t;return t.$q=void 0,r.$query=function(){return this._ar()._query},r.$ref=function(){return this.$query().ref()},n=["limit","startAt","endAt"],angular.forEach(n,function(t){r["$"+t]=function(n){this._ar().update(t,n)}}),e=["remove","push","update","set","setPriority","setWithPriority"],angular.forEach(e,function(t,n){var e;e=function(){switch(n){case 0:return 0;case 5:return 2;default:return 1}}(),r["$"+t]=function(){var n,r,s;return n=c.call(arguments,0,e),r=o.$q.defer(),n.push(i(r)),(s=this.$ref())[t].apply(s,n),r.promise}}),r.$thenNotify=function(t){return this.$promise=this.$promise.then(void 0,void 0,t),this},t}(),angular.module("ng-fire-alarm",[]).value("Firebase",Firebase).run(["$q","Firebase"].concat(function(t,n){return u.$q=t,n.prototype.$toAlarm=function(n){var i,e;return n||(n={}),i=t.defer(),e=s.create(this,i,n),new u(i.promise,e,n)}}))}).call(this);