Skip to content
This repository was archived by the owner on Mar 17, 2025. It is now read-only.

Commit dddf524

Browse files
author
jwngr
committed
Added error message when trying to use array-like data stored in Firebase
1 parent 83edb53 commit dddf524

File tree

2 files changed

+16
-2
lines changed

2 files changed

+16
-2
lines changed

src/FirebaseArray.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -210,6 +210,8 @@
210210
$loaded: function(resolve, reject) {
211211
var promise = this._promise;
212212
if( arguments.length ) {
213+
// allow this method to be called just like .then
214+
// by passing any arguments on to .then
213215
promise = promise.then.call(promise, resolve, reject);
214216
}
215217
return promise;

src/firebase.js

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,13 @@
202202
ref.on('child_removed', removed, error);
203203

204204
// determine when initial load is completed
205-
ref.once('value', function() { resolve(null); }, resolve);
205+
ref.once('value', function(snap) {
206+
if (angular.isArray(snap.val())) {
207+
throw new Error('Storing data using array indices in Firebase can result in unexpected behavior. See https://www.firebase.com/docs/rest/guide/understanding-data.html#section-arrays-in-firebase for more information.');
208+
}
209+
210+
resolve(null);
211+
}, resolve);
206212
}
207213

208214
// call resolve(), do not call this directly
@@ -281,7 +287,13 @@
281287

282288
function init() {
283289
ref.on('value', applyUpdate, error);
284-
ref.once('value', function() { resolve(null); }, resolve);
290+
ref.once('value', function(snap) {
291+
if (angular.isArray(snap.val())) {
292+
throw new Error('Storing data using array indices in Firebase can result in unexpected behavior. See https://www.firebase.com/docs/rest/guide/understanding-data.html#section-arrays-in-firebase for more information.');
293+
}
294+
295+
resolve(null);
296+
}, resolve);
285297
}
286298

287299
// call resolve(); do not call this directly

0 commit comments

Comments
 (0)