Files
reactfire/dist/reactfire.min.js
2014-11-06 19:23:55 +00:00

10 lines
2.3 KiB
JavaScript

/*!
* ReactFire is an open-source JavaScript library that allows you to add a
* realtime data source to your React apps by providing and easy way to let
* Firebase populate the state of React components.
*
* ReactFire 0.4.0
* https://github.com/firebase/reactfire/
* License: MIT
*/
!function(e,t){"use strict";"function"==typeof define&&define.amd?define([],function(){return e.ReactFireMixin=t()}):"object"==typeof exports?module.exports=t():e.ReactFireMixin=t()}(this,function(){"use strict";var e={componentWillMount:function(){this.firebaseRefs={},this.firebaseListeners={}},componentWillUnmount:function(){for(var e in this.firebaseRefs)this.firebaseRefs.hasOwnProperty(e)&&this.unbind(e)},bindAsArray:function(e,t,i){this._bind(e,t,i,!0)},bindAsObject:function(e,t,i){this._bind(e,t,i,!1)},_bind:function(e,t,i,n){this._validateBindVar(t);var r,o;if("[object Object]"!==Object.prototype.toString.call(e)?(r="firebaseRef must be an instance of Firebase",o="INVALID_FIREBASE_REF"):"boolean"!=typeof n&&(r="bindAsArray must be a boolean. Got: "+n,o="INVALID_BIND_AS_ARRAY"),"undefined"!=typeof r){var s=new Error("ReactFire: "+r);throw s.code=o,s}this.firebaseRefs[t]=e.ref(),this.firebaseListeners[t]=e.on("value",function(e){var i={};i[t]=n?this._toArray(e.val()):e.val(),this.setState(i)}.bind(this),i)},unbind:function(e){if(this._validateBindVar(e),"undefined"==typeof this.firebaseRefs[e]){var t=new Error('ReactFire: unexpected value for bindVar. "'+e+'" was either never bound or has already been unbound');throw t.code="UNBOUND_BIND_VARIABLE",t}this.firebaseRefs[e].off("value",this.firebaseListeners[e]),delete this.firebaseRefs[e],delete this.firebaseListeners[e]},_validateBindVar:function(e){var t;if("string"!=typeof e?t="bindVar must be a string. Got: "+e:0===e.length?t='bindVar must be a non-empty string. Got: ""':e.length>768?t="bindVar is too long to be stored in Firebase. Got: "+e:/[\[\].#$\/\u0000-\u001F\u007F]/.test(e)&&(t="bindVar cannot contain any of the following characters: . # $ ] [ /. Got: "+e),"undefined"!=typeof t){var i=new Error("ReactFire: "+t);throw i.code="INVALID_BIND_VARIABLE",i}},_isArray:function(e){return"[object Array]"===Object.prototype.toString.call(e)},_toArray:function(e){var t=[];if(e)if(this._isArray(e))t=e;else if("object"==typeof e)for(var i in e)e.hasOwnProperty(i)&&t.push(e[i]);return t}};return e});