Last active
January 22, 2017 17:08
-
-
Save menuka94/432d3f2b26de466f0d0f598f50033055 to your computer and use it in GitHub Desktop.
Firebase Web
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const auth = firebase.auth(); | |
auth.singInWithEmailAndPassword(email, pass); | |
// create new user | |
auth.createUserWithEmailAndPassword(email, pass); | |
auth.onAuthStateChanged(firebaseUser => {}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(function () { | |
// Initialize Firebase | |
const config = { | |
apiKey: "", | |
authDomain: "", | |
databaseURL: "", | |
storageBucket: "", | |
messagingSenderId: "" | |
}; | |
firebase.initializeApp(config); | |
var bigOne = document.getElementById('bigOne'); // <h1 id="bigOne"></h1> | |
var dbRef = firebase.database().ref().child('text'); | |
dbRef.on('value', snap => bigOne.innerText = snap.val()); | |
// get the element | |
const preObject = document.getElementById('object'); // <pre id="object"></pre> | |
const ulList = document.getElementById('list'); // <ul id="list"></ul> | |
// create references | |
const dbRefObject = firebase.database().ref().child('object'); | |
const dbRefList = dbRefObject.child('hobbies'); | |
// Sync object changes | |
dbRefObject.on('value', snap => { | |
preObject.innerText = JSON.stringify(snap.val(), null, 3); | |
}); | |
// Sync list changes | |
dbRefList.on('child_added', snap => { | |
const li = document.createElement('li'); | |
li.innerText = snap.val(); | |
li.id = snap.key; | |
ulList.appendChild(li); | |
}); | |
dbRefList.on('child_changed', snap => { | |
const liChanged = document.getElementById(snap.key); | |
liChanged.innerText = snap.val(); | |
}); | |
dbRefList.on('child_removed', snap => { | |
const liToRemove = document.getElementById(snap.key); | |
liToRemove.remove(); | |
}); | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment