Realtime DB

with Firebase

Marlena Baker

baker.marlena@gmail.com                                                                                      git/baker-marlena

What?

DEMO.
How?

What?

What?

  • Data stored as JSON object

    • flexible database 

    • access directly with Firebase’s GUI

  • Data can be stored locally
  • Includes SDK

What?DEMO.

Contingency

What

DEMO.

How?

Initial Setup

<script src="https://www.gstatic.com/firebasejs/4.1.2/firebase-app.js"></script>
<script src="https://www.gstatic.com/firebasejs/4.1.2/firebase-database.js"></script>
var config = {
  apiKey: 
  databaseURL: 
  };

firebase.initializeApp(config);

referencing your Database

const database = firebase.database();
currentSession = database.ref(sessionKey);
currentSession.child("timer")

currentSession.child(otherUser)

Adding to your Database

session_data : {
    user_1:{
      textInput:"",
      wordCount:0
    },
    user_2:{
      textInput:"",
      wordCount:0
    }
  };
database.ref(session_key).set(session_data);

Updating your Database

let update = {
    [userName]: {
      textInput: this.value,
      wordCount: wordCountValue
      }
    };

  currentSession.update(update);
currentSession.update({startStatus:false});

Listening to your Database

currentSession.child(otherUser)
    .on("value", (snapshot) => {
        const data = snapshot.val();
        return data.wordCount;
      });

-> 23
currentSession.child('initilized')
    .once('value')
        .then(function(snapshot){
          let data = snapshot.val();
          return data;
        };

-> false
currentSession.child('timeLeft').off();

Thank you

example Code:

baker-marlena/realtime-demo

Marlena Baker

baker.marlena@gmail.com                                                                                      git/baker-marlena

Firebase Realtime

By Marlena Baker

Firebase Realtime

  • 215