forked from arminstr/reremeter
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfireBase.js
More file actions
46 lines (35 loc) · 1.02 KB
/
fireBase.js
File metadata and controls
46 lines (35 loc) · 1.02 KB
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
var app_fireBase = {};
(function(){
// Your web app's Firebase configuration
var config = {
// your api config
};
// Initialize Firebase
firebase.initializeApp(config);
app_fireBase = firebase;
function fnCreate(path, body, callBack){
if(!path || !body) return;
app_fireBase.database().ref(path).set(body, callBack);
}
function fnUpdate(path, body, callBack){
if(!path || !body) return;
app_fireBase.database().ref(path).update(body, callBack);
}
function fnListen(path, callBack){
if(!path || !callBack) return;
var listen = app_fireBase.database().ref(path);
listen.on('value', function(snapshot) {
callBack(snapshot.val());
});
}
function fnGet(path, successCallback, errorCallBack){
if(!path || !successCallback || !errorCallBack) return;
app_fireBase.database().ref(path).once('value').then(successCallback, errorCallBack)
}
app_fireBase.databaseApi = {
create: fnCreate,
update: fnUpdate,
get: fnGet,
listen: fnListen
}
})()