-
Notifications
You must be signed in to change notification settings - Fork 142
/
firebase-app.html
149 lines (135 loc) · 4.63 KB
/
firebase-app.html
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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
<!--
@license
Copyright 2016 Google Inc. All Rights Reserved.
Use of this source code is governed by a BSD-style
license that can be found in the LICENSE file or at
https://github.com/firebase/polymerfire/blob/master/LICENSE
-->
<link rel="import" href="../polymer/polymer.html">
<link rel="import" href="firebase-app-script.html">
<!-- TODO(cdata): Remove all of the imports below this line when it is possible
to lazy load Firebase scripts alongside Custom Elements v1 upgrade order -->
<link rel="import" href="firebase-database-script.html">
<link rel="import" href="firebase-auth-script.html">
<link rel="import" href="firebase-storage-script.html">
<link rel="import" href="firebase-messaging-script.html">
<link rel="import" href="firebase-firestore-script.html">
<link rel="import" href="firebase-functions-script.html">
<dom-module id="firebase-app">
<script>
(function() {
'use strict';
/**
* The firebase-app element is used for initializing and configuring your
* connection to firebase. It is permanently initialized once attached and
* should not be dynamically bound.
*/
Polymer({
is: 'firebase-app',
properties: {
/**
* The name of your app. Optional.
*
* You can use this with the `appName` property of other Polymerfire elements
* in order to use multiple firebase configurations on a page at once.
* In that case the name is used as a key to lookup the configuration.
*/
name: {
type: String,
value: ''
},
/**
* Your API key.
*
* Get this from the Auth > Web Setup panel of the new
* Firebase Console at https://console.firebase.google.com
*
* It looks like this: 'AIzaSyDTP-eiQezleFsV2WddFBAhF_WEzx_8v_g'
*/
apiKey: {
type: String
},
/**
* The domain name to authenticate with.
*
* The same as your Firebase Hosting subdomain or custom domain.
* Available on the Firebase Console.
*
* For example: 'polymerfire-test.firebaseapp.com'
*/
authDomain: {
type: String
},
/**
* The URL of your Firebase Realtime Database. You can find this
* URL in the Database panel of the Firebase Console.
* Available on the Firebase Console.
*
* For example: 'https://polymerfire-test.firebaseio.com/'
*/
databaseUrl: {
type: String
},
/**
* The Firebase Storage bucket for your project. You can find this
* in the Firebase Console under "Web Setup".
*
* For example: `polymerfire-test.appspot.com`
*/
storageBucket: {
type: String,
value: null
},
/**
* The Firebase Cloud Messaging Sender ID for your project. You can find
* this in the Firebase Console under "Web Setup".
*/
messagingSenderId: {
type: String,
value: null
},
/**
* The Google Cloud Project ID for your project. You can find this
* in the Firebase Console under "Web Setup".
*
* For example: `polymerfire-test`
*/
projectId: {
type: String,
value: null
},
/**
* The Firebase app object constructed from the other fields of
* this element.
* @type {firebase.app.App}
*/
app: {
type: Object,
notify: true,
computed: '__computeApp(name, apiKey, authDomain, databaseUrl, storageBucket, messagingSenderId, projectId)'
}
},
__computeApp: function(name, apiKey, authDomain, databaseUrl, storageBucket, messagingSenderId, projectId) {
if (apiKey && authDomain && databaseUrl) {
var init = [{
apiKey: apiKey,
authDomain: authDomain,
databaseURL: databaseUrl,
projectId: projectId,
storageBucket: storageBucket,
messagingSenderId: messagingSenderId
}];
if (name) {
init.push(name);
}
firebase.initializeApp.apply(firebase, init);
this.fire('firebase-app-initialized');
} else {
return null;
}
return firebase.app(name);
}
});
})();
</script>
</dom-module>