-
Notifications
You must be signed in to change notification settings - Fork 1
/
firebase.helper.js
52 lines (45 loc) · 1.45 KB
/
firebase.helper.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
47
48
49
50
51
52
function initFireBase() {
// Your web app's Firebase configuration
// For Firebase JS SDK v7.20.0 and later, measurementId is optional
var firebaseConfig = {
apiKey: "AIzaSyCn2U12L4iH5s65peWz9vmuy-uvms7uW9M",
authDomain: "lol2d-mapeditor-2.firebaseapp.com",
databaseURL: "https://lol2d-mapeditor-2-default-rtdb.firebaseio.com",
projectId: "lol2d-mapeditor-2",
storageBucket: "lol2d-mapeditor-2.appspot.com",
messagingSenderId: "838951362664",
appId: "1:838951362664:web:3591926df1b4b52925dbdd",
measurementId: "G-L0P3BF88W8",
};
// Initialize Firebase
firebase.initializeApp(firebaseConfig);
firebase.analytics();
}
function listenToFireBase(ref, dataCallback) {
let database = firebase.database();
database.ref(ref).on("value", (snapshot) => {
const data = snapshot.val();
dataCallback && dataCallback(data);
});
}
function removeDataFirebase(ref, id) {
firebase
.database()
.ref(ref + id)
.remove();
}
function addDataFirebase(ref, data, onFailed) {
firebase
.database()
.ref(ref)
.set(data, (error) => {
if (error) onFailed && onFailed(error);
});
}
function updateDataFirebase(ref, data) {
firebase.database().ref(ref).update(data);
}
function generateNewKeyFirebase(ref) {
var newDataKey = firebase.database().ref().child(ref).push().key;
return newDataKey;
}