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

Commit 05a4783

Browse files
committed
Merge pull request #258 from katowulf/master
Fixes #255 - orderByPriority always returns an array
2 parents 07e78ef + 7fa78f4 commit 05a4783

File tree

2 files changed

+26
-29
lines changed

2 files changed

+26
-29
lines changed

angularfire.js

Lines changed: 25 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -39,38 +39,35 @@
3939
// for more info see: https://www.firebase.com/docs/ordered-data.html
4040
angular.module("firebase").filter("orderByPriority", function() {
4141
return function(input) {
42-
if (!input) {
43-
return [];
44-
}
45-
if (!input.$getIndex || typeof input.$getIndex != "function") {
46-
// If input is an object, map it to an array for the time being.
47-
var type = Object.prototype.toString.call(input);
48-
if (typeof input == "object" && type == "[object Object]") {
49-
var ret = [];
50-
for (var prop in input) {
51-
if (input.hasOwnProperty(prop)) {
52-
ret.push(input[prop]);
53-
}
42+
var sorted = [];
43+
if (input) {
44+
if (!input.$getIndex || typeof input.$getIndex != "function") {
45+
// input is not an angularFire instance
46+
if( angular.isArray(input) ) {
47+
// if input is an array, copy it
48+
sorted = input.slice(0);
49+
}
50+
else if( angular.isObject(input) ) {
51+
// If input is an object, map it to an array
52+
angular.forEach(input, function(prop) {
53+
sorted.push(prop);
54+
});
5455
}
55-
return ret;
5656
}
57-
return input;
58-
}
59-
60-
var sorted = [];
61-
var index = input.$getIndex();
62-
if (index.length <= 0) {
63-
return input;
64-
}
65-
66-
for (var i = 0; i < index.length; i++) {
67-
var val = input[index[i]];
68-
if (val) {
69-
val.$id = index[i];
70-
sorted.push(val);
57+
else {
58+
// input is an angularFire instance
59+
var index = input.$getIndex();
60+
if (index.length > 0) {
61+
for (var i = 0; i < index.length; i++) {
62+
var val = input[index[i]];
63+
if (val) {
64+
val.$id = index[i];
65+
sorted.push(val);
66+
}
67+
}
68+
}
7169
}
7270
}
73-
7471
return sorted;
7572
};
7673
});

angularfire.min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)