forked from FirebaseExtended/angularfire
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfirebaseRef.js
46 lines (37 loc) · 1.32 KB
/
firebaseRef.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
(function() {
"use strict";
function FirebaseRef() {
this.urls = null;
this.registerUrl = function registerUrl(urlOrConfig) {
if (typeof urlOrConfig === 'string') {
this.urls = {};
this.urls.default = urlOrConfig;
}
if (angular.isObject(urlOrConfig)) {
this.urls = urlOrConfig;
}
};
this.$$checkUrls = function $$checkUrls(urlConfig) {
if (!urlConfig) {
return new Error('No Firebase URL registered. Use firebaseRefProvider.registerUrl() in the config phase. This is required if you are using $firebaseAuthService.');
}
if (!urlConfig.default) {
return new Error('No default Firebase URL registered. Use firebaseRefProvider.registerUrl({ default: "https://<my-firebase-app>.firebaseio.com/"}).');
}
};
this.$$createRefsFromUrlConfig = function $$createMultipleRefs(urlConfig) {
var refs = {};
var error = this.$$checkUrls(urlConfig);
if (error) { throw error; }
angular.forEach(urlConfig, function(value, key) {
refs[key] = firebase.database().refFromURL(value);
});
return refs;
};
this.$get = function FirebaseRef_$get() {
return this.$$createRefsFromUrlConfig(this.urls);
};
}
angular.module('firebase')
.provider('$firebaseRef', FirebaseRef);
})();