dist/index.js
function onChildAdded(dbRef, fromCacheCallback, newDataArrivingCallback, snapCallback, cancelCallbackOrContext, context) {
		var storageKey = getStorageKeyFromDbRef(dbRef, 'child_added');

		return _reactNative.AsyncStorage.getItem(storageKey).then(function (value) {
			// Called processedCallback with cached value.
			if (value !== null) {
				var cachedVal = JSON.parse(value);
				callWithContext(fromCacheCallback, cachedVal, cancelCallbackOrContext, context);
			}
		}).then(function () {
			var firstData = true;

			var callbackIntercept = function callbackIntercept(snap) {
				//Call the data arriving callback the first time new data comes in.
				if (firstData) {
					firstData = false;
					newDataArrivingCallback.bind(this)();
				}
				//Then call the snapCallback as normal.
				snapCallback.bind(this)(snap);
			};

			dbRef.on('child_added', callbackIntercept, cancelCallbackOrContext, context);
		});
	}
function onChildAdded(dbRef, fromCacheCallback, newDataArrivingCallback, snapCallback, cancelCallbackOrContext, context) {
		var storageKey = getStorageKeyFromDbRef(dbRef, 'child_added');

		return _reactNative.AsyncStorage.getItem(storageKey).then(function (value) {
			// Called processedCallback with cached value.
			if (value !== null) {
				var cachedVal = JSON.parse(value);
				callWithContext(fromCacheCallback, cachedVal, cancelCallbackOrContext, context);
			}
		}).then(function () {
			var firstData = true;

			var callbackIntercept = function callbackIntercept(snap) {
				//Call the data arriving callback the first time new data comes in.
				if (firstData) {
					firstData = false;
					newDataArrivingCallback.bind(this)();
				}
				//Then call the snapCallback as normal.
				snapCallback.bind(this)(snap);
			};

			dbRef.on('child_added', callbackIntercept, cancelCallbackOrContext, context);
		});
	}
function onChildAdded ( dbRef , fromCacheCallback , newDataArrivingCallback , snapCallback , cancelCallbackOrContext , context ) { var storageKey = getStorageKeyFromDbRef ( dbRef , 'child_added' ) ; return _reactNative . AsyncStorage . getItem ( storageKey ) . then ( function ( value ) { // Called processedCallback with cached value. if ( value !== null ) { var cachedVal = JSON . parse ( value ) ; callWithContext ( fromCacheCallback , cachedVal , cancelCallbackOrContext , context ) ; } } ) . then ( function ( ) { var firstData = true ; var callbackIntercept = function callbackIntercept ( snap ) { //Call the data arriving callback the first time new data comes in. if ( firstData ) { firstData = false ; newDataArrivingCallback . bind ( this ) ( ) ; } //Then call the snapCallback as normal. snapCallback . bind ( this ) ( snap ) ; } ; dbRef . on ( 'child_added' , callbackIntercept , cancelCallbackOrContext , context ) ; } ) ; }
Create an 'child_added' on listener that will first return any cached data saved by a call to offChildAdded. When fresh data arrives, newDataArrivingCallback will be called once, followed by the standard snap callback. From this point on only the snapCallback will be called.
@param {firebase.database.Reference} dbRef Firebase database reference to listen at.
@param {*} fromCacheCallback Callback that will be called with cached data if any is available.
@param {*} newDataArrivingCallback Callback called immediately before fresh data starts arriving.
@param {*} snapCallback Callback called when new data snapshots arrive from the server.
@param {*} cancelCallbackOrContext Optional callback that will be called in the case of an error, e.g. forbidden.
@param {*} context Optional context that will be bound to `this` in callbacks.
@returns {Promise} Resolves when the cache has been read and listener attached to DB ref.
Create an child_added on listener that will first return any cached data saved by a call to offChildAdded . When fresh data arrives newDataArrivingCallback will be called once followed by the standard snap callback . From this point on only the snapCallback will be called .