forked from FirebaseExtended/emberfire
-
Notifications
You must be signed in to change notification settings - Fork 0
/
emberfire-latest.min.js
1 lines (1 loc) · 2.37 KB
/
emberfire-latest.min.js
1
"use strict";var EmberFire=Ember.Namespace.create();EmberFire.coerce=function(a){var b=a.val(),c=a.ref(),d=b._type;switch(d){case"object":b=EmberFire.Object.create({ref:c});break;case"array":b=EmberFire.Array.create({ref:c});break;case"objectArray":b=EmberFire.ObjectArray.create({ref:c})}return b},EmberFire.ObjectMixin=Ember.Mixin.create({type:null,typeKey:"_type",init:function(){this.ref.child(this.typeKey).set(this.type),this.ref.on("child_added",function(a){a.name()!=this.typeKey&&this.childAdded(a)},this),this.ref.on("child_removed",function(a){a.name()!=this.typeKey&&this.childRemoved(a)},this),this.ref.on("child_changed",function(a){a.name()!=this.typeKey&&this.childChanged(a)},this),this.ref.on("value",function(a){a.name()!=this.typeKey&&this.valueChanged(a)},this),this._super()},childAdded:function(){},childChanged:function(){},childRemoved:function(){},valueChanged:function(){},willDestroy:function(){this.ref.off()}}),EmberFire.Object=Ember.ObjectProxy.extend(EmberFire.ObjectMixin,{type:"object",ref:null,init:function(){this.set("content",{}),this._super()},valueChanged:function(a){this.set("content",a.val())},toJSON:function(){var a={},b=this.get("content");for(var c in b)a[c]=Ember.get(b,c);return a._type="object",a},setUnknownProperty:function(a,b){return this.ref.child(a).set(b),this._super(a,b)}}),EmberFire.Array=Ember.ArrayProxy.extend(EmberFire.ObjectMixin,{type:"array",coerceChild:EmberFire.coerce,init:function(){this._array=Ember.A([]),this._index=Ember.A([]),this.set("content",this._array),this._super()},childAdded:function(a){var b=this.coerceChild(a),c=a.name();this._index.pushObject(c),this._array.pushObject(b)},childRemoved:function(a){var b=this._index.indexOf(a.name());this._index.removeAt(b),this._array.removeAt(b)},childChanged:function(a){var b=this._index.indexOf(a.name()),c=this._array.objectAt(b),d=c instanceof EmberFire.Object;if(!d){var e=this.coerceChild(a);this._array.replace(b,1,[e])}},replaceContent:function(a,b,c){for(var d=0;b>d;d++){var e=this._index[a+d];this.ref.child(e).remove()}c.forEach(function(a){var b=a;return a.toJSON&&(b=a.toJSON()),this.ref.push(b).name()},this)},toJSON:function(){for(var a={},b=this.get("content"),c=0;c<this._index.length;c++)a[this._index[c]]=b[c];return a._type=this.type,a}}),EmberFire.ObjectArray=EmberFire.Array.extend({type:"objectArray",coerceChild:function(a){return EmberFire.Object.create({ref:a.ref()})}});