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

Commit c485405

Browse files
committed
Merge pull request #549 from firebase/jw-error-on-array
Added error message when trying to use array-like data stored in Firebase
2 parents d5f7ad9 + 1e749e7 commit c485405

File tree

2 files changed

+18
-4
lines changed

2 files changed

+18
-4
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: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@
99
//
1010
// * `ref`: A Firebase reference. Queries or limits may be applied.
1111
// * `config`: An object containing any of the advanced config options explained in API docs
12-
.factory("$firebase", [ "$firebaseUtils", "$firebaseConfig",
13-
function ($firebaseUtils, $firebaseConfig) {
12+
.factory("$firebase", [ "$log", "$firebaseUtils", "$firebaseConfig",
13+
function ($log, $firebaseUtils, $firebaseConfig) {
1414
function AngularFire(ref, config) {
1515
// make the new keyword optional
1616
if (!(this instanceof AngularFire)) {
@@ -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+
$log.warn('Storing data using array indices in Firebase can result in unexpected behavior. See https://www.firebase.com/docs/web/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+
$log.warn('Storing data using array indices in Firebase can result in unexpected behavior. See https://www.firebase.com/docs/web/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)